Skip to content

DavinciDreams/evolving-ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

169 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿค– Self-Improving AI Agent

A sophisticated AI agent with advanced self-improvement capabilities, long-term memory, and autonomous code evolution.

๐ŸŒŸ Key Features

๐Ÿง  Advanced AI Capabilities

  • Long-term Memory: Persistent memory system using ChromaDB vector embeddings
  • Dynamic Context Management: Intelligent context retrieval and management
  • Self-Evaluation: Continuous output evaluation and improvement cycles
  • Knowledge Base: Automatic knowledge acquisition and updates

๐Ÿ”„ Self-Improvement Engine

  • Code Analysis: Automated analysis of its own codebase
  • Autonomous Modifications: Safe self-modification with validation
  • GitHub Integration: Automatic pull request creation for improvements
  • Performance Monitoring: Continuous performance tracking and optimization

๐Ÿš€ Production Features

  • FastAPI Web Server: RESTful API with Swagger documentation
  • Multiple LLM Providers: Support for OpenAI, Anthropic, OpenRouter, Z AI (GLM-4.7 with coding endpoint), and more
  • Web Search Integration: Real-time web search with multiple provider support (DuckDuckGo, Tavily, SerpAPI)
  • Discord Bot: Real-time chat integration with Discord
  • Robust Error Handling: Comprehensive error management and recovery
  • Configurable Environment: Flexible configuration system

๐Ÿ“‹ Requirements

  • Python 3.8+
  • ChromaDB for vector storage
  • FastAPI for web server
  • Multiple LLM provider APIs

๐Ÿ› ๏ธ Installation

  1. Clone the repository:

    git clone <repository-url>
    cd evolving ai
  2. Install dependencies:

    pip install -r requirements.txt
  3. Configure environment:

    cp .env.example .env
    # Edit .env with your API keys and configuration

๐Ÿš€ Usage

Main Entry Points

  • Run the main agent:

    python main.py
  • Start the API server:

    python -m uvicorn api_server:app --host 127.0.0.1 --port 8000 --reload
  • Organize or clean up the project structure:

    python organize_project.py
  • Generate or summarize Swagger API docs:

    python swagger_summary.py
  • Run the complete system demo:

    python demo_complete_system.py

Self-Improvement System

To enable autonomous self-improvement and code modification, set the following in your .env file:

ENABLE_SELF_MODIFICATION=true

When enabled, the agent will:

  • Analyze its own codebase for improvements
  • Propose and validate modifications
  • Optionally create GitHub pull requests for validated changes
  • Autofix code style using isort and black before committing improvements

Linting Autofix Step: Before each code improvement is committed, the agent automatically runs isort and black to ensure code style consistency. If autofix fails for a file, that file is skipped and not committed.

Manual Linting: To manually run the same linting autofix on your codebase:

isort path/to/your/file.py
black path/to/your/file.py
# Or recursively for the whole project:
isort .
black .

Workflow:

  1. Set ENABLE_SELF_MODIFICATION=true in .env
  2. Run python main.py or start the API server
  3. The agent will autonomously analyze, modify, autofix (isort + black), and validate its code according to the self-improvement cycle

See docs/SELF_IMPROVEMENT_DEMO.md for a detailed walkthrough.

API Endpoints

Access the interactive API documentation at: http://localhost:8000/docs

Key endpoints:

  • /chat - Interact with the agent
  • /web-search - Search the web for information
  • /analyze - Code analysis and suggestions
  • /memory - Memory management
  • /knowledge - Knowledge base operations
  • /github/* - GitHub integration features
  • /discord/status - Discord bot status

GitHub Integration

# Set up GitHub integration
export GITHUB_TOKEN="your_github_token"
export GITHUB_REPO_URL="https://github.com/username/repository"

With these set, the agent can:

  • Analyze its own code
  • Create improvement pull requests
  • Track development history

Web Search Integration

The agent can search the web in real-time using multiple providers:

Available Providers:

  • DuckDuckGo (default, free, no API key required)
  • Tavily (AI-optimized search, requires API key from tavily.com)
  • SerpAPI (Google search results, requires API key from serpapi.com)

Setup:

# Enable web search (DuckDuckGo is always available)
WEB_SEARCH_ENABLED=true
WEB_SEARCH_DEFAULT_PROVIDER=duckduckgo
WEB_SEARCH_MAX_RESULTS=5

# Optional: Add API keys for better search results
TAVILY_API_KEY=your_tavily_api_key
SERPAPI_KEY=your_serpapi_key

Test Web Search:

python test_web_search.py

API Usage:

# Via API endpoint
POST /web-search
{
  "query": "Latest developments in AI",
  "max_results": 5,
  "include_content": true
}

Features:

  • Automatic fallback between providers
  • Result caching for improved performance
  • Full page content extraction
  • Search query storage in memory for learning

Discord Integration

Connect the agent to Discord for real-time chat interactions:

Setup:

  1. Create a Discord bot at discord.com/developers
  2. Enable "Message Content Intent" in bot settings
  3. Copy bot token and channel IDs
  4. Configure in .env:
DISCORD_BOT_TOKEN=your_bot_token
DISCORD_ENABLED=true
DISCORD_CHANNEL_IDS=channel_id_1,channel_id_2
DISCORD_STATUS_CHANNEL_ID=status_channel_id

Features:

  • Real-time message responses
  • Status updates for improvements
  • Rate limiting and cooldown
  • Rich embed responses

๐Ÿ”ง Configuration

Key configuration options in .env:

# LLM Configuration
OPENAI_API_KEY=your_openai_key
ANTHROPIC_API_KEY=your_anthropic_key
OPENROUTER_API_KEY=your_openrouter_key
ZAI_API_KEY=your_zai_key

# GitHub Integration
GITHUB_TOKEN=your_github_token
GITHUB_REPO_URL=your_repository_url

# Web Search Integration
WEB_SEARCH_ENABLED=true
WEB_SEARCH_DEFAULT_PROVIDER=duckduckgo
TAVILY_API_KEY=your_tavily_key  # Optional
SERPAPI_KEY=your_serpapi_key     # Optional

# Discord Integration
DISCORD_BOT_TOKEN=your_discord_token
DISCORD_ENABLED=true
DISCORD_CHANNEL_IDS=your_channel_ids

# Agent Settings
AGENT_NAME=EvolveAI
AGENT_ROLE=Senior Software Engineer

# Self-Improvement
ENABLE_SELF_MODIFICATION=true

๐Ÿงช Testing

Run all tests:

python -m pytest

Run individual test scripts:

python tests/test_complete_system.py
python tests/test_api_endpoints.py
python tests/test_github_integration.py
python tests/test_end_to_end_self_improvement.py
python tests/test_core_improvements.py
python tests/test_agent_improvements.py
python tests/test_fallback_system.py
# ...and others in the tests/ directory

๐Ÿ“š Project Structure

evolving_agent/
โ”œโ”€โ”€ core/                # Core agent functionality
โ”œโ”€โ”€ knowledge/           # Knowledge management
โ”œโ”€โ”€ self_modification/   # Code analysis and modification
โ”œโ”€โ”€ utils/               # Utilities and integrations
โ”œโ”€โ”€ tests/               # Test suite
knowledge_base/          # Knowledge base data
api_server.py            # FastAPI server entry point
main.py                  # Main agent entry point
organize_project.py      # Project organization/cleanup
swagger_summary.py       # Swagger/OpenAPI summary
demo_complete_system.py  # Demo script
requirements.txt         # Python dependencies
.env.example             # Example environment config
docs/                    # Documentation

๐Ÿค Contributing

This AI agent continuously improves itself, but manual contributions are welcome:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

The AI agent will analyze and potentially incorporate your improvements into its own evolution cycle.

๐Ÿ“„ License

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

๐Ÿ”ฎ Future Roadmap

  • Enhanced self-modification capabilities
  • Multi-agent collaboration
  • Advanced reasoning systems
  • Expanded integration ecosystem
  • Production deployment tools

This documentation was enhanced by the AI agent's self-improvement system.

About

A sophisticated AI agent with self-improvement capabilities, long-term memory, dynamic context queries, and autonomous code modification abilities.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors