Replies: 3 comments
-
Beta Was this translation helpful? Give feedback.
-
|
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: You can achieve this deterministically by using either a Hello @ckl-axel, Thank you for your feature request. Having a deterministic way to control agent execution is a great point. ADK provides a couple of ways to achieve the conditional execution you're looking for based on the session state. Using a
|
Beta Was this translation helpful? Give feedback.
-
|
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: You can achieve this by implementing a custom agent. This agent will act as an orchestrator, checking a flag in the session state to decide whether to route the request to the onboarding sub-agent or other sub-agents. Hello! That's a great question. You can definitely implement this kind of runtime logic in ADK. While the Here’s a conceptual example of how you could build an orchestrator agent that conditionally runs an onboarding agent: from google.adk.agents import BaseAgent, LlmAgent
from google.adk.sessions import InvocationContext, Session
class OnboardingOrchestrator(BaseAgent):
"""A custom agent to orchestrate onboarding."""
def __init__(self, onboarding_agent: BaseAgent, main_agent: BaseAgent, **kwargs):
# Pass all potential sub-agents to the parent constructor
# so the framework is aware of them for tracing and other purposes.
super().__init__(sub_agents=[onboarding_agent, main_agent], **kwargs)
self.onboarding_agent = onboarding_agent
self.main_agent = main_agent
async def _run_async_impl(self, ctx: InvocationContext):
"""
Conditionally runs the onboarding agent or the main agent
based on a flag in the session state.
"""
# Check a flag in the session state.
onboarding_complete = ctx.session.state.get("onboarding_complete", False)
if not onboarding_complete:
# If onboarding is not complete, run the onboarding agent.
# The onboarding agent would be responsible for setting the
# 'onboarding_complete' flag to True in the session state
# when it's finished.
async for event in self.onboarding_agent.run_async(ctx):
yield event
else:
# Otherwise, run the main agent.
async for event in self.main_agent.run_async(ctx):
yield eventIn this pattern:
This approach allows for complex and deterministic routing logic within your agent hierarchy. For more details, you can refer to the official documentation on creating custom agents. [1] |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Is your feature request related to a problem? Please describe.
We have an onboarding agent that is highly optimized for the initial interaction with new users. It would be great if we can have conditional inclusion of the sub agent so that outside of the initial interaction we know for certain it will not be transferred to. The condition can be a field in the session state of the user.
Describe alternatives you've considered
We are currently doing it via prompt engineering but a deterministic way to do this would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions