Skip to content

Commit ec86608

Browse files
ievagrublyte-engcopybara-github
authored andcommitted
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
1 parent c0892c7 commit ec86608

File tree

1 file changed

+22
-5
lines changed
  • contributing/samples/output_schema_with_tools

1 file changed

+22
-5
lines changed

contributing/samples/output_schema_with_tools/agent.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"""
2121

2222
from google.adk.agents import LlmAgent
23+
from google.adk.tools.google_search_tool import google_search
2324
from pydantic import BaseModel
2425
from pydantic import Field
2526
import requests
@@ -79,6 +80,22 @@ def get_current_year() -> str:
7980
return str(datetime.now().year)
8081

8182

83+
# Create the knowledge agent that uses google_search tool.
84+
knowledge_agent = LlmAgent(
85+
name="knowledge_agent",
86+
model="gemini-2.5-flash",
87+
instruction="""
88+
You are a helpful assistant that gathers information about famous people.
89+
Use google_search tool to find information about them.
90+
Provide the output into a structured response using the PersonInfo format.
91+
""",
92+
description="""
93+
A knowledge agent that gathers information about famous people.
94+
""",
95+
tools=[google_search],
96+
output_schema=PersonInfo,
97+
)
98+
8299
# Create the agent with both output_schema and tools
83100
root_agent = LlmAgent(
84101
name="person_info_agent",
@@ -87,15 +104,15 @@ def get_current_year() -> str:
87104
You are a helpful assistant that gathers information about famous people.
88105
89106
When asked about a person, you should:
90-
1. Use the search_wikipedia tool to find information about them
91-
2. Use the get_current_year tool if you need to calculate ages
92-
3. Compile the information into a structured response using the PersonInfo format
93-
94-
Always use the set_model_response tool to provide your final answer in the required structured format.
107+
1. Use the knowledge_agent to find information about politicians
108+
2. Use the search_wikipedia tool to find information about other people
109+
3. Use the get_current_year tool if you need to calculate ages
110+
4. Compile the information into a structured response using the PersonInfo format
95111
""".strip(),
96112
output_schema=PersonInfo,
97113
tools=[
98114
search_wikipedia,
99115
get_current_year,
100116
],
117+
sub_agents=[knowledge_agent],
101118
)

0 commit comments

Comments
 (0)