The Supervisor Agent is the master orchestrator of ISC-CodeConnect's multi-agent system. It serves as the entry point for complex queries, analyzing them for decomposition requirements and managing multi-stage execution workflows. When a query requires multiple sequential operations, the Supervisor Agent breaks it down into executable stages and coordinates their execution across specialized agents.
- Complex Query Assessment: Determines if queries require multi-stage processing
- Stage Definition: Breaks complex requests into sequential, executable stages
- Dependency Management: Identifies stage dependencies and execution order
- Flow Validation: Ensures each stage maps to available agent flows
- Stage Execution Management: Coordinates sequential stage processing
- Progress Tracking: Monitors and reports stage completion status
- State Management: Maintains execution context across stages
- Error Recovery: Handles stage failures and provides graceful fallbacks
- Real-time Updates: Provides live progress updates during execution
- Task Tracking: Generates unique task IDs for frontend correlation
- Stage Notifications: Sends detailed stage start/completion events
- Error Reporting: Communicates errors with user-friendly messages
__all__ = ["send_stage_progress_update", "decompose_query", "process_stage_completion"]class ExecutionStage(BaseModel):
stage_id: int = Field(description="Unique identifier for this execution stage")
stage_query: str = Field(description="The specific query to execute at this stage")
stage_description: str = Field(description="A short description of what this stage accomplishes")
requires_previous_stage_output: bool = Field(description="Whether this stage depends on the output of a previous stage")class QueryDecomposition(BaseModel):
decomposition_required: bool = Field(description="Whether the query needs to be broken down into multiple stages")
stages: List[ExecutionStage] = Field(default=[], description="List of execution stages if decomposition is required")Purpose: Analyzes queries and determines if they require multi-stage decomposition.
Process Flow:
- Query Analysis: Uses structured LLM output to analyze query complexity
- Decomposition Decision: Applies sophisticated rules to determine if breakdown is needed
- Stage Creation: If decomposition required, creates detailed execution stages
- State Initialization: Sets up supervisor state for multi-stage execution
- Frontend Notification: Sends planning progress and stage structure to frontend
Key Decision Logic:
- 13 Available Flows: Maps queries to one of 13 specialized agent flows
- Explicit Request Rule: Only decomposes when users explicitly request multiple deliverables
- Anti-Pattern Protection: Prevents over-decomposition of informational queries
- Best Practice Filtering: Avoids adding implicit stages based on development best practices
Return Scenarios:
- Multi-stage Required: Returns router targeting with first stage query
- Single Stage: Returns router targeting for direct processing
- Error Handling: Returns error state with fallback to router
Purpose: Processes stage completions and manages multi-stage workflow progression.
Process Flow:
- Stage Result Storage: Captures and stores completed stage output
- Progress Calculation: Updates completion percentages and metrics
- Next Stage Preparation: Sets up subsequent stage execution if needed
- Final Assembly: Combines all stage results when workflow completes
- Frontend Updates: Sends completion events and progress notifications
State Transitions:
- Continue: Routes to next stage via router agent
- Complete: Finalizes workflow and assembles final response
- Error: Provides graceful error handling with partial results
Purpose: Allows any agent to send progress updates during stage execution.
Usage: Called by specialized agents to provide real-time progress feedback:
await send_stage_progress_update(state, "Analyzing code patterns...", config)Query: "Create an Apex class for account management and write tests for it"
Stages:
1. Apex Creation → "Create an Apex class for account management"
2. Apex Test Generation → "Write test class for the account management Apex class"
Query: "How can I create feature switch?"
Reason: Informational query asking for guidance - use General Query Processing flow
Query: "Create an Apex class for account management"
Reason: User only requested one component - don't add test generation implicitly
The Supervisor Agent maps queries to exactly one of 13 available flows:
- Apex Code Creation - New classes/triggers
- Apex Code Modification - Existing code updates
- Apex Code Explanation - Code analysis
- Apex Test Generation - Test class creation
- Apex Test Modification - Test updates
- Apex Test Explanation - Test analysis
- LWC Creation - New components
- LWC Modification - Component updates
- LWC Explanation - Component analysis
- LWC Test Generation - Jest tests
- LWC Test Modification - Test updates
- LWC Test Explanation - Test analysis
- General Query Processing - Informational queries, best practices, patterns
- ❌ Validation stages (built into all flows)
- ❌ Integration testing stages (automatic)
- ❌ Verification stages (included automatically)
- ❌ Quality assurance stages (built-in)
- ❌ Best practice stages user didn't request
- User explicitly requests multiple different flow types
- Query requires genuinely different technologies (Apex + LWC)
- Sequential dependency exists between different flow types
- Cannot be satisfied by any single flow
{
"supervisor_active": bool, # Whether supervisor is managing execution
"supervisor_task_id": str, # Unique task identifier
"supervisor_stages": List[Dict], # List of execution stages
"current_stage_index": int, # Currently executing stage
"total_stages": int, # Total number of stages
"stage_results": List[Dict], # Results from completed stages
"original_query": str, # User's original query
"stage_query": str # Current stage query
}{
"stage_id": int, # Stage identifier
"stage_query": str, # Query for this stage
"stage_response": List[Any] # Agent response(s)
}{
"chunk": "Analyzing query complexity...",
"details": {
"description": "Breaking down complex query into executable stages",
"response": "Planning execution strategy...",
"taskId": "task_12345",
"taskType": "planning",
"taskStatus": "in_progress"
}
}{
"chunk": "Breaking down your request into 2 steps",
"details": {
"description": "Task decomposition complete",
"response": "Here's my execution plan:\n\n**Step 1**: Generate Apex class\n**Step 2**: Generate test class",
"taskId": "task_12345",
"taskType": "decomposition",
"taskStatus": "complete",
"stages": [...]
}
}{
"chunk": "✅ Completed step 1/2",
"details": {
"description": "Stage 1 of 2 completed successfully",
"response": "✅ **Step 1 Complete**: Generate Apex class\n\n[Generated code here]",
"taskId": "task_12345",
"stageId": 1,
"taskType": "stage_execution",
"stageStatus": "complete",
"progressInfo": {
"completedStages": 1,
"totalStages": 2,
"percentComplete": 50
}
}
}{
"chunk": "All 2 steps completed. Final response ready.",
"details": {
"description": "Multi-stage task execution complete.",
"response": "[Combined results from all stages]",
"taskId": "task_12345",
"taskType": "final_result",
"taskStatus": "complete",
"totalStages": 2
}
}The Supervisor Agent uses a comprehensive 500+ line prompt that includes:
- 13 Available Flows Documentation: Complete descriptions of each flow's capabilities
- Decomposition Rules: Detailed rules for when to decompose vs. single-flow processing
- Anti-Pattern Examples: Extensive examples of incorrect decomposition patterns
- Decision Flowchart: Step-by-step decision process
- Response Examples: Correct and incorrect decomposition examples
Query: "Write test class for AccountService"
Decision Process:
1. Query Type Check: Technical query (not informational) ✓
2. Explicit Request Check: Single request (test class only) ✓
3. Flow Type Count: 1 flow (Apex Test Generation) ✓
4. Result: decomposition_required = false
Reasoning: Apex Test Generation flow can reference AccountService
without requiring the class to be created first.
- Decomposition Errors: Fall back to normal router processing
- Stage Completion Errors: Provide partial results with graceful termination
- State Corruption: Return error state with diagnostic information
- Frontend Communication: Send error events with user-friendly messages
{
"current_agent": "end",
"error_state": {
"message": "Error description",
"location": "function_name"
},
"partial_results": [...], # Any completed stages
"supervisor_active": False
}- Decomposition Analysis Time: Query analysis duration
- Stage Execution Time: Individual stage processing time
- Total Workflow Time: End-to-end multi-stage completion
- Success Rate: Successful decomposition and completion rate
- Error Recovery Rate: Successful error handling percentage
- Structured Output: Uses LLM structured output for reliable parsing
- State Caching: Maintains execution state across stages
- Progress Streaming: Real-time frontend updates
- Error Boundaries: Isolated error handling per stage
- Router Agent: Receives control from router for complex queries
- LLM Provider: Uses structured output for decomposition analysis
- Router Agent: Routes stages back to router for processing
- Specialized Agents: Coordinates execution across all agent types
- Frontend: Streams progress and completion events
# Other agents can send progress updates
from src.agents.supervisor_agent import send_stage_progress_update
await send_stage_progress_update(
state,
"Analyzing retrieved code patterns...",
config
)# Input Query
"Create an Apex REST API for account management and build an LWC component to consume it"
# Decomposition Result
{
"decomposition_required": true,
"stages": [
{
"stage_id": 1,
"stage_query": "Create an Apex REST API service for account management with CRUD operations",
"stage_description": "Generate Apex REST service",
"requires_previous_stage_output": false
},
{
"stage_id": 2,
"stage_query": "Create an LWC component that consumes the account management REST API",
"stage_description": "Generate LWC for API consumption",
"requires_previous_stage_output": true
}
]
}# Input Query
"How can I create feature switch?"
# Decomposition Result
{
"decomposition_required": false,
"stages": []
}
# Routes to General Query Processing flow for comprehensive guidance- Use Progress Updates: Call
send_stage_progress_update()for long operations - Handle Context: Access previous stage results via
state["stage_results"] - Error Reporting: Provide detailed error information for debugging
- State Validation: Check
supervisor_activebefore supervisor operations
- Be Explicit: Only request what you actually need
- Avoid Assumptions: Don't assume additional components are needed
- Sequential Thinking: Structure multi-step requests logically
- Clear Dependencies: Make stage dependencies obvious
- Dynamic Stage Modification: Ability to add/remove stages mid-execution
- Parallel Stage Execution: Support for independent parallel stages
- Stage Checkpointing: Resume capability for interrupted workflows
- Advanced Analytics: Detailed performance and success metrics
- CI/CD Integration: Multi-stage deployments with ISC-CodeConnect
- Code Review Workflows: Automated review and improvement stages
- Testing Pipelines: Comprehensive test generation and execution stages
The Supervisor Agent represents the sophisticated orchestration capabilities that make ISC-CodeConnect's multi-agent system both powerful and user-friendly, ensuring complex requests are handled intelligently while maintaining simplicity for straightforward queries.