โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โก โก โ
โ ๐ค AI Agent Orchestration ๐ญ โ
โ โก โก โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ Image โ โ Story โ โ
โ โ Generator โ โ Teller โ โ
โ โ ๐จ โ โ ๐ โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โ
โ โ โ โ
โ โโโโโโโโฌโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโ โ
โ โ Orchestratorโ โ
โ โ ๐ฏ โ โ
โ โโโโโโโโโโโโโโโ โ
โ โก โก โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
To make the environment configuration as smooth as possible, we'll use Cloud Shell for this workshop.
Click "Activate Cloud Shell" at the top right. Authorize it to make API calls on launch if needed. Then, click "Open in new window" followed by "Open Editor". This will provide an interface eerily similar to VSCode.
Before starting, you need to configure a couple of variables in config.py:
- Google Cloud Storage bucket for images ๐๏ธ - Update
GCS_IMAGE_BUCKETwith your workshop bucket - Toolbox endpoint ๐ง - Update
TOOLBOX_ENDPOINTwith the Cloud Run URL from thepar-devfest-sfeirGoogle Cloud Project
First, create and activate a virtual environment:
python3 -m venv .venv
source .venv/bin/activateTo activate it in future sessions:
source .venv/bin/activateEnsure you have the required dependencies:
pip install -r requirements.txtAt the root of every agent directory, you need to create a .env file with the following environment variables:
GOOGLE_GENAI_USE_VERTEXAI=TRUE
GOOGLE_CLOUD_PROJECT=<PROJECT_ID>
GOOGLE_CLOUD_LOCATION=us-central1This will help your agent know who is paying for its work. The agents are pretty strict and might refuse to work without this information. Don't worry! We'll indicate every time you need to create the file! ๐ฎโ๐จ
Welcome, brave adventurer! You have two paths before you:
- solution: Everything is already codedโyou just need to update the
config.pyfile and add.envfiles (as mentioned above) ina2a_image_generator_agent,a2a_storyteller_agent, andorchestrator_agent. You'll be done in NO TIME! (NO TIME = 15 minutes) - workshop: The path for intrepid explorers! Some code will be missing, and it's up to you to complete it! HINTs will be provided if you feel completely lost in the woods...
Ready to dive into the world of agents? Let's build a multi-agent!
The workshop folder contains an additional agents folder to help you build your first storytelling agent.
This agent was built using ADK. If you're curious about any part, you can check the documentation: https://google.github.io/adk-docs/agents/workflow-agents.
-
Draft Writer Agent:
workshop/a2a_storyteller_agent/storyteller_agent/draft_writer_agent/agent.py- Your mission: Implement the DraftWriterAgent that generates the initial draft of a story (4-8 sentences) based on search results.
๐ก HINT
Use the same structure as other ADK workflow agents:draft_writer_agent = Agent( name="DraftWriterAgent", model=MODEL_GEMINI, description=""" A creative writing assistant that generates the initial draft of a story based on the provided search results, focusing on creating an engaging start. """, include_contents='none', instruction=f""" !!! COMPLETE THE AGENT INSTRUCTIONS """, output_key=STATE_CURRENT_DOC )
You can also check the
solution/a2a_storyteller_agent/storyteller_agent/draft_writer_agent/agent.pyfile for a reference implementation. -
Refinement Loop:
workshop/a2a_storyteller_agent/storyteller_agent/refinement_loop/agent.py- Your mission: Add critic_agent and editor_agent to the sub_agents list in the LoopAgent configuration.
- Pro tip: It might also be a good idea to limit the number of iterations ๐
๐ก HINT
After the agent description, add the sub-agents and maximum iterations:sub_agents=[ critic_agent, editor_agent, ], max_iterations=5
Don't forget to place the .env file at the root of the storyteller_agent folder.
From the workshop/agents folder:
adk webNow let's add an A2A wrapper and unlock the next level!
-
Agent Skill & Card:
workshop/a2a_storyteller_agent/__main__.py- Your mission: Create AgentSkill for story creation with id, name, description, tags, and examples.
๐ก HINT
Add AgentSkill to Storyteller agent A2A wrapper:skill = AgentSkill( id="create_story", name="Story Creation Tool", description="Helps with writing stories", tags=["story creation"], examples=["What's new in Generative AI?"], )
- Your mission: Create AgentCard for storyteller agent with name, description, url, version, input/output modes, capabilities, and skills.
๐ก HINT
Add AgentCard to Storyteller agent A2A wrapper:agent_card = AgentCard( name="Storyteller Agent", description="Helps with writing stories", url=f"http://{host}:{port}", version="1.0.0", defaultInputModes=StorytellerAgent.SUPPORTED_CONTENT_TYPES, defaultOutputModes=StorytellerAgent.SUPPORTED_CONTENT_TYPES_OUTPUT, capabilities=capabilities, skills=[skill], )
Don't forget to place the .env file at the root of the a2a_storyteller_agent folder.
From the solution (or workshop) folder:
uv run a2a_storyteller_agent/To test and debug, you can use the a2a-inspector tool, which provides a user-friendly interface for interacting with your agents.
# Clone the a2a-inspector repository
git clone https://github.com/a2aproject/a2a-inspector.git
cd a2a-inspector
# Follow the installation instructions in the repository- Start your agent server (e.g.,
uv run a2a_image_generator_agent/) - Launch a2a-inspector and connect to your agent's endpoint (e.g.,
http://127.0.0.1:10002) - Send test messages to verify agent behavior and responses
- Monitor logs to troubleshoot any issues
-
A2A Server URLs:
workshop/config.pyFor our A2A servers to be used, we need to specify where they can be found!- Your mission: Add the URLs for the A2A servers (A2A_IMAGE_GENERATION_URL and A2A_STORYTELLER_URL).
๐ก HINT
Check the URLs and ports used to start the servers!A2A_IMAGE_GENERATION_URL = "http://127.0.0.1:10001" A2A_STORYTELLER_URL = "http://127.0.0.1:10002"
-
MCP ToolBox Connector:
workshop/orchestrator_agent/sub_agent/agent.py- Your mission: Add the MCP Toolbox connector to save the story. If you need help, check the corresponding package: https://pypi.org/project/toolbox-core/ .
๐ก HINT
Use the ToolboxSyncClient to connect to the toolbox and load the save tool:toolbox = ToolboxSyncClient(TOOLBOX_ENDPOINT) save_story = toolbox.load_tool("insert-story")
Place the .env file at the root of the a2a_image_generator_agent folder and orchestrator_agent folder. And you're all set to go!
From the solution (or workshop) folder:
uv run a2a_image_generator_agent/From the solution (or workshop) folder:
uv run a2a_storyteller_agent/From the solution (or workshop) folder:
adk webYou can now choose the orchestrator_agent and test your storytelling solution! Time to see your creation come to life! โจ