AG2 (formerly Autogen) Multi-Agents Example on Vertex AI Agent Engine

Source notebook

Repo path: gemini/agent-engine/tutorial_ag2_on_agent_engine.ipynb · Open on GitHub · advanced

Builds and deploys an AG2 multi-agent research app to Vertex AI Agent Engine.

Summary

This notebook teaches how to configure AG2 with Gemini on Vertex AI, define specialized research agents, and run a group chat workflow locally. It then wraps the agents in a Queryable ResearchApp, deploys it with AgentEngine.create, tests the deployed endpoint, monitors logs, writes a report, and cleans up deployments.

Key code patterns

Gemini config for AG2

config_list = [{
    "model": MODEL_NAME,
    "project_id": PROJECT_ID,
    "location": LOCATION,
    "api_type": "google",
}]

AG2 agents use this config_list to call Gemini through Google Cloud.

Initialize Vertex AI

vertexai.init(
    project=PROJECT_ID,
    location=LOCATION,
    staging_bucket=STAGING_BUCKET,
)

Sets the project, region, and Cloud Storage staging bucket before Agent Engine deployment.

Create AG2 group chat

groupchat = GroupChat(
    agents=[user_proxy, researcher, literature_reviewer, fact_checker, data_analyst],
    messages=[],
    max_round=12,
)
manager = GroupChatManager(
    groupchat=groupchat,
    llm_config={"config_list": config_list, "seed": seed},
)

Combines specialized agents into one orchestrated conversation managed by Gemini.

Run cached multi-agent chat

with Cache.disk() as cache:
    result = user_proxy.initiate_chat(
        manager,
        message=msg,
        summary_method="reflection_with_llm",
        summary_args={"summary_prompt": custom_summary_prompt},
        cache=cache,
    )

Uses disk caching to reduce inference cost and LLM reflection to generate the final report.

Deploy Queryable app

agent_engine = AgentEngine.create(
    ResearchApp(project_id=PROJECT_ID, location=LOCATION),
    display_name="AG2 Research Application",
    gcs_dir_name=artifacts_gcs_dirname,
    requirements=["ag2[gemini]==0.10.5"],
)

Packages the Queryable ResearchApp and deploys it as a Vertex AI Agent Engine resource.

Models & APIs used

  • Models: gemini-2.5-flash
  • APIs / services: Vertex AI, Vertex AI Agent Engine, Cloud Storage, Cloud Logging, Service Usage API
  • SDKs / libraries: ag2, google-cloud-aiplatform, vertexai, autogen, google-generativeai, dask, cloudpickle

When to use this

Use this pattern when deploying an AG2 multi-agent workflow with Gemini to Vertex AI Agent Engine for remote execution.

Gotchas & caveats

  • Enable billing, Service Usage API, Vertex AI API, and Logs Explorer before running.
  • Agent Engine location is stated as only supported in us-central1.
  • The staging bucket must start with gs:// and be writable.
  • All agents and bootstrapping code must be initialized in set_up, not init.
  • Deployment is a long-running operation and should be monitored in Logs Explorer.
  • CACHING_SEED is best-effort deterministic sampling; determinism is not guaranteed.
  • Cleanup cells default to dry run, so deletion requires changing dry_run_delete_step.

Best practices

  • Authenticate in Colab with google.colab.auth or use Application Default Credentials outside Colab.
  • Test ResearchApp locally before deploying to Vertex AI Agent Engine.
  • Use Cache.disk() to reduce inference cost.
  • Use human_input_mode=“NEVER” for the deployed UserProxyAgent query flow.
  • Clean up deployed Agent Engines to avoid unnecessary costs.
  • Specify pinned package versions in AgentEngine.create requirements.
  • Inspect deployment logs for agent initialization, conversation logs, progress indicators, and errors.