Lab 4 Challenge: Transforming an Agent
Goal
Your task is to create a new "Haiku Poet" agent by duplicating and modifying the "Echo" agent from the previous lab. This will demonstrate how to build upon existing agents.
Requirements
- In your
adk-trainingdirectory, duplicate theecho_agentdirectory and rename the copy tohaiku_poet_agent. - Navigate into the new
haiku_poet_agentsub-directory. - Follow the Python Approach below to modify the agent's behavior.
- Change the
nametohaiku_poet_agent. - Update the
description. - Craft a new
instructionthat gives the agent the persona of a wise poet who transforms the user's topic into a haiku. - Include at least two examples (few-shot prompts) in your instruction to guide the agent.
- Change the
- Return to the parent
adk-trainingdirectory. - Run the new agent using the
adk web haiku_poet_agentcommand. - Interact with the agent in the Dev UI to verify that it correctly responds with a haiku.
Python Approach (Primary)
Modify the agent.py file inside your new haiku_poet_agent directory. You will need to update the name, description, and instruction arguments in the LlmAgent constructor.
Alternative Approach: Using YAML Configuration
If you are using a root_agent.yaml file:
- Modify the
name,description, andinstructionfields in yourroot_agent.yamlfile. - Ensure you do not have an
agent.pyfile in the same directory, as the YAML file will take precedence.
Self-Reflection Questions
- How does providing examples (few-shot prompting) in the instruction help the LLM understand the task better than just describing it?
- What would happen if you removed the constraint "Do not answer questions or have a conversation"? How would the agent's behavior change?
- Experiment with creating a new persona for the agent (e.g., a Shakespearean poet, a futuristic robot). What are the key elements you need to include in the instruction to make the new persona convincing?
🕵️ Hidden Solution 🕵️
Looking for the solution? Here's a hint (Base64 decode me):
L2RvYy1hZGstdHJhaW5pbmcvbW9kdWxlMDQtbGxtYWdlbnQtZGVlcC1kaXZlL2xhYi1zb2x1dGlvbg==
The direct link is: Lab Solution