Introduction to DeepCode
Relevant source files
The following files were used as context for generating this wiki page:
DeepCode is an open-source agentic coding platform designed to revolutionize research reproducibility and automated software development. Developed by the Data Intelligence Lab at HKU, the system utilizes a multi-agent architecture to transform complex inputs—such as academic papers or natural language requirements—into production-ready, executable codebases.
Sources: ui/components.py:16-25, ui/components.py:44-50
The project focuses on three primary pipelines: Paper2Code for research implementation, Text2Web for front-end prototyping, and Text2Backend for scalable architecture generation. These workflows are orchestrated by a central engine that manages specialized agents, dynamic task planning, and intelligent memory management via Model Context Protocol (MCP).
Sources: ui/components.py:75-92, workflows/code_implementation_workflow.py:27-35
Core System Architecture
DeepCode's architecture is built on a "Standard MCP" (Model Context Protocol) framework. This structure separates the high-level workflow orchestration from the low-level execution environment, allowing for modular tool use and cross-agent collaboration.
Multi-Agent Orchestration
The system utilizes specialized agents to handle distinct phases of the code generation lifecycle. This includes structure generation, code implementation, and concise memory management.
The diagram shows the flow from user input through the orchestrator to specialized agents, which interact with specific MCP server tools.
Sources: workflows/code_implementation_workflow_index.py:27-40, workflows/code_implementation_workflow_index.py:118-124
Implementation Components
| Component | Responsibility | Relevant Files |
|---|---|---|
| Workflow Manager | Orchestrates phases (Analyze, Plan, Implement) | code_implementation_workflow.py |
| CodeImplementationAgent | Executes tool calls and generates source code | workflows/agents/ |
| ConciseMemoryAgent | Manages token usage and context preservation | memory_agent_concise.py |
| StructureGeneratorAgent | Parses plans and creates directory trees | prompts/code_prompts.py |
Sources: workflows/code_implementation_workflow.py:45-55, workflows/agents/memory_agent_concise.py:31-45
High-Level Workflow: Paper2Code
The flagship Paper2Code workflow follows a systematic pipeline to move from a research document to a functional repository.
- Input Analysis: Analyzes URLs, PDF paths, or text to determine the input type.
- Paper Downloading/Conversion: Converts various formats into Markdown for LLM ingestion.
- Concept & Algorithm Analysis: Extracts mathematical formulations, pseudocode, and structural maps.
- Code Planning: Synthesizes analysis into a detailed reproduction plan (max 15 files).
- Implementation: Executes iterative development with a "Clean Slate" memory strategy.
Sources: prompts/code_prompts.py:44-65, prompts/code_prompts.py:173-195, prompts/code_prompts.py:382-395
The Paper2Code pipeline from initial document ingestion to the final validated codebase.
Sources: prompts/code_prompts.py:20-30, ui/components.py:95-110
Intelligent Memory Management
To handle long-running development sessions without hitting token limits, DeepCode implements a Concise Memory Strategy. This logic ensures the LLM focuses only on the immediate task while maintaining global awareness of the project plan.
Memory Optimization Logic
The ConciseMemoryAgent follows a specific lifecycle:
- Before First File: Maintains normal conversation flow.
- After First File: Discards conversational history.
- Clean Slate: Triggers after every
write_filecall, retaining only the System Prompt, Initial Plan, and current round tool results.
Sources: workflows/agents/memory_agent_concise.py:11-20, workflows/agents/memory_agent_concise_index.py:598-615
Essential Tools Tracked
The memory agent specifically records results from essential tools to provide context for the next implementation cycle:
| Tool Category | Tool Names |
|---|---|
| File Operations | read_code_mem, read_file, write_file |
| Code Analysis | search_code, search_reference_code, get_file_structure |
| Execution | execute_python, execute_bash |
Sources: workflows/agents/memory_agent_concise.py:55-65, workflows/agents/memory_agent_concise_index.py:494-510
Technical Implementation Details
Configuration & Models
The system is configured via mcp_agent.secrets.yaml and supports both Anthropic and OpenAI providers.
# Example Configuration from workflow initialization
default_models:
anthropic: "claude-sonnet-4-20250514"
openai: "gpt-4o"
Sources: workflows/agents/memory_agent_concise.py:75-80, workflows/code_implementation_workflow.py:48-52
The Development Cycle
Within the implementation loop, the agent follows a strict cycle to ensure consistency:
- Read: Calls
read_code_memto understand existing interfaces. - Reference: Optionally calls
search_code_referencesfor inspiration. - Implement: Uses
write_fileto generate complete code (no placeholders). - Test: Executes code via
execute_pythonto verify accuracy.
Sources: prompts/code_prompts.py:760-775, workflows/code_implementation_workflow_index.py:275-290
User Interface and Interaction
DeepCode provides a Streamlit-based UI for monitoring the multi-stage workflow. It includes status indicators for initialization, analysis, planning, and implementation.
Sequence of events between the user, the UI components, and the backend workflow orchestration.
Conclusion
DeepCode serves as a comprehensive bridge between research and production. By combining specialized agents with the Model Context Protocol and an aggressive concise memory strategy, it enables the automated generation of complex, multi-file codebases while maintaining high technical accuracy and reproducibility.
Sources: ui/components.py:230-250, workflows/code_implementation_workflow_index.py:410-435