mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
docs: Add sample agent to test support of output_schema, tools and subagents at the same time for gemini model
Co-authored-by: Ieva Grublyte <ievagrublyte@google.com> PiperOrigin-RevId: 826006607
This commit is contained in:
committed by
Copybara-Service
parent
c0892c725c
commit
ec86608734
@@ -20,6 +20,7 @@ supported through a workaround that uses a special set_model_response tool.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from google.adk.agents import LlmAgent
|
from google.adk.agents import LlmAgent
|
||||||
|
from google.adk.tools.google_search_tool import google_search
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from pydantic import Field
|
from pydantic import Field
|
||||||
import requests
|
import requests
|
||||||
@@ -79,6 +80,22 @@ def get_current_year() -> str:
|
|||||||
return str(datetime.now().year)
|
return str(datetime.now().year)
|
||||||
|
|
||||||
|
|
||||||
|
# Create the knowledge agent that uses google_search tool.
|
||||||
|
knowledge_agent = LlmAgent(
|
||||||
|
name="knowledge_agent",
|
||||||
|
model="gemini-2.5-flash",
|
||||||
|
instruction="""
|
||||||
|
You are a helpful assistant that gathers information about famous people.
|
||||||
|
Use google_search tool to find information about them.
|
||||||
|
Provide the output into a structured response using the PersonInfo format.
|
||||||
|
""",
|
||||||
|
description="""
|
||||||
|
A knowledge agent that gathers information about famous people.
|
||||||
|
""",
|
||||||
|
tools=[google_search],
|
||||||
|
output_schema=PersonInfo,
|
||||||
|
)
|
||||||
|
|
||||||
# Create the agent with both output_schema and tools
|
# Create the agent with both output_schema and tools
|
||||||
root_agent = LlmAgent(
|
root_agent = LlmAgent(
|
||||||
name="person_info_agent",
|
name="person_info_agent",
|
||||||
@@ -87,15 +104,15 @@ root_agent = LlmAgent(
|
|||||||
You are a helpful assistant that gathers information about famous people.
|
You are a helpful assistant that gathers information about famous people.
|
||||||
|
|
||||||
When asked about a person, you should:
|
When asked about a person, you should:
|
||||||
1. Use the search_wikipedia tool to find information about them
|
1. Use the knowledge_agent to find information about politicians
|
||||||
2. Use the get_current_year tool if you need to calculate ages
|
2. Use the search_wikipedia tool to find information about other people
|
||||||
3. Compile the information into a structured response using the PersonInfo format
|
3. Use the get_current_year tool if you need to calculate ages
|
||||||
|
4. Compile the information into a structured response using the PersonInfo format
|
||||||
Always use the set_model_response tool to provide your final answer in the required structured format.
|
|
||||||
""".strip(),
|
""".strip(),
|
||||||
output_schema=PersonInfo,
|
output_schema=PersonInfo,
|
||||||
tools=[
|
tools=[
|
||||||
search_wikipedia,
|
search_wikipedia,
|
||||||
get_current_year,
|
get_current_year,
|
||||||
],
|
],
|
||||||
|
sub_agents=[knowledge_agent],
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user