You've already forked adk-python
mirror of
https://github.com/encounter/adk-python.git
synced 2026-03-30 10:57:20 -07:00
8f3ca0359e
PiperOrigin-RevId: 813305068
Workflow Triage Sample
This sample demonstrates how to build a multi-agent workflow that intelligently triages incoming requests and delegates them to appropriate specialized agents.
Overview
The workflow consists of three main components:
- Execution Manager Agent (
agent.py) - Analyzes user input and determines which execution agents are relevant - Plan Execution Agent - Sequential agent that coordinates execution and summarization
- Worker Execution Agents (
execution_agent.py) - Specialized agents that execute specific tasks in parallel
Architecture
Execution Manager Agent (root_agent)
- Model: gemini-2.5-flash
- Name:
execution_manager_agent - Role: Analyzes user requests and updates the execution plan
- Tools:
update_execution_plan- Updates which execution agents should be activated - Sub-agents: Delegates to
plan_execution_agentfor actual task execution - Clarification: Asks for clarification if user intent is unclear before proceeding
Plan Execution Agent
- Type: SequentialAgent
- Name:
plan_execution_agent - Components:
worker_parallel_agent(ParallelAgent) - Runs relevant agents in parallelexecution_summary_agent- Summarizes the execution results
Worker Agents
The system includes two specialized execution agents that run in parallel:
- Code Agent (
code_agent): Handles code generation tasks- Uses
before_agent_callback_check_relevanceto skip if not relevant - Output stored in
code_agent_outputstate key
- Uses
- Math Agent (
math_agent): Performs mathematical calculations- Uses
before_agent_callback_check_relevanceto skip if not relevant - Output stored in
math_agent_outputstate key
- Uses
Execution Summary Agent
- Model: gemini-2.5-flash
- Name:
execution_summary_agent - Role: Summarizes outputs from all activated agents
- Dynamic Instructions: Generated based on which agents were activated
- Content Inclusion: Set to "none" to focus on summarization
Key Features
- Dynamic Agent Selection: Automatically determines which agents are needed based on user input
- Parallel Execution: Multiple relevant agents can work simultaneously via
ParallelAgent - Relevance Filtering: Agents skip execution if they're not relevant to the current state using callback mechanism
- Stateful Workflow: Maintains execution state through
ToolContext - Execution Summarization: Automatically summarizes results from all activated agents
- Sequential Coordination: Uses
SequentialAgentto ensure proper execution flow
Usage
The workflow follows this pattern:
- User provides input to the root agent (
execution_manager_agent) - Manager analyzes the request and identifies relevant agents (
code_agent,math_agent) - If user intent is unclear, manager asks for clarification before proceeding
- Manager updates the execution plan using
update_execution_plan - Control transfers to
plan_execution_agent worker_parallel_agent(ParallelAgent) runs only relevant agents based on the updated planexecution_summary_agentsummarizes the results from all activated agents
Example Queries
Vague requests requiring clarification:
> hi
> Help me do this.
The root agent (execution_manager_agent) will greet the user and ask for clarification about their specific task.
Math-only requests:
> What's 1+1?
Only the math_agent executes while code_agent is skipped.
Multi-domain requests:
> What's 1+11? Write a python function to verify it.
Both code_agent and math_agent execute in parallel, followed by summarization.
Available Execution Agents
code_agent- For code generation and programming tasksmath_agent- For mathematical computations and analysis
Implementation Details
- Uses Google ADK agents framework
- Implements callback-based relevance checking via
before_agent_callback_check_relevance - Maintains state through
ToolContextand state keys - Supports parallel agent execution with
ParallelAgent - Uses
SequentialAgentfor coordinated execution flow - Dynamic instruction generation for summary agent based on activated agents
- Agent outputs stored in state with
{agent_name}_outputkeys