|
| 1 | +# Workflow Triage Sample |
| 2 | + |
| 3 | +This sample demonstrates how to build a multi-agent workflow that intelligently triages incoming requests and delegates them to appropriate specialized agents. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The workflow consists of three main components: |
| 8 | + |
| 9 | +1. **Execution Manager Agent** (`agent.py`) - Analyzes user input and determines which execution agents are relevant |
| 10 | +2. **Plan Execution Agent** - Sequential agent that coordinates execution and summarization |
| 11 | +3. **Worker Execution Agents** (`execution_agent.py`) - Specialized agents that execute specific tasks in parallel |
| 12 | + |
| 13 | +## Architecture |
| 14 | + |
| 15 | +### Execution Manager Agent (`root_agent`) |
| 16 | +- **Model**: gemini-2.5-flash |
| 17 | +- **Name**: `execution_manager_agent` |
| 18 | +- **Role**: Analyzes user requests and updates the execution plan |
| 19 | +- **Tools**: `update_execution_plan` - Updates which execution agents should be activated |
| 20 | +- **Sub-agents**: Delegates to `plan_execution_agent` for actual task execution |
| 21 | +- **Clarification**: Asks for clarification if user intent is unclear before proceeding |
| 22 | + |
| 23 | +### Plan Execution Agent |
| 24 | +- **Type**: SequentialAgent |
| 25 | +- **Name**: `plan_execution_agent` |
| 26 | +- **Components**: |
| 27 | + - `worker_parallel_agent` (ParallelAgent) - Runs relevant agents in parallel |
| 28 | + - `execution_summary_agent` - Summarizes the execution results |
| 29 | + |
| 30 | +### Worker Agents |
| 31 | +The system includes two specialized execution agents that run in parallel: |
| 32 | + |
| 33 | +- **Code Agent** (`code_agent`): Handles code generation tasks |
| 34 | + - Uses `before_agent_callback_check_relevance` to skip if not relevant |
| 35 | + - Output stored in `code_agent_output` state key |
| 36 | +- **Math Agent** (`math_agent`): Performs mathematical calculations |
| 37 | + - Uses `before_agent_callback_check_relevance` to skip if not relevant |
| 38 | + - Output stored in `math_agent_output` state key |
| 39 | + |
| 40 | +### Execution Summary Agent |
| 41 | +- **Model**: gemini-2.5-flash |
| 42 | +- **Name**: `execution_summary_agent` |
| 43 | +- **Role**: Summarizes outputs from all activated agents |
| 44 | +- **Dynamic Instructions**: Generated based on which agents were activated |
| 45 | +- **Content Inclusion**: Set to "none" to focus on summarization |
| 46 | + |
| 47 | +## Key Features |
| 48 | + |
| 49 | +- **Dynamic Agent Selection**: Automatically determines which agents are needed based on user input |
| 50 | +- **Parallel Execution**: Multiple relevant agents can work simultaneously via `ParallelAgent` |
| 51 | +- **Relevance Filtering**: Agents skip execution if they're not relevant to the current state using callback mechanism |
| 52 | +- **Stateful Workflow**: Maintains execution state through `ToolContext` |
| 53 | +- **Execution Summarization**: Automatically summarizes results from all activated agents |
| 54 | +- **Sequential Coordination**: Uses `SequentialAgent` to ensure proper execution flow |
| 55 | + |
| 56 | +## Usage |
| 57 | + |
| 58 | +The workflow follows this pattern: |
| 59 | + |
| 60 | +1. User provides input to the root agent (`execution_manager_agent`) |
| 61 | +2. Manager analyzes the request and identifies relevant agents (`code_agent`, `math_agent`) |
| 62 | +3. If user intent is unclear, manager asks for clarification before proceeding |
| 63 | +4. Manager updates the execution plan using `update_execution_plan` |
| 64 | +5. Control transfers to `plan_execution_agent` |
| 65 | +6. `worker_parallel_agent` (ParallelAgent) runs only relevant agents based on the updated plan |
| 66 | +7. `execution_summary_agent` summarizes the results from all activated agents |
| 67 | + |
| 68 | +### Example Queries |
| 69 | + |
| 70 | +**Vague requests requiring clarification:** |
| 71 | + |
| 72 | +``` |
| 73 | +> hi |
| 74 | +> Help me do this. |
| 75 | +``` |
| 76 | + |
| 77 | +The root agent (`execution_manager_agent`) will greet the user and ask for clarification about their specific task. |
| 78 | + |
| 79 | +**Math-only requests:** |
| 80 | + |
| 81 | +``` |
| 82 | +> What's 1+1? |
| 83 | +``` |
| 84 | + |
| 85 | +Only the `math_agent` executes while `code_agent` is skipped. |
| 86 | + |
| 87 | +**Multi-domain requests:** |
| 88 | + |
| 89 | +``` |
| 90 | +> What's 1+11? Write a python function to verify it. |
| 91 | +``` |
| 92 | + |
| 93 | +Both `code_agent` and `math_agent` execute in parallel, followed by summarization. |
| 94 | + |
| 95 | +## Available Execution Agents |
| 96 | + |
| 97 | +- `code_agent` - For code generation and programming tasks |
| 98 | +- `math_agent` - For mathematical computations and analysis |
| 99 | + |
| 100 | +## Implementation Details |
| 101 | + |
| 102 | +- Uses Google ADK agents framework |
| 103 | +- Implements callback-based relevance checking via `before_agent_callback_check_relevance` |
| 104 | +- Maintains state through `ToolContext` and state keys |
| 105 | +- Supports parallel agent execution with `ParallelAgent` |
| 106 | +- Uses `SequentialAgent` for coordinated execution flow |
| 107 | +- Dynamic instruction generation for summary agent based on activated agents |
| 108 | +- Agent outputs stored in state with `{agent_name}_output` keys |
0 commit comments