Skip to content

Commit cb55970

Browse files
google-genai-botcopybara-github
authored andcommitted
refactor: Simplify agent_tool.py
PiperOrigin-RevId: 771135917
1 parent 40b15ad commit cb55970

File tree

1 file changed

+3
-18
lines changed

1 file changed

+3
-18
lines changed

src/google/adk/tools/agent_tool.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,6 @@ async def run_async(
9797

9898
if isinstance(self.agent, LlmAgent) and self.agent.input_schema:
9999
input_value = self.agent.input_schema.model_validate(args)
100-
else:
101-
input_value = args['request']
102-
103-
if isinstance(self.agent, LlmAgent) and self.agent.input_schema:
104-
if isinstance(input_value, dict):
105-
input_value = self.agent.input_schema.model_validate(input_value)
106-
if not isinstance(input_value, self.agent.input_schema):
107-
raise ValueError(
108-
f'Input value {input_value} is not of type'
109-
f' `{self.agent.input_schema}`.'
110-
)
111100
content = types.Content(
112101
role='user',
113102
parts=[
@@ -119,7 +108,7 @@ async def run_async(
119108
else:
120109
content = types.Content(
121110
role='user',
122-
parts=[types.Part.from_text(text=input_value)],
111+
parts=[types.Part.from_text(text=args['request'])],
123112
)
124113
runner = Runner(
125114
app_name=self.agent.name,
@@ -145,15 +134,11 @@ async def run_async(
145134

146135
if not last_event or not last_event.content or not last_event.content.parts:
147136
return ''
137+
merged_text = '\n'.join(p.text for p in last_event.content.parts if p.text)
148138
if isinstance(self.agent, LlmAgent) and self.agent.output_schema:
149-
merged_text = '\n'.join(
150-
[p.text for p in last_event.content.parts if p.text]
151-
)
152139
tool_result = self.agent.output_schema.model_validate_json(
153140
merged_text
154141
).model_dump(exclude_none=True)
155142
else:
156-
tool_result = '\n'.join(
157-
[p.text for p in last_event.content.parts if p.text]
158-
)
143+
tool_result = merged_text
159144
return tool_result

0 commit comments

Comments
 (0)