Replies: 1 comment
-
|
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: Directly escalating from an Hi @sigott, That's a great question about controlling the flow of a The termination of a The Recommended SolutionYou mentioned that adding another agent to the loop feels a bit "clunky." However, this is the idiomatic approach in ADK, and the agent for this task can be very lightweight and simple. It doesn't need to be a complex LLM-based agent. You can create a simple Here is a conceptual example: from adk.agents import BaseAgent, AgentContext
from adk.events import Event, EventActions
class LoopTerminationAgent(BaseAgent):
"""An agent that checks a condition and escalates to terminate the loop."""
async def _run_async_impl(self, context: "AgentContext"):
# Retrieve the necessary data from state to make a decision
# This is the same logic you would have in your callback
should_terminate = your_condition_check(context.state)
if should_terminate:
# Yield an event with escalate=True to stop the parent LoopAgent
print("Condition met. Terminating loop.")
yield Event(actions=EventActions(escalate=True))
else:
# Otherwise, do nothing and let the loop continue
yield Event(content="Condition not met. Continuing loop.")
# Then, add this agent to your LoopAgent's list of agents
loop_agent = LoopAgent(
agents=[
your_main_sub_agent,
LoopTerminationAgent() # This agent will run at the end of each loop iteration
],
max_iterations=20
)This approach keeps the control flow logic cleanly encapsulated within an agent, which aligns with ADK's design principles. It's a clear and maintainable way to manage the loop's execution based on dynamic conditions in the state. [1] https://google.github.io/adk-docs/agents/multi-agents/ |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a loop agent that is a sub_agent to the root_agent. The loop agent has an after_agent_callback. The callback keeps track of a few things and updates the state after each loop iteration. Is there a way to also escalate (end the loop) from within the callback? I know this can be done by adding another agent in the loop but that just seems a bit clunky?
It would be nice if I could modify the agent's last event from within the after_agent_callback and add/modify the event's EventActions.
Beta Was this translation helpful? Give feedback.
All reactions