# DeepCritical Workflow - Simplified Magentic Architecture > **Architecture Pattern**: Microsoft Magentic Orchestration > **Design Philosophy**: Simple, dynamic, manager-driven coordination > **Key Innovation**: Intelligent manager replaces rigid sequential phases --- ## 1. High-Level Magentic Workflow ```mermaid flowchart TD Start([User Query]) --> Manager[Magentic Manager
Plan • Select • Assess • Adapt] Manager -->|Plans| Task1[Task Decomposition] Task1 --> Manager Manager -->|Selects & Executes| HypAgent[Hypothesis Agent] Manager -->|Selects & Executes| SearchAgent[Search Agent] Manager -->|Selects & Executes| AnalysisAgent[Analysis Agent] Manager -->|Selects & Executes| ReportAgent[Report Agent] HypAgent -->|Results| Manager SearchAgent -->|Results| Manager AnalysisAgent -->|Results| Manager ReportAgent -->|Results| Manager Manager -->|Assesses Quality| Decision{Good Enough?} Decision -->|No - Refine| Manager Decision -->|No - Different Agent| Manager Decision -->|No - Stalled| Replan[Reset Plan] Replan --> Manager Decision -->|Yes| Synthesis[Synthesize Final Result] Synthesis --> Output([Research Report]) style Start fill:#e1f5e1 style Manager fill:#ffe6e6 style HypAgent fill:#fff4e6 style SearchAgent fill:#fff4e6 style AnalysisAgent fill:#fff4e6 style ReportAgent fill:#fff4e6 style Decision fill:#ffd6d6 style Synthesis fill:#d4edda style Output fill:#e1f5e1 ``` ## 2. Magentic Manager: The 6-Phase Cycle ```mermaid flowchart LR P1[1. Planning
Analyze task
Create strategy] --> P2[2. Agent Selection
Pick best agent
for subtask] P2 --> P3[3. Execution
Run selected
agent with tools] P3 --> P4[4. Assessment
Evaluate quality
Check progress] P4 --> Decision{Quality OK?
Progress made?} Decision -->|Yes| P6[6. Synthesis
Combine results
Generate report] Decision -->|No| P5[5. Iteration
Adjust plan
Try again] P5 --> P2 P6 --> Done([Complete]) style P1 fill:#fff4e6 style P2 fill:#ffe6e6 style P3 fill:#e6f3ff style P4 fill:#ffd6d6 style P5 fill:#fff3cd style P6 fill:#d4edda style Done fill:#e1f5e1 ``` ## 3. Simplified Agent Architecture ```mermaid graph TB subgraph "Orchestration Layer" Manager[Magentic Manager
• Plans workflow
• Selects agents
• Assesses quality
• Adapts strategy] SharedContext[(Shared Context
• Hypotheses
• Search Results
• Analysis
• Progress)] Manager <--> SharedContext end subgraph "Specialist Agents" HypAgent[Hypothesis Agent
• Domain understanding
• Hypothesis generation
• Testability refinement] SearchAgent[Search Agent
• Multi-source search
• RAG retrieval
• Result ranking] AnalysisAgent[Analysis Agent
• Evidence extraction
• Statistical analysis
• Code execution] ReportAgent[Report Agent
• Report assembly
• Visualization
• Citation formatting] end subgraph "MCP Tools" WebSearch[Web Search
PubMed • arXiv • bioRxiv] CodeExec[Code Execution
Sandboxed Python] RAG[RAG Retrieval
Vector DB • Embeddings] Viz[Visualization
Charts • Graphs] end Manager -->|Selects & Directs| HypAgent Manager -->|Selects & Directs| SearchAgent Manager -->|Selects & Directs| AnalysisAgent Manager -->|Selects & Directs| ReportAgent HypAgent --> SharedContext SearchAgent --> SharedContext AnalysisAgent --> SharedContext ReportAgent --> SharedContext SearchAgent --> WebSearch SearchAgent --> RAG AnalysisAgent --> CodeExec ReportAgent --> CodeExec ReportAgent --> Viz style Manager fill:#ffe6e6 style SharedContext fill:#ffe6f0 style HypAgent fill:#fff4e6 style SearchAgent fill:#fff4e6 style AnalysisAgent fill:#fff4e6 style ReportAgent fill:#fff4e6 style WebSearch fill:#e6f3ff style CodeExec fill:#e6f3ff style RAG fill:#e6f3ff style Viz fill:#e6f3ff ``` ## 4. Dynamic Workflow Example ```mermaid sequenceDiagram participant User participant Manager participant HypAgent participant SearchAgent participant AnalysisAgent participant ReportAgent User->>Manager: "Research protein folding in Alzheimer's" Note over Manager: PLAN: Generate hypotheses → Search → Analyze → Report Manager->>HypAgent: Generate 3 hypotheses HypAgent-->>Manager: Returns 3 hypotheses Note over Manager: ASSESS: Good quality, proceed Manager->>SearchAgent: Search literature for hypothesis 1 SearchAgent-->>Manager: Returns 15 papers Note over Manager: ASSESS: Good results, continue Manager->>SearchAgent: Search for hypothesis 2 SearchAgent-->>Manager: Only 2 papers found Note over Manager: ASSESS: Insufficient, refine search Manager->>SearchAgent: Refined query for hypothesis 2 SearchAgent-->>Manager: Returns 12 papers Note over Manager: ASSESS: Better, proceed Manager->>AnalysisAgent: Analyze evidence for all hypotheses AnalysisAgent-->>Manager: Returns analysis with code Note over Manager: ASSESS: Complete, generate report Manager->>ReportAgent: Create comprehensive report ReportAgent-->>Manager: Returns formatted report Note over Manager: SYNTHESIZE: Combine all results Manager->>User: Final Research Report ``` ## 5. Manager Decision Logic ```mermaid flowchart TD Start([Manager Receives Task]) --> Plan[Create Initial Plan] Plan --> Select[Select Agent for Next Subtask] Select --> Execute[Execute Agent] Execute --> Collect[Collect Results] Collect --> Assess[Assess Quality & Progress] Assess --> Q1{Quality Sufficient?} Q1 -->|No| Q2{Same Agent Can Fix?} Q2 -->|Yes| Feedback[Provide Specific Feedback] Feedback --> Execute Q2 -->|No| Different[Try Different Agent] Different --> Select Q1 -->|Yes| Q3{Task Complete?} Q3 -->|No| Q4{Making Progress?} Q4 -->|Yes| Select Q4 -->|No - Stalled| Replan[Reset Plan & Approach] Replan --> Plan Q3 -->|Yes| Synth[Synthesize Final Result] Synth --> Done([Return Report]) style Start fill:#e1f5e1 style Plan fill:#fff4e6 style Select fill:#ffe6e6 style Execute fill:#e6f3ff style Assess fill:#ffd6d6 style Q1 fill:#ffe6e6 style Q2 fill:#ffe6e6 style Q3 fill:#ffe6e6 style Q4 fill:#ffe6e6 style Synth fill:#d4edda style Done fill:#e1f5e1 ``` ## 6. Hypothesis Agent Workflow ```mermaid flowchart LR Input[Research Query] --> Domain[Identify Domain
& Key Concepts] Domain --> Context[Retrieve Background
Knowledge] Context --> Generate[Generate 3-5
Initial Hypotheses] Generate --> Refine[Refine for
Testability] Refine --> Rank[Rank by
Quality Score] Rank --> Output[Return Top
Hypotheses] Output --> Struct[Hypothesis Structure:
• Statement
• Rationale
• Testability Score
• Data Requirements
• Expected Outcomes] style Input fill:#e1f5e1 style Output fill:#fff4e6 style Struct fill:#e6f3ff ``` ## 7. Search Agent Workflow ```mermaid flowchart TD Input[Hypotheses] --> Strategy[Formulate Search
Strategy per Hypothesis] Strategy --> Multi[Multi-Source Search] Multi --> PubMed[PubMed Search
via MCP] Multi --> ArXiv[arXiv Search
via MCP] Multi --> BioRxiv[bioRxiv Search
via MCP] PubMed --> Aggregate[Aggregate Results] ArXiv --> Aggregate BioRxiv --> Aggregate Aggregate --> Filter[Filter & Rank
by Relevance] Filter --> Dedup[Deduplicate
Cross-Reference] Dedup --> Embed[Embed Documents
via MCP] Embed --> Vector[(Vector DB)] Vector --> RAGRetrieval[RAG Retrieval
Top-K per Hypothesis] RAGRetrieval --> Output[Return Contextualized
Search Results] style Input fill:#fff4e6 style Multi fill:#ffe6e6 style Vector fill:#ffe6f0 style Output fill:#e6f3ff ``` ## 8. Analysis Agent Workflow ```mermaid flowchart TD Input1[Hypotheses] --> Extract Input2[Search Results] --> Extract[Extract Evidence
per Hypothesis] Extract --> Methods[Determine Analysis
Methods Needed] Methods --> Branch{Requires
Computation?} Branch -->|Yes| GenCode[Generate Python
Analysis Code] Branch -->|No| Qual[Qualitative
Synthesis] GenCode --> Execute[Execute Code
via MCP Sandbox] Execute --> Interpret1[Interpret
Results] Qual --> Interpret2[Interpret
Findings] Interpret1 --> Synthesize[Synthesize Evidence
Across Sources] Interpret2 --> Synthesize Synthesize --> Verdict[Determine Verdict
per Hypothesis] Verdict --> Support[• Supported
• Refuted
• Inconclusive] Support --> Gaps[Identify Knowledge
Gaps & Limitations] Gaps --> Output[Return Analysis
Report] style Input1 fill:#fff4e6 style Input2 fill:#e6f3ff style Execute fill:#ffe6e6 style Output fill:#e6ffe6 ``` ## 9. Report Agent Workflow ```mermaid flowchart TD Input1[Query] --> Assemble Input2[Hypotheses] --> Assemble Input3[Search Results] --> Assemble Input4[Analysis] --> Assemble[Assemble Report
Sections] Assemble --> Exec[Executive Summary] Assemble --> Intro[Introduction] Assemble --> Methods[Methods] Assemble --> Results[Results per
Hypothesis] Assemble --> Discussion[Discussion] Assemble --> Future[Future Directions] Assemble --> Refs[References] Results --> VizCheck{Needs
Visualization?} VizCheck -->|Yes| GenViz[Generate Viz Code] GenViz --> ExecViz[Execute via MCP
Create Charts] ExecViz --> Combine VizCheck -->|No| Combine[Combine All
Sections] Exec --> Combine Intro --> Combine Methods --> Combine Discussion --> Combine Future --> Combine Refs --> Combine Combine --> Format[Format Output] Format --> MD[Markdown] Format --> PDF[PDF] Format --> JSON[JSON] MD --> Output[Return Final
Report] PDF --> Output JSON --> Output style Input1 fill:#e1f5e1 style Input2 fill:#fff4e6 style Input3 fill:#e6f3ff style Input4 fill:#e6ffe6 style Output fill:#d4edda ``` ## 10. Data Flow & Event Streaming ```mermaid flowchart TD User[👤 User] -->|Research Query| UI[Gradio UI] UI -->|Submit| Manager[Magentic Manager] Manager -->|Event: Planning| UI Manager -->|Select Agent| HypAgent[Hypothesis Agent] HypAgent -->|Event: Delta/Message| UI HypAgent -->|Hypotheses| Context[(Shared Context)] Context -->|Retrieved by| Manager Manager -->|Select Agent| SearchAgent[Search Agent] SearchAgent -->|MCP Request| WebSearch[Web Search Tool] WebSearch -->|Results| SearchAgent SearchAgent -->|Event: Delta/Message| UI SearchAgent -->|Documents| Context SearchAgent -->|Embeddings| VectorDB[(Vector DB)] Context -->|Retrieved by| Manager Manager -->|Select Agent| AnalysisAgent[Analysis Agent] AnalysisAgent -->|MCP Request| CodeExec[Code Execution Tool] CodeExec -->|Results| AnalysisAgent AnalysisAgent -->|Event: Delta/Message| UI AnalysisAgent -->|Analysis| Context Context -->|Retrieved by| Manager Manager -->|Select Agent| ReportAgent[Report Agent] ReportAgent -->|MCP Request| CodeExec ReportAgent -->|Event: Delta/Message| UI ReportAgent -->|Report| Context Manager -->|Event: Final Result| UI UI -->|Display| User style User fill:#e1f5e1 style UI fill:#e6f3ff style Manager fill:#ffe6e6 style Context fill:#ffe6f0 style VectorDB fill:#ffe6f0 style WebSearch fill:#f0f0f0 style CodeExec fill:#f0f0f0 ``` ## 11. MCP Tool Architecture ```mermaid graph TB subgraph "Agent Layer" Manager[Magentic Manager] HypAgent[Hypothesis Agent] SearchAgent[Search Agent] AnalysisAgent[Analysis Agent] ReportAgent[Report Agent] end subgraph "MCP Protocol Layer" Registry[MCP Tool Registry
• Discovers tools
• Routes requests
• Manages connections] end subgraph "MCP Servers" Server1[Web Search Server
localhost:8001
• PubMed
• arXiv
• bioRxiv] Server2[Code Execution Server
localhost:8002
• Sandboxed Python
• Package management] Server3[RAG Server
localhost:8003
• Vector embeddings
• Similarity search] Server4[Visualization Server
localhost:8004
• Chart generation
• Plot rendering] end subgraph "External Services" PubMed[PubMed API] ArXiv[arXiv API] BioRxiv[bioRxiv API] Modal[Modal Sandbox] ChromaDB[(ChromaDB)] end SearchAgent -->|Request| Registry AnalysisAgent -->|Request| Registry ReportAgent -->|Request| Registry Registry --> Server1 Registry --> Server2 Registry --> Server3 Registry --> Server4 Server1 --> PubMed Server1 --> ArXiv Server1 --> BioRxiv Server2 --> Modal Server3 --> ChromaDB style Manager fill:#ffe6e6 style Registry fill:#fff4e6 style Server1 fill:#e6f3ff style Server2 fill:#e6f3ff style Server3 fill:#e6f3ff style Server4 fill:#e6f3ff ``` ## 12. Progress Tracking & Stall Detection ```mermaid stateDiagram-v2 [*] --> Initialization: User Query Initialization --> Planning: Manager starts Planning --> AgentExecution: Select agent AgentExecution --> Assessment: Collect results Assessment --> QualityCheck: Evaluate output QualityCheck --> AgentExecution: Poor quality
(retry < max_rounds) QualityCheck --> Planning: Poor quality
(try different agent) QualityCheck --> NextAgent: Good quality
(task incomplete) QualityCheck --> Synthesis: Good quality
(task complete) NextAgent --> AgentExecution: Select next agent state StallDetection <> Assessment --> StallDetection: Check progress StallDetection --> Planning: No progress
(stall count < max) StallDetection --> ErrorRecovery: No progress
(max stalls reached) ErrorRecovery --> PartialReport: Generate partial results PartialReport --> [*] Synthesis --> FinalReport: Combine all outputs FinalReport --> [*] note right of QualityCheck Manager assesses: • Output completeness • Quality metrics • Progress made end note note right of StallDetection Stall = no new progress after agent execution Triggers plan reset end note ``` ## 13. Gradio UI Integration ```mermaid graph TD App[Gradio App
DeepCritical Research Agent] App --> Input[Input Section] App --> Status[Status Section] App --> Output[Output Section] Input --> Query[Research Question
Text Area] Input --> Controls[Controls] Controls --> MaxHyp[Max Hypotheses: 1-10] Controls --> MaxRounds[Max Rounds: 5-20] Controls --> Submit[Start Research Button] Status --> Log[Real-time Event Log
• Manager planning
• Agent selection
• Execution updates
• Quality assessment] Status --> Progress[Progress Tracker
• Current agent
• Round count
• Stall count] Output --> Tabs[Tabbed Results] Tabs --> Tab1[Hypotheses Tab
Generated hypotheses with scores] Tabs --> Tab2[Search Results Tab
Papers & sources found] Tabs --> Tab3[Analysis Tab
Evidence & verdicts] Tabs --> Tab4[Report Tab
Final research report] Tab4 --> Download[Download Report
MD / PDF / JSON] Submit -.->|Triggers| Workflow[Magentic Workflow] Workflow -.->|MagenticOrchestratorMessageEvent| Log Workflow -.->|MagenticAgentDeltaEvent| Log Workflow -.->|MagenticAgentMessageEvent| Log Workflow -.->|MagenticFinalResultEvent| Tab4 style App fill:#e1f5e1 style Input fill:#fff4e6 style Status fill:#e6f3ff style Output fill:#e6ffe6 style Workflow fill:#ffe6e6 ``` ## 14. Complete System Context ```mermaid graph LR User[👤 Researcher
Asks research questions] -->|Submits query| DC[DeepCritical
Magentic Workflow] DC -->|Literature search| PubMed[PubMed API
Medical papers] DC -->|Preprint search| ArXiv[arXiv API
Scientific preprints] DC -->|Biology search| BioRxiv[bioRxiv API
Biology preprints] DC -->|Agent reasoning| Claude[Claude API
Sonnet 4 / Opus] DC -->|Code execution| Modal[Modal Sandbox
Safe Python env] DC -->|Vector storage| Chroma[ChromaDB
Embeddings & RAG] DC -->|Deployed on| HF[HuggingFace Spaces
Gradio 6.0] PubMed -->|Results| DC ArXiv -->|Results| DC BioRxiv -->|Results| DC Claude -->|Responses| DC Modal -->|Output| DC Chroma -->|Context| DC DC -->|Research report| User style User fill:#e1f5e1 style DC fill:#ffe6e6 style PubMed fill:#e6f3ff style ArXiv fill:#e6f3ff style BioRxiv fill:#e6f3ff style Claude fill:#ffd6d6 style Modal fill:#f0f0f0 style Chroma fill:#ffe6f0 style HF fill:#d4edda ``` ## 15. Workflow Timeline (Simplified) ```mermaid gantt title DeepCritical Magentic Workflow - Typical Execution dateFormat mm:ss axisFormat %M:%S section Manager Planning Initial planning :p1, 00:00, 10s section Hypothesis Agent Generate hypotheses :h1, after p1, 30s Manager assessment :h2, after h1, 5s section Search Agent Search hypothesis 1 :s1, after h2, 20s Search hypothesis 2 :s2, after s1, 20s Search hypothesis 3 :s3, after s2, 20s RAG processing :s4, after s3, 15s Manager assessment :s5, after s4, 5s section Analysis Agent Evidence extraction :a1, after s5, 15s Code generation :a2, after a1, 20s Code execution :a3, after a2, 25s Synthesis :a4, after a3, 20s Manager assessment :a5, after a4, 5s section Report Agent Report assembly :r1, after a5, 30s Visualization :r2, after r1, 15s Formatting :r3, after r2, 10s section Manager Synthesis Final synthesis :f1, after r3, 10s ``` --- ## Key Differences from Original Design | Aspect | Original (Judge-in-Loop) | New (Magentic) | |--------|-------------------------|----------------| | **Control Flow** | Fixed sequential phases | Dynamic agent selection | | **Quality Control** | Separate Judge Agent | Manager assessment built-in | | **Retry Logic** | Phase-level with feedback | Agent-level with adaptation | | **Flexibility** | Rigid 4-phase pipeline | Adaptive workflow | | **Complexity** | 5 agents (including Judge) | 4 agents (no Judge) | | **Progress Tracking** | Manual state management | Built-in round/stall detection | | **Agent Coordination** | Sequential handoff | Manager-driven dynamic selection | | **Error Recovery** | Retry same phase | Try different agent or replan | --- ## Simplified Design Principles 1. **Manager is Intelligent**: LLM-powered manager handles planning, selection, and quality assessment 2. **No Separate Judge**: Manager's assessment phase replaces dedicated Judge Agent 3. **Dynamic Workflow**: Agents can be called multiple times in any order based on need 4. **Built-in Safety**: max_round_count (15) and max_stall_count (3) prevent infinite loops 5. **Event-Driven UI**: Real-time streaming updates to Gradio interface 6. **MCP-Powered Tools**: All external capabilities via Model Context Protocol 7. **Shared Context**: Centralized state accessible to all agents 8. **Progress Awareness**: Manager tracks what's been done and what's needed --- ## Legend - 🔴 **Red/Pink**: Manager, orchestration, decision-making - 🟡 **Yellow/Orange**: Specialist agents, processing - 🔵 **Blue**: Data, tools, MCP services - 🟣 **Purple/Pink**: Storage, databases, state - 🟢 **Green**: User interactions, final outputs - ⚪ **Gray**: External services, APIs --- ## Implementation Highlights **Simple 4-Agent Setup:** ```python workflow = ( MagenticBuilder() .participants( hypothesis=HypothesisAgent(tools=[background_tool]), search=SearchAgent(tools=[web_search, rag_tool]), analysis=AnalysisAgent(tools=[code_execution]), report=ReportAgent(tools=[code_execution, visualization]) ) .with_standard_manager( chat_client=AnthropicClient(model="claude-sonnet-4"), max_round_count=15, # Prevent infinite loops max_stall_count=3 # Detect stuck workflows ) .build() ) ``` **Manager handles quality assessment in its instructions:** - Checks hypothesis quality (testable, novel, clear) - Validates search results (relevant, authoritative, recent) - Assesses analysis soundness (methodology, evidence, conclusions) - Ensures report completeness (all sections, proper citations) No separate Judge Agent needed - manager does it all! --- **Document Version**: 2.0 (Magentic Simplified) **Last Updated**: 2025-11-24 **Architecture**: Microsoft Magentic Orchestration Pattern **Agents**: 4 (Hypothesis, Search, Analysis, Report) + 1 Manager **License**: MIT ## See Also - [Orchestrators](orchestrators.md) - Overview of all orchestrator patterns - [Graph Orchestration](graph-orchestration.md) - Graph-based execution overview - [Graph Orchestration (Detailed)](graph_orchestration.md) - Detailed graph architecture - [Workflows](workflows.md) - Workflow patterns summary - [API Reference - Orchestrators](../api/orchestrators.md) - API documentation