Skip to content

stardashtech/Code-Agent

Repository files navigation

Code Agent: Your AI Pair Programmer 🚀

Build Status License: MIT Open Issues Stars

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.

✨ Why Choose Code Agent?

  • 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.

🔥 Features

  • 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.

🏗️ Architecture & Components

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.

⚙️ Workflow Explained

The agent processes queries through a structured, intelligent workflow:

  1. Initialization: Sets up connections (LLM, Vector Store) and attempts Docker runner initialization. Indexes code if necessary.
  2. Query Intake: Receives the user's request in natural language.
  3. Reflection: The query is analyzed for clarity and complexity. Keywords are extracted. If ambiguous, the agent asks for clarification.
  4. Planning: A dynamic plan is generated by the LLM, outlining the steps needed (e.g., search, analyze, generate, validate, apply).
  5. Execution: The PlanExecutor carries 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.
  6. Finalization: Compiles the results, status, summaries, and any generated artifacts.
  7. Output: Presents the comprehensive result to the user.

🚀 Getting Started

Prerequisites

  • 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).

Setup Instructions

  1. Clone the Magic:
    git clone <your-repository-url>
    cd <repository-directory>
  2. Prepare Your Environment:
    python3 -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
    pip install -r requirements.txt
    (Ensure requirements.txt is up-to-date)
  3. Launch Qdrant:
    • The easiest way is often Docker:
      docker run -p 6333:6333 qdrant/qdrant
    • Verify connection details in your agent's configuration.
  4. Ensure Docker Daemon is Running:
    • Required for the code validation sandbox feature.
  5. Configure API Keys:
    • Set the OPENAI_API_KEY (or other provider keys) as an environment variable OR update config.py.
    • Important: Never commit API keys directly to your repository! Use environment variables or a .env file (add .env to your .gitignore).

Running the Agent

Execute the main entry point:

python main.py  # Or the relevant script for your setup

Interact with the agent through its interface or command-line prompts.

⚠️ Known Issues

  • 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.

🤝 Contributing

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:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/YourAmazingFeature).
  3. Make your changes.
  4. Commit your changes (git commit -m 'Add some AmazingFeature').
  5. Push to the branch (git push origin feature/YourAmazingFeature).
  6. Open a Pull Request.

Please ensure your code adheres to existing style guidelines and includes tests where appropriate.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details (assuming you add an MIT license file).

💬 Community & Support

  • 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! ✨

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors