Code Agent is a cutting-edge, AI-powered assistant designed to revolutionize how you interact with your codebase. It understands your needs, analyzes code semantically, suggests intelligent improvements, and can even automate modifications, acting like an experienced pair programmer.
Leveraging the power of Large Language Models (LLMs) and advanced techniques like semantic search and dynamic planning, Code Agent goes beyond simple syntax checking to provide deep insights and actionable suggestions. Whether you're trying to understand complex logic, add new features, refactor existing code, or identify potential bugs, Code Agent is here to accelerate your development workflow.
- Intelligent Code Comprehension: Moves beyond keyword matching to truly understand the intent behind your queries and the logic within your code.
- Accelerated Development: Automates tedious tasks like finding relevant code sections, generating boilerplate, and applying refactoring patterns.
- Enhanced Code Quality: Proactively suggests improvements, identifies potential issues, and helps maintain consistency across your codebase.
- Dynamic & Adaptive: Doesn't rely on fixed rules; it uses reflection and dynamic planning to tailor its approach to your specific query and codebase context.
- Safe & Secure: Includes an optional Docker-based sandbox for validating code changes in an isolated environment before applying them.
- Extensible Architecture: Built with modularity in mind, ready for future integrations and tool additions.
- Natural Language Interface: Converse with the agent using plain English.
- Deep Semantic Search: Pinpoints relevant code snippets across your project using vector embeddings (Qdrant), even if you don't know the exact function or variable names.
- LLM-Powered Analysis: Utilizes state-of-the-art LLMs (like GPT via OpenAI) for sophisticated code analysis, explanation, and reasoning.
- Automated Code Generation & Modification: Generates code patches, new functions, or refactoring suggestions based on your requests.
- Reflection & Dynamic Planning: Intelligently assesses query clarity and dynamically creates multi-step plans to tackle complex tasks.
- Optional Sandbox Validation: Safely test generated code within a Docker container to catch errors before they hit your main codebase. (Requires Docker)
- Automated File Backup: Automatically creates backups before modifying any files, ensuring you can always revert changes.
- Configurable & Modular: Easily configure API keys, model preferences, and other settings.
Code Agent employs a sophisticated, modular architecture:
| Component | Location | Role |
|---|---|---|
| Code Agent Service | app/services/code_agent.py |
Main orchestrator, manages the end-to-end workflow and coordinates components. |
| Reflection Engine | agent/reflection.py, app/agents/* |
Assesses query clarity, extracts keywords, decomposes tasks, informs planning. |
| Dynamic Planner | app/agents/planner.py |
Generates context-aware, multi-step execution plans using LLMs. |
| Plan Executor | app/services/plan_executor.py |
Executes the plan step-by-step, managing state and invoking tools/LLMs. |
| Vector Store Manager | app/services/vector_store_manager.py |
Interfaces with Qdrant for storing code embeddings and performing lightning-fast semantic searches. |
| LLM Interface | models/llm.py |
Standardized interface for interacting with various LLM providers (e.g., OpenAI). |
| Docker Sandbox Runner | app/services/docker_runner.py |
(Optional) Provides a secure Docker environment for code validation and execution. |
| Configuration | config.py |
Manages application settings, API keys, and service endpoints. |
| Logging Service | agent/logger.py |
Provides structured logging throughout the agent's operation. |
The agent processes queries through a structured, intelligent workflow:
- Initialization: Sets up connections (LLM, Vector Store) and attempts Docker runner initialization. Indexes code if necessary.
- Query Intake: Receives the user's request in natural language.
- Reflection: The query is analyzed for clarity and complexity. Keywords are extracted. If ambiguous, the agent asks for clarification.
- Planning: A dynamic plan is generated by the LLM, outlining the steps needed (e.g., search, analyze, generate, validate, apply).
- Execution: The
PlanExecutorcarries out the plan:- Search: Finds relevant code via the
VectorStoreManager. - Analyze: Uses the LLM to understand the code in the context of the query.
- Generate Fix: Instructs the LLM to create the necessary code changes.
- Validate: (If Docker is enabled) Executes the fix in the sandbox.
- Apply: Backs up the original file and applies the validated changes.
- Search: Finds relevant code via the
- Finalization: Compiles the results, status, summaries, and any generated artifacts.
- Output: Presents the comprehensive result to the user.
- Python 3.9+
- Docker Engine & Docker Compose (Recommended, required for sandbox validation)
- Access to a Qdrant vector database instance.
- An API key for your chosen LLM provider (e.g., OpenAI).
- Clone the Magic:
git clone <your-repository-url> cd <repository-directory>
- Prepare Your Environment:
(Ensure
python3 -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate` pip install -r requirements.txt
requirements.txtis up-to-date) - Launch Qdrant:
- The easiest way is often Docker:
docker run -p 6333:6333 qdrant/qdrant
- Verify connection details in your agent's configuration.
- The easiest way is often Docker:
- Ensure Docker Daemon is Running:
- Required for the code validation sandbox feature.
- Configure API Keys:
- Set the
OPENAI_API_KEY(or other provider keys) as an environment variable OR updateconfig.py. - Important: Never commit API keys directly to your repository! Use environment variables or a
.envfile (add.envto your.gitignore).
- Set the
Execute the main entry point:
python main.py # Or the relevant script for your setupInteract with the agent through its interface or command-line prompts.
- Docker Sandbox Runner Initialization: The agent gracefully handles cases where Docker isn't running or accessible by skipping the optional "Validate Code (Sandbox)" step. To enable validation, ensure Docker is installed and the daemon is active. Look for errors like
docker.errors.DockerException: Error while fetching server API version...in the logs if you encounter issues.
We welcome contributions to make Code Agent even more powerful! Whether it's bug fixes, feature enhancements, documentation improvements, or new tool integrations, please feel free to:
- Fork the repository.
- Create a new branch (
git checkout -b feature/YourAmazingFeature). - Make your changes.
- Commit your changes (
git commit -m 'Add some AmazingFeature'). - Push to the branch (
git push origin feature/YourAmazingFeature). - Open a Pull Request.
Please ensure your code adheres to existing style guidelines and includes tests where appropriate.
This project is licensed under the MIT License - see the LICENSE file for details (assuming you add an MIT license file).
- Issues: Report bugs or suggest features via GitHub Issues.
- (Optional): Add links to Discord, Slack, mailing lists, etc.
Let's build the future of coding together with Code Agent! ✨