Skip to main content
The Context-Aware Routing Pattern creates a dynamic workflow where tasks are intelligently distributed to specialized agents based on content analysis rather than predetermined paths. Unlike static patterns with fixed routes, this approach analyzes each request in real-time to determine the most appropriate specialist, ensuring queries are handled by agents with the most relevant expertise while maintaining conversation continuity even as topics shift across domains.

Key Characteristics

Context-Aware Routing Pattern The Context-Aware Routing Pattern uses intelligent analysis to match requests with the most qualified specialist. By examining the content and context of each query, the system can dynamically adapt its routing decisions, ensuring optimal expertise allocation while maintaining a seamless user experience across domain transitions.
  • Dynamic Content Analysis: Each request is analyzed for keywords, themes, and intent to determine the most appropriate domain for routing.
  • Adaptive Routing Logic: Routing decisions adapt in real-time to changing topics, allowing smooth transitions between different domains of expertise.
  • Ambiguity Resolution: When queries have unclear domain affiliations, the system can request clarification before routing.
  • Contextual Memory: Past interactions and domain history inform future routing decisions, creating a more coherent multi-domain experience.

Information Flow

Context-Aware Flow In the Context-Aware Routing Pattern, information flows through a central router that serves as a dispatcher for incoming requests. This router analyzes each query’s content and context before directing it to a specialized agent, creating a hub-and-spoke information flow that dynamically adjusts based on the nature of each request rather than following a predetermined sequence.
  • Analysis Phase: Each request undergoes content analysis to extract domain indicators and intent.
  • Decision Point: Based on analysis, the system determines which specialist agent has the most relevant expertise.
  • Specialization Phase: The selected domain expert processes the request using their specialized knowledge.
  • Return Path: Responses flow back to the user, with the router maintaining awareness of the conversation state for future routing decisions.

Implementation

Our implementation using AG2’s Group Chat demonstrates the Context-Aware Routing Pattern with a router agent that analyzes queries and directs them to specialized domain experts. The system maintains rich contextual information about domain history, request patterns, and confidence levels, enabling intelligent routing decisions that improve as the conversation evolves.
  • Content Analysis Tools: The router agent uses sophisticated analysis functions to determine query domains and calculate confidence scores.
  • Domain Specialists: Four specialized agents (technology, finance, healthcare, general knowledge) provide domain-specific expertise.
  • Context Variables: Shared context tracks domain history, confidence scores, and routing decisions to inform future interactions.
  • OnContextCondition Handoffs: Efficient conditional handoffs dynamically route requests based on the determined domain.
This pattern excels in multi-domain support systems, complex customer service environments, and research assistants that require access to diverse knowledge domains. It enables a single system to provide expert-level responses across multiple domains while maintaining a coherent conversation experience.

Agent Flow

Code

In this code example we use OpenAI’s GPT-4o mini.We also set the LLM parameter parallel_tool_calls to False so that our agents don’t recommend more than one tool call at a time. This parameter may not be available with all model providers.

Output