Skip to content

ShaileshKumar97/Intelligent-Python-Coding-Agent

Repository files navigation

Intelligent Python Coding Agent

An AI-powered coding assistant that interprets natural language queries, generates optimized Python code, executes it securely, and provides detailed explanations.

Features

  • 🧠 Natural Language Understanding: Processes and understands coding requests in natural language
  • 💻 Code Generation: Produces high-quality, optimized Python code tailored to your requirements
  • 🔒 Secure Execution: Runs generated code in a sandboxed environment with resource limits
  • 📚 Comprehensive Explanations: Provides detailed explanations of the generated code
  • 🔄 Interactive Feedback: Learns from user feedback to improve over time
  • 🌐 Multiple Interfaces: Command-line and REST API interfaces

Architecture

The system is built with a modular architecture consisting of the following components:

  • NLP Query Processor: Analyzes natural language coding requests
  • Code Generator: Produces high-quality Python code using LLMs
  • Security Validator: Checks code for security issues before execution
  • Code Executor: Runs code in a secure sandbox environment
  • Explanation Generator: Creates detailed explanations of generated code
  • Feedback Handler: Processes user feedback to improve the system

Installation

  1. Clone the repository:

    git clone https://github.com/ShaileshKumar97/Intelligent-Python-Coding-Agent.git
    cd Intelligent-Python-Coding-Agent
  2. Create a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. Set up environment variables:

    export CODEAGENT_OPENAI_API_KEY=your_api_key_here
    # Or create a .env file with the above

Usage

Command-line Interface

Run the agent in interactive mode:

python agent_cli.py --interactive

Process a single query:

python agent_cli.py --query "Generate a Python function to compute the factorial of a number using recursion."

For more options:

python agent_cli.py --help

REST API

Start the API server:

python agent_api.py

The server will be available at http://localhost:8000 with Swagger documentation at http://localhost:8000/docs.

Example API request:

curl -X POST "http://localhost:8000/api/query" \
  -H "Content-Type: application/json" \
  -d '{"query": "Generate a Python function to compute the factorial of a number using recursion."}'

Configuration

The agent can be configured through the config/agent_config.json file. Key configuration options include:

  • LLM Models: Choose which models to use for different components
  • Execution Settings: Configure timeout, memory limits, and sandbox settings
  • Security Options: Set security validation strictness
  • Explanation Preferences: Configure technical level and detail level
  • Feedback Settings: Enable/disable learning from feedback

Project Structure

intelligent-python-coding-agent/
├── agent/                             # Core agent modules
│   ├── __init__.py
│   ├── code_executor.py               # Secure code execution
│   ├── code_generator.py              # Code generation module
│   ├── explanation_generator.py       # Explanation generation
│   └── feedback_handler.py            # Feedback processing
│   ├── intelligent_coding_agent.py    # Main agent class
│   ├── nlp_processor.py               # NLP query processor
├── config/                            # Configuration
│   ├── __init__.py
│   ├── agent_config.json              # Default configuration
│   └── settings.py                    # Configuration management
├── tests/                             # Tests modules
│   └── tests_agent.py                 # Unit and Integration Test cases
├── utils/                             # Utility modules
│   ├── __init__.py
│   ├── logger.py                      # Logging utilities
│   └── security.py                    # Security utilities
├── agent_cli.py                       # Command-line interface
├── agent_api.py                       # REST API interface
└── README.md                          # This file
├── requirements.txt                   # Dependencies

Examples

Simple Algorithm Task

python agent_cli.py --query "Generate a Python function to compute the factorial of a number using recursion."

Data Processing Task

python agent_cli.py --query "Create a script that reads a CSV file, filters rows where the 'age' column is above 30, and writes the result to a new CSV file."

Algorithmic Complexity Task

python agent_cli.py --query "Develop a Python solution for the knapsack problem using dynamic programming and explain the time complexity."

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • This project uses OpenAI's GPT models for natural language processing and code generation
  • Built with LangChain for AI orchestration

Future Improvements

  • Support for additional programming languages
  • Visual interface for code generation and execution
  • Real-time collaboration features
  • Integration with version control systems
  • Support for more complex project structures and dependencies

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors