from google.adk.tools.agent_tool import AgentTool
# Travel specialist agent
travel_agent = Agent(
name="travel_specialist",
model="gemini-2.0-flash",
instruction="""You are a travel planning specialist. Use get_user_context to
understand the user's travel preferences and history before making recommendations.
After providing advice, use store_interaction to save travel-related information.""",
description="Specialist in travel planning and recommendations",
tools=[search_memory, save_memory]
)
# Health advisor agent
health_agent = Agent(
name="health_advisor",
model="gemini-2.0-flash",
instruction="""You are a health and wellness advisor. Use get_user_context to
understand the user's health goals and dietary preferences.
After providing advice, use store_interaction to save health-related information.""",
description="Specialist in health and wellness advice",
tools=[search_memory, save_memory]
)
# Coordinator agent that delegates to specialists
coordinator_agent = Agent(
name="coordinator",
model="gemini-2.0-flash",
instruction="""You are a coordinator that delegates requests to specialist agents.
For travel-related questions (trips, hotels, flights, destinations), delegate to the travel specialist.
For health-related questions (fitness, diet, wellness, exercise), delegate to the health advisor.
Use get_user_context to understand the user before delegation.""",
description="Coordinates requests between specialist agents",
tools=[
AgentTool(agent=travel_agent, skip_summarization=False),
AgentTool(agent=health_agent, skip_summarization=False)
]
)
def chat_with_specialists(user_input: str, user_id: str) -> str:
"""
Handle user input with specialist agent delegation and memory.
Args:
user_input: The user's message
user_id: Unique identifier for the user
Returns:
The specialist agent's response
"""
session_service = InMemorySessionService()
session = session_service.create_session(
app_name="specialist_system",
user_id=user_id,
session_id=f"session_{user_id}"
)
runner = Runner(agent=coordinator_agent, app_name="specialist_system", session_service=session_service)
content = types.Content(role='user', parts=[types.Part(text=user_input)])
events = runner.run(user_id=user_id, session_id=session.id, new_message=content)
for event in events:
if event.is_final_response():
response = event.content.parts[0].text
# Store the conversation in shared memory
conversation = [
{"role": "user", "content": user_input},
{"role": "assistant", "content": response}
]
mem0.add(conversation, user_id=user_id)
return response
return "No response generated"
# Example usage
response = chat_with_specialists("Plan a healthy meal for my Italy trip", user_id="alice")
print(response)