Prompt Management
Relevant source files
The following files were used as context for generating this wiki page:
Prompt Management in the DeepCode project refers to the systematic organization, generation, and refinement of Large Language Model (LLM) instructions designed to facilitate the autonomous reproduction of research papers and complex software systems. It serves as the cognitive framework that guides various specialized agents through a multi-stage pipeline, from initial paper analysis and reference indexing to final code implementation and validation. Sources: prompts/code_prompts.py:1-20, workflows/code_implementation_workflow.py:140-160
The system employs a multi-agent orchestration strategy where prompts are categorized into functional groups such as input analysis, algorithm extraction, code planning, and memory management. This ensures that each component of the Paper2Code workflow receives precise, role-aware instructions tailored to specific technical tasks. Sources: prompts/code_prompts.py:22-100, ui/components.py:100-130
Multi-Stage Workflow Prompts
The prompt architecture is structured to mirror the research reproduction lifecycle. This involves a sequence of specialized prompts that transform raw academic text into executable codebases.
Input Analysis and Acquisition
Before implementation begins, prompts are used to analyze input types (URLs, PDFs, or directories) and manage the acquisition of source materials. The PAPER_INPUT_ANALYZER_PROMPT enforces a strict JSON-only output to ensure machine-readability of the detected metadata. Sources: prompts/code_prompts.py:22-55
Research Paper Decomposition
Two core prompts handle the deep analysis of research documents:
- Algorithm Analysis: The
PAPER_ALGORITHM_ANALYSIS_PROMPTutilizes a "Segmented Reading Strategy" to extract mathematical formulations, pseudocode, and hyperparameters without exceeding token limits. Sources: prompts/code_prompts.py:164-280 - Concept Analysis: The
PAPER_CONCEPT_ANALYSIS_PROMPTmaps the paper's theoretical foundations and structural components to an implementation roadmap. Sources: prompts/code_prompts.py:282-390
The diagram shows the sequential flow of information through specialized prompts during the paper-to-code transformation process. Sources: prompts/code_prompts.py:22-500, workflows/code_implementation_workflow.py:180-200
Memory and Context Management Prompts
To handle long-running development sessions, the system uses specific prompts to manage "sliding window" memory and summarize implementation progress.
Concise Memory Agents
The ConciseMemoryAgent uses a "clean slate" approach triggered after every write_file tool call. This prevents the accumulation of conversational clutter while preserving the initial plan and the latest technical context. Sources: workflows/agents/memory_agent_concise.py:16-50, workflows/agents/memory_agent_concise_index.py:480-520
Role-Aware Summarization
The CONVERSATION_SUMMARY_PROMPT is designed to be role-aware, distinguishing between user instructions (requirements/feedback) and assistant messages (technical decisions/implementations). This reduces token usage by 70-80% while maintaining continuity. Sources: prompts/code_prompts.py:560-605
| Prompt Variable | Target Agent | Primary Output Format | Purpose |
|---|---|---|---|
PAPER_INPUT_ANALYZER_PROMPT | Input Analyzer | Raw JSON | Path classification and metadata extraction |
PAPER_ALGORITHM_ANALYSIS_PROMPT | Extraction Agent | Structured YAML | Capturing formulas and pseudocode |
CODE_PLANNING_PROMPT | Planning Agent | Detailed YAML Plan | Integrating analysis into a file structure |
CONVERSATION_SUMMARY_PROMPT | Summary Agent | Markdown Summary | Token reduction and role-specific context preservation |
Sources: prompts/code_prompts.py:22-605, workflows/agents/memory_agent_concise.py:280-320
Implementation and Logic Execution
Implementation prompts are responsible for the physical creation of the codebase. They bridge the gap between high-level plans and shell-level operations.
Structure Generation
The STRUCTURE_GENERATOR_PROMPT analyzes the implementation plan to produce shell commands (mkdir -p, touch). It ensures that the target directory (e.g., /generate_code) matches the logical architecture defined in the previous phases. Sources: prompts/code_prompts.py:516-545, workflows/code_implementation_workflow.py:230-260
Iterative Code Writing
The PURE_CODE_IMPLEMENTATION_SYSTEM_PROMPT guides the assistant through an iterative development cycle. It enforces a strict "Observe -> Plan -> Execute" loop where only one tool call is permitted per message to ensure precision. Sources: prompts/code_prompts.py:640-725, workflows/code_implementation_workflow_index.py:150-180
This sequence diagram illustrates the feedback loop between implementation prompts, memory optimization, and tool execution. Sources: workflows/agents/memory_agent_concise.py:530-580, workflows/code_implementation_workflow.py:280-320
Conclusion
Prompt Management in this project is characterized by its modularity and strict adherence to structured outputs. By separating algorithm extraction from architectural planning and utilizing concise memory strategies, the system maintains high technical accuracy across complex, multi-file code reproduction tasks. Sources: prompts/code_prompts.py:5-15, workflows/code_implementation_workflow.py:460-490