Early Stopping in ADK SequentialAgent? #894
Replies: 1 comment
|
For a condition in your own workflow, put the check in one custom orchestration agent. That avoids adding the same check to every child.
from contextlib import aclosing
from google.adk.agents import BaseAgent
class ConditionalSequence(BaseAgent):
async def _run_async_impl(self, ctx):
for agent in self.sub_agents:
if ctx.session.state.get("stop_sequence", False):
return
async with aclosing(agent.run_async(ctx)) as events:
async for event in events:
yield event
root_agent = ConditionalSequence(
name="pipeline",
sub_agents=[first_agent, second_agent, third_agent],
)When a child's tool determines that the sequence should stop, set This stops between children, rather than cancelling a child that is already running. Also, |
Uh oh!
There was an error while loading. Please reload this page.
Is there a built-in mechanism to stop the entire agent sequence in SequentialAgent if a sub-agent meets a certain condition? Or do we need to manually add state checks to each sub-agent?
All reactions