Google Cloud Vertex AI Agent Builder Cannot Find Custom Package Module During Deployment

I’m having trouble deploying my custom agent application to Google Cloud Vertex AI Reasoning Engine. The deployment keeps failing with a module import error even though my wheel package seems to be built correctly.

My Setup

I built a custom agent app organized in a package called ml_analytics. The wheel file contains:

ml_analytics/main_agent.py
ml_analytics/helper_agents/...

I’m deploying using this code:

my_app = AdkApp.from_module(
    agent_module_name="ml_analytics.main_agent",
    agent_object_name="primary_agent"
)

deployed_agent = agent_engines.create(
    my_app,
    extra_packages=[wheel_path],
    requirements=[
        "vertexai==1.43.0",
        "cloudpickle==3.0.0",
        "pydantic==2.11.3",
        "google-adk"
    ],
    env_vars=environment_vars,
    verbose=True
)

The Error

When I try to deploy, I get this error message:

Pickle load failed: Missing module. Service terminating. ModuleNotFoundError: No module named 'ml_analytics'

What I Already Checked

  • The wheel file is properly structured and contains all my modules
  • Local installation works fine with pip install
  • GCS bucket permissions are set up correctly
  • The service account has Storage Object Viewer access
  • The wheel file path in GCS is accessible

I’m confused why Vertex AI can’t find my custom module even though it’s packaged in the wheel file. Has anyone run into this before? Are there special requirements for how the package needs to be structured for ADK deployment to work?

I encountered a similar issue, and what resolved it for me was ensuring that my setup.py included packages=find_packages() for proper package discovery. Additionally, it’s essential that each subdirectory in your package contains an __init__.py file, even if they are empty. Pay attention to the naming convention of your wheel file as well; it should conform to the format ml_analytics-1.0.0-py3-none-any.whl. Lastly, I realized I was building the wheel from the wrong directory, which misconfigured the package structure. Always make sure to build it from the parent directory.

seems like a timing issue, maybe your agent is trying to import it before the wheel is fully installed. try adding a small delay or check if your module loads in init of main_agent.py. also, make sure your setup.py is set to discover submodules properly!

Had this exact problem last month! It’s a wheel unpacking issue during deployment. Vertex AI tries to deserialize pickle before your custom package gets added to the Python path. Here’s what fixed it for me: change your agent_module_name parameter from ml_analytics.main_agent to just main_agent. Then restructure your wheel so main_agent.py sits at the root level with ml_analytics as a subfolder. This way the main module loads first, then imports from ml_analytics as needed. Also check your wheel’s METADATA file - make sure it shows the right package name. Sometimes the build process creates weird naming that breaks the import path.