Skip to content

Commit c0892c7

Browse files
ievagrublyte-engcopybara-github
authored andcommitted
chore: remove legacy validation that forbids co-exist of agent transfer and output_schema. Closes #3318
Remove validation for output_schema and agent transfer flags. The check that prevented `output_schema` from co-existing with agent transfer capabilities (`disallow_transfer_to_parent` or `disallow_transfer_to_peers` being False) has been removed. The agent will no longer automatically set these transfer flags to True when `output_schema` is present. Co-authored-by: Ieva Grublyte <ievagrublyte@google.com> PiperOrigin-RevId: 825998224
1 parent ce8f674 commit c0892c7

File tree

3 files changed

+31
-51
lines changed

3 files changed

+31
-51
lines changed

src/google/adk/agents/llm_agent.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -744,32 +744,8 @@ def __maybe_save_output_to_state(self, event: Event):
744744

745745
@model_validator(mode='after')
746746
def __model_validator_after(self) -> LlmAgent:
747-
self.__check_output_schema()
748747
return self
749748

750-
def __check_output_schema(self):
751-
if not self.output_schema:
752-
return
753-
754-
if (
755-
not self.disallow_transfer_to_parent
756-
or not self.disallow_transfer_to_peers
757-
):
758-
logger.warning(
759-
'Invalid config for agent %s: output_schema cannot co-exist with'
760-
' agent transfer configurations. Setting'
761-
' disallow_transfer_to_parent=True, disallow_transfer_to_peers=True',
762-
self.name,
763-
)
764-
self.disallow_transfer_to_parent = True
765-
self.disallow_transfer_to_peers = True
766-
767-
if self.sub_agents:
768-
raise ValueError(
769-
f'Invalid config for agent {self.name}: if output_schema is set,'
770-
' sub_agents must be empty to disable agent transfer.'
771-
)
772-
773749
@field_validator('generate_content_config', mode='after')
774750
@classmethod
775751
def validate_generate_content_config(

tests/unittests/agents/test_llm_agent_fields.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -167,40 +167,26 @@ async def _global_instruction_provider(ctx: ReadonlyContext) -> str:
167167
assert bypass_state_injection
168168

169169

170-
def test_output_schema_will_disable_transfer(caplog: pytest.LogCaptureFixture):
171-
with caplog.at_level('WARNING'):
172-
173-
class Schema(BaseModel):
174-
pass
175-
176-
agent = LlmAgent(
177-
name='test_agent',
178-
output_schema=Schema,
179-
)
180-
181-
# Transfer is automatically disabled
182-
assert agent.disallow_transfer_to_parent
183-
assert agent.disallow_transfer_to_peers
184-
assert (
185-
'output_schema cannot co-exist with agent transfer configurations.'
186-
in caplog.text
187-
)
188-
189-
190-
def test_output_schema_with_sub_agents_will_throw():
170+
def test_output_schema_with_sub_agents_will_not_throw():
191171
class Schema(BaseModel):
192172
pass
193173

194174
sub_agent = LlmAgent(
195175
name='sub_agent',
196176
)
197177

198-
with pytest.raises(ValueError):
199-
_ = LlmAgent(
200-
name='test_agent',
201-
output_schema=Schema,
202-
sub_agents=[sub_agent],
203-
)
178+
agent = LlmAgent(
179+
name='test_agent',
180+
output_schema=Schema,
181+
sub_agents=[sub_agent],
182+
)
183+
184+
# Transfer is not disabled
185+
assert not agent.disallow_transfer_to_parent
186+
assert not agent.disallow_transfer_to_peers
187+
188+
assert agent.output_schema == Schema
189+
assert agent.sub_agents == [sub_agent]
204190

205191

206192
def test_output_schema_with_tools_will_not_throw():

tests/unittests/flows/llm_flows/test_output_schema_processor.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,24 @@ async def test_output_schema_with_tools_validation_removed():
7272
assert len(agent.tools) == 1
7373

7474

75+
@pytest.mark.asyncio
76+
async def test_output_schema_with_sub_agents():
77+
"""Test that LlmAgent now allows output_schema with sub_agents."""
78+
sub_agent = LlmAgent(
79+
name='sub_agent',
80+
model='gemini-1.5-flash',
81+
)
82+
agent = LlmAgent(
83+
name='test_agent',
84+
model='gemini-1.5-flash',
85+
output_schema=PersonSchema,
86+
sub_agents=[sub_agent],
87+
)
88+
89+
assert agent.output_schema == PersonSchema
90+
assert len(agent.sub_agents) == 1
91+
92+
7593
@pytest.mark.asyncio
7694
async def test_basic_processor_skips_output_schema_with_tools():
7795
"""Test that basic processor doesn't set output_schema when tools are present."""

0 commit comments

Comments
 (0)