Skip to main content
The Programming Assistant Agent (also known as General Coder) provides comprehensive programming help without requiring a specific repository. It can write code, execute it, debug issues, and provide detailed explanations.

Overview

Implemented in src/services/agents/agent_general_coder.py:19, the GeneralCoder class provides a clean workspace for programming tasks through two specialized agents:
  • General_Coder Agent: Plans code solutions and provides programming guidance
  • Coder_Excute Agent: Executes code and returns results

Key Features

Code Generation

Write complete, executable code solutions from task descriptions

Code Execution

Execute code in a safe environment and return results

Debugging Help

Identify and fix errors with detailed explanations

File Management

Automatically track and summarize created files

Usage

Basic Usage

from src.services.agents.agent_general_coder import GeneralCoder
from configs.oai_config import get_llm_config
import asyncio

# Initialize
llm_config = get_llm_config()
code_execution_config = {
    "work_dir": "coding/workspace",
    "use_docker": False
}

coder = GeneralCoder(
    llm_config=llm_config,
    code_execution_config=code_execution_config
)

# Execute a coding task
task = "Calculate NVIDIA's maximum drawdown in 2024"
result = asyncio.run(coder.create_code_tool(
    task_description=task
))
print(result)

CLI Mode

# Launch Programming Assistant directly
python launcher.py --mode general_assistant

# Interactive prompt
💻 Please describe your programming task: 
   Write a function to calculate Fibonacci numbers

🔧 Processing...
📋 Task result: [code solution with explanation]

Methods

create_code_tool()

Generate, execute code and return execution results. Source: src/services/agents/agent_general_coder.py:95
task_description
str
required
Detailed description of the task, including required operations and expected results (not code)
context
str | dict
default:"None"
Additional background information or context for the task (includes user’s original question, necessary information, data paths, etc.)
required_libraries
list
default:"None"
List of Python libraries that might be needed for the task
Returns: Union[str, dict] - Execution results or dictionary with execution_result and file_summary
async def create_code_tool(
    self,
    task_description: str,
    context: Optional[str|dict] = None,
    required_libraries: Optional[list] = None,
) -> Union[str, dict]:
    """
    Generate, execute code and return the execution results.
    
    This function uses an AI coding assistant to generate code, 
    then executes the code and returns the execution results.
    """

Example with Context

result = await coder.create_code_tool(
    task_description="Analyze stock data and create visualizations",
    context={
        "data_file": "stocks.csv",
        "metrics": ["price", "volume", "volatility"]
    },
    required_libraries=["pandas", "matplotlib", "numpy"]
)

Configuration

Initialization Parameters

llm_config
dict
required
LLM configuration dictionary with API settings
code_execution_config
dict
required
Code execution configuration including work_dir and use_docker settings
connection_id
str
default:"None"
Optional connection ID for tracking
send_message_function
callable
default:"None"
Optional callback function for sending messages
agent_history
list
default:"None"
Optional list of previous conversation history

Working Directory

The agent automatically manages files in its working directory:
code_execution_config = {
    "work_dir": "coding/my_project",  # Files will be created here
    "use_docker": False
}

Code Quality Features

The Programming Assistant follows best practices enforced through system prompts:
For complex problems, the agent automatically:
  • Breaks down tasks into logical components
  • Creates separate files for each component
  • Executes files in proper sequence
  • Example: data_fetcher.py, data_processor.py, visualizer.py
Source: src/services/agents/agent_general_coder.py:85
The agent automatically:
  • Tracks all created files
  • Adds descriptions using insert_file_description_to_file()
  • Maintains a Task_description.json file
  • Only saves files after successful execution
Source: src/services/agents/agent_general_coder.py:84
The agent:
  • Filters out failed execution attempts from history
  • Only includes successful code in final output
  • Provides clear error messages
  • Retries with corrected code
Source: src/services/agents/agent_general_coder.py:226
Enforced practices:
  • Avoid repetitive and redundant code
  • Separate analysis from execution code
  • Only output executable code in code blocks
  • First explain approach, then provide clean code
  • No mixed explanations within code blocks
Source: src/services/agents/agent_general_coder.py:86

File Management

Automatic File Summarization

The agent uses LLM to analyze created files and categorize them: Source: src/services/agents/agent_general_coder.py:146
# Example return format
{
    "execution_result": "Task completed successfully",
    "file_summary": {
        "code_files": [
            {"filename": "analyzer.py", "description": "Stock data analysis script"}
        ],
        "data_files": [
            {"filename": "results.csv", "description": "Analysis results"}
        ],
        "image_files": [
            {"filename": "plot.png", "description": "Visualization of trends"}
        ]
    }
}

Task Description File

The agent maintains Task_description.json to track files across sessions:
{
    "stock_data.csv": "NVIDIA stock data for 2024",
    "analyzer.py": "Script to calculate maximum drawdown",
    "plot.png": "Visualization of stock performance"
}

Example Use Cases

task = """
Analyze the CSV file 'sales_data.csv' and:
1. Calculate monthly revenue trends
2. Identify top 5 products by sales
3. Create a visualization
"""

result = await coder.create_code_tool(
    task_description=task,
    required_libraries=["pandas", "matplotlib", "seaborn"]
)

Integration with Scheduler

The Programming Assistant is accessible through the RepoMaster scheduler: Source: src/core/agent_scheduler.py:273
from src.core.agent_scheduler import RepoMasterAgent

agent = RepoMasterAgent(
    llm_config=llm_config,
    code_execution_config=code_execution_config
)

result = agent.run_general_code_assistant(
    task_description="Create a function to calculate prime numbers",
    work_directory="coding/workspace"
)

Conversation Parameters

The agent uses the following parameters for code generation conversations: Source: src/services/agents/agent_general_coder.py:125
max_turns=50  # Maximum conversation turns
summary_method="reflection_with_llm"  # Use LLM for summarization
summary_prompt="Summarize takeaway from the conversation and 
                generate a complete and detailed report at last."

Limitations

  • No Repository Context: Does not have access to existing codebases or repositories
  • Fresh Workspace: Each session starts with a clean working directory
  • Limited to Python: Primarily focused on Python code execution
  • No Web Access: Cannot search the internet or access external resources

When to Use Programming Assistant

Good for:
  • Writing standalone scripts and utilities
  • Learning programming concepts with examples
  • Implementing algorithms and data structures
  • Quick prototyping and experimentation
  • Debugging code snippets
Not ideal for:
  • Tasks requiring specific libraries in repositories
  • Complex multi-file projects with dependencies
  • Tasks requiring web search or real-time data
  • Working with existing codebases

Next Steps

Repository Agent

Learn about repository analysis and execution

Unified Interface

Use intelligent multi-agent orchestration

Build docs developers (and LLMs) love