Agent Orchestration Engine
Relevant source files
The following files were used as context for generating this wiki page:
The Agent Orchestration Engine is the central coordination layer of the DeepCode project, designed to automate the complete "Research-to-Code" transformation pipeline. It manages a multi-agent system where specialized AI agents collaborate to analyze academic papers, synthesize implementation plans, acquire relevant code repositories, and generate production-ready codebases. Sources: workflows/agent_orchestration_engine.py:1-35
The engine operates using an asynchronous, high-performance architecture that leverages the Model Context Protocol (MCP) to connect with various tools and services. It supports two primary execution modes: a comprehensive Research-to-Code pipeline for academic reproduction and a streamlined Chat-Based Planning pipeline for direct user requirements. Sources: workflows/agent_orchestration_engine.py:37-45, workflows/agent_orchestration_engine.py:841-855
Core Specialized Agents
The orchestration engine coordinates several specialized agents, each with a defined role in the development lifecycle:
| Agent Role | Responsibility |
|---|---|
| Research Analysis | Processes input (PDF/URL/Text) to identify paper metadata and core requirements. |
| Concept Analysis | Analyzes system architecture and conceptual frameworks within documents. |
| Algorithm Analysis | Extracts mathematical formulas, pseudocode, and technical implementation details. |
| Code Planner | Integrates conceptual and algorithmic analysis into a unified implementation roadmap. |
| Reference Intelligence | Identifies relevant GitHub repositories cited in research papers. |
| Code Implementation | Synthesizes the final codebase using file-by-file iterative development. |
Sources: workflows/agent_orchestration_engine.py:12-25, prompts/code_prompts.py:112-280
Multi-Agent Orchestration Workflows
Research-to-Code Pipeline
This pipeline automates the transformation of a research paper into a working codebase. It follows a multi-phase approach starting from document parsing to the final code synthesis.
The diagram above illustrates the sequential execution of specialized agents in the Research-to-Code pipeline. Sources: workflows/agent_orchestration_engine.py:648-775
Chat-Based Planning Pipeline
A streamlined workflow for users who provide requirements directly via a chat interface. It bypasses academic research phases and focuses on transforming descriptions into executable plans. Sources: workflows/agent_orchestration_engine.py:841-860
The sequence diagram shows the interaction flow for direct requirement-to-code generation. Sources: workflows/agent_orchestration_engine.py:862-950
Implementation Mechanisms
Adaptive Document Segmentation
For large research papers, the engine employs a document segmentation strategy to overcome token limits. It splits documents into manageable chunks based on query types (e.g., "algorithm_extraction" or "concept_analysis") before passing them to the analysis agents. Sources: prompts/code_prompts.py:112-140, workflows/agent_orchestration_engine.py:530-580
Iterative Code Synthesis Loop
Code implementation is handled through a "Pure Code Implementation Loop." This loop utilizes a specialized ConciseMemoryAgent to manage context efficiently by clearing history after each successful write_file operation while preserving the original plan and current tool results. Sources: workflows/code_implementation_workflow_index.py:188-230, workflows/agents/memory_agent_concise_index.py:30-55
This flow details the development cycle for individual files within the implementation phase. Sources: workflows/code_implementation_workflow_index.py:232-280, prompts/code_prompts.py:540-570
System Configuration and Servers
The engine relies on a set of Model Context Protocol (MCP) servers to interact with the environment. Sources: workflows/agent_orchestration_engine.py:48-80
| Server Name | Functionality |
|---|---|
command-executor | Runs shell commands for directory and file creation. |
filesystem | Performs local file read/write operations. |
file-downloader | Downloads and converts documents (e.g., PDF to Markdown). |
github-downloader | Clones or downloads GitHub repositories. |
code-implementation | Provides specialized tools for codebase development. |
code-reference-indexer | Manages indexes of related codebases for reference. |
Sources: workflows/agent_orchestration_engine.py:165-175, workflows/code_implementation_workflow_index.py:320-340
Search Server Selection
The orchestration engine dynamically selects a search server (e.g., brave or bocha-mcp) based on the mcp_agent.config.yaml file to perform external knowledge retrieval. Sources: workflows/agent_orchestration_engine.py:48-69
Technical Accuracy & Constraints
- Token Management: Uses
RequestParamswithmax_tokensup to 8192 for high-capacity models like Claude 3.5 Sonnet. Sources: workflows/agent_orchestration_engine.py:440-450 - Workspace Safety: All code is generated within a
generate_codesubdirectory inside the targeted paper workspace to prevent accidental file overwrites. Sources: workflows/code_implementation_workflow_index.py:120-130 - Language Standards: Enforces production-grade code with full type hints, docstrings, and error handling through system prompts. Sources: prompts/code_prompts.py:390-410
The Agent Orchestration Engine serves as the backbone of DeepCode, transforming high-level intent or complex research into executable software through structured multi-agent collaboration. Sources: workflows/agent_orchestration_engine.py:1-45