Flows
Flows orchestrate the complex request-response lifecycle in ADK-TS, managing the sequence of operations from user input through LLM processing to final response generation. The flow system provides a modular, extensible pipeline for preprocessing, LLM invocation, and postprocessing.Flow Architecture
BaseLlmFlow
All flows extend fromBaseLlmFlow, which defines the core lifecycle:
Flow Types
SingleFlow
Handles single-agent scenarios:AutoFlow
Manages multi-agent coordination and transfers:Request Processors
Request processors build up theLlmRequest before sending to the model:
Built-in Request Processors
- BasicProcessor - Sets up base request structure
- InstructionsProcessor - Adds system instructions
- IdentityProcessor - Injects agent identity information
- ContentsProcessor - Adds conversation history
- NaturalLanguagePlanningProcessor - Adds planning prompts
- CodeExecutionProcessor - Prepares code execution context
Response Processors
Response processors handle LLM output and generate events:Built-in Response Processors
- FunctionsProcessor - Handles tool/function calls
- AgentTransferProcessor - Manages sub-agent transfers
- NaturalLanguagePlanningProcessor - Processes planning responses
- CodeExecutionProcessor - Handles code execution results
InvocationContext
The context object passed through the flow pipeline:Processing Pipeline
The complete flow through a single step:Custom Flow Example
Create a specialized flow for specific use cases:Streaming Events
Flows yield events as they’re generated:Flow Control
Early Termination
Multi-Step Processing
Flows automatically loop until a final response:Function Call Flow
When the LLM calls a function:Best Practices
- Processor Order: Request processors run sequentially; order matters for dependencies.
- Event Yielding: Yield events for user feedback during long operations.
- Error Handling: Wrap processor logic in try-catch to prevent pipeline failures.
-
Context Preservation: Don’t mutate
InvocationContext; use it read-only except for specific flags. - Streaming: Design processors to work with partial responses during streaming.
- Performance: Keep processors lightweight; heavy operations should be in tools.