Spaces:
Running
A newer version of the Gradio SDK is available:
6.1.0
Orchestrators Architecture
DeepCritical supports multiple orchestration patterns for research workflows.
Research Flows
IterativeResearchFlow
File: src/orchestrator/research_flow.py
Pattern: Generate observations β Evaluate gaps β Select tools β Execute β Judge β Continue/Complete
Agents Used:
KnowledgeGapAgent: Evaluates research completenessToolSelectorAgent: Selects tools for addressing gapsThinkingAgent: Generates observationsWriterAgent: Creates final reportJudgeHandler: Assesses evidence sufficiency
Features:
- Tracks iterations, time, budget
- Supports graph execution (
use_graph=True) and agent chains (use_graph=False) - Iterates until research complete or constraints met
Usage:
IterativeResearchFlow Initialization start_line:57 end_line:80
DeepResearchFlow
File: src/orchestrator/research_flow.py
Pattern: Planner β Parallel iterative loops per section β Synthesizer
Agents Used:
PlannerAgent: Breaks query into report sectionsIterativeResearchFlow: Per-section research (parallel)LongWriterAgentorProofreaderAgent: Final synthesis
Features:
- Uses
WorkflowManagerfor parallel execution - Budget tracking per section and globally
- State synchronization across parallel loops
- Supports graph execution and agent chains
Usage:
DeepResearchFlow Initialization start_line:709 end_line:728
Graph Orchestrator
File: src/orchestrator/graph_orchestrator.py
Purpose: Graph-based execution using Pydantic AI agents as nodes
Features:
- Uses graph execution (
use_graph=True) or agent chains (use_graph=False) as fallback - Routes based on research mode (iterative/deep/auto)
- Streams
AgentEventobjects for UI - Uses
GraphExecutionContextto manage execution state
Node Types:
- Agent Nodes: Execute Pydantic AI agents
- State Nodes: Update or read workflow state
- Decision Nodes: Make routing decisions
- Parallel Nodes: Execute multiple nodes concurrently
Edge Types:
- Sequential Edges: Always traversed
- Conditional Edges: Traversed based on condition
- Parallel Edges: Used for parallel execution branches
Special Node Handling:
The GraphOrchestrator has special handling for certain nodes:
execute_toolsnode: State node that usessearch_handlerto execute searches and add evidence to workflow stateparallel_loopsnode: Parallel node that executesIterativeResearchFlowinstances for each section in deep research modesynthesizernode: Agent node that callsLongWriterAgent.write_report()directly withReportDraftinstead of usingagent.run()writernode: Agent node that callsWriterAgent.write_report()directly with findings instead of usingagent.run()
GraphExecutionContext:
The orchestrator uses GraphExecutionContext to manage execution state:
- Tracks current node, visited nodes, and node results
- Manages workflow state and budget tracker
- Provides methods to store and retrieve node execution results
Orchestrator Factory
File: src/orchestrator_factory.py
Purpose: Factory for creating orchestrators
Modes:
- Simple: Legacy orchestrator (backward compatible)
- Advanced: Magentic orchestrator (requires OpenAI API key)
- Auto-detect: Chooses based on API key availability
Usage:
Create Orchestrator start_line:44 end_line:66
Magentic Orchestrator
File: src/orchestrator_magentic.py
Purpose: Multi-agent coordination using Microsoft Agent Framework
Features:
- Uses
agent-framework-core - ChatAgent pattern with internal LLMs per agent
MagenticBuilderwith participants:searcher: SearchAgent (wraps SearchHandler)hypothesizer: HypothesisAgent (generates hypotheses)judge: JudgeAgent (evaluates evidence)reporter: ReportAgent (generates final report)
- Manager orchestrates agents via chat client (OpenAI or HuggingFace)
- Event-driven: converts Magentic events to
AgentEventfor UI streaming via_process_event()method - Supports max rounds, stall detection, and reset handling
Event Processing:
The orchestrator processes Magentic events and converts them to AgentEvent:
MagenticOrchestratorMessageEventβAgentEventwith type based on message contentMagenticAgentMessageEventβAgentEventwith type based on agent nameMagenticAgentDeltaEventβAgentEventfor streaming updatesMagenticFinalResultEventβAgentEventwith type "complete"
Requirements:
agent-framework-corepackage- OpenAI API key or HuggingFace authentication
Hierarchical Orchestrator
File: src/orchestrator_hierarchical.py
Purpose: Hierarchical orchestrator using middleware and sub-teams
Features:
- Uses
SubIterationMiddlewarewithResearchTeamandLLMSubIterationJudge - Adapts Magentic ChatAgent to
SubIterationTeamprotocol - Event-driven via
asyncio.Queuefor coordination - Supports sub-iteration patterns for complex research tasks
Legacy Simple Mode
File: src/legacy_orchestrator.py
Purpose: Linear search-judge-synthesize loop
Features:
- Uses
SearchHandlerProtocolandJudgeHandlerProtocol - Generator-based design yielding
AgentEventobjects - Backward compatibility for simple use cases
State Initialization
All orchestrators must initialize workflow state:
Initialize Workflow State start_line:98 end_line:112
Event Streaming
All orchestrators yield AgentEvent objects:
Event Types:
started: Research startedsearching: Search in progresssearch_complete: Search completedjudging: Evidence evaluation in progressjudge_complete: Evidence evaluation completedlooping: Iteration in progresshypothesizing: Generating hypothesesanalyzing: Statistical analysis in progressanalysis_complete: Statistical analysis completedsynthesizing: Synthesizing resultscomplete: Research completederror: Error occurredstreaming: Streaming update (delta events)
Event Structure:
AgentEvent Model start_line:104 end_line:126
See Also
- Graph Orchestration - Graph-based execution details
- Workflow Diagrams - Detailed workflow diagrams
- API Reference - Orchestrators - API documentation