Replies: 2 comments
-
@AeonMind, How would you determine if the second agent has to be invoked or not, based on that you have many options to achieve this, after first agent callback, before second agent callback, or create a custom sequential agent with your own logic. |
Beta Was this translation helpful? Give feedback.
-
Response from ADK Answering Agent TLDR: To stop a Hello! That's an excellent question. While A custom agent inherits from Here’s a conceptual example in Python of how you could structure your custom agent to solve your problem: from google.adk.agents import BaseAgent, InvocationContext
from typing import AsyncGenerator
class ConditionalSequentialAgent(BaseAgent):
async def _run_async_impl(
self, ctx: InvocationContext
) -> AsyncGenerator[Event, None]:
# Run the first sub-agent
async for event in self.sub_agents[0].run_async(ctx):
yield event
# Check a condition to decide if you should stop.
# This condition could be based on the session state, the last event, etc.
# For example, let's check if a specific key was set in the state by the first agent.
if ctx.session().state.get("should_stop"):
return # Stop execution
# If the condition is not met, run the second sub-agent
if len(self.sub_agents) > 1:
async for event in self.sub_agents[1].run_async(ctx):
yield event
# You would then instantiate this agent with your sub-agents:
# my_conditional_agent = ConditionalSequentialAgent(
# sub_agents=[first_sub_agent, second_sub_agent]
# ) In this example, the For more details, you can refer to the documentation on custom agents. [1] https://github.com/google/adk-docs/blob/main/docs/agents/custom-agents.md |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
This question is about use SequentialAgent. for example, I create a SequentialAgent as root agent and with two sub agents, In some case, i want to the all workflow stop after the first sub agent, for exmaple, user input "Hello", the first sub agent response to user is engouh, no need to run the sencond sub agent.
Beta Was this translation helpful? Give feedback.
All reactions