A powerful AI-powered code assistant that helps you generate documentation, refactor code, detect bugs, and more using Large Language Models (LLMs).
Note: Only Google Gemini (google-genai) is required by default. If you use OpenAI, Anthropic, or Ollama, TheAgent will prompt you to install the required package the first time you use that provider.
- Documentation Generation: Generate comprehensive docstrings for Python functions
- Code Summarization: Get clear summaries of your code's functionality
- Test Generation: Automatically generate unit tests for your code
- Bug Detection: Identify potential bugs and issues in your code
- Code Refactoring: Improve code quality and readability
- Type Annotation: Add type hints to your Python code
- Code Migration: Migrate code to newer Python versions
- Interactive Chat: Chat with the agent for code-related questions
- Enhanced Safety: Built-in safety checks and user approval workflows
- File Management: List, read, and manage files in your project
- Context Awareness: Understand your project structure and file relationships
Provider | Models (examples) | Env Variable(s) | PyPI Package |
---|---|---|---|
openai | gpt-4o, gpt-3.5-turbo | OPENAI_API_KEY |
openai (optional) |
anthropic | claude-3-haiku-20240307 | ANTHROPIC_API_KEY |
anthropic (optional) |
gemini-2.5-flash | GOOGLE_GENAI_API_KEY |
google-genai (default) |
|
ollama | llama2, phi3, etc. | OLLAMA_HOST (opt.) |
ollama (optional) |
Provider packages are installed on demand. If you select a provider and the required package is missing, TheAgent will prompt you to install it automatically.
# Clone the repository
# (for development or latest version)
git clone https://github.com/haroon0x/theagent.git
cd theagent
pip install -e .
-
Get API Keys: Sign up for your preferred LLM provider:
- OpenAI: Get your API key at OpenAI Platform
- Anthropic: Get your API key at Anthropic Console
- Google: Get your API key at Google AI Studio
- Ollama: Install locally at Ollama.ai (no API key needed)
-
Environment Setup: Create a
.env
file with your API keys:# Choose one or more providers OPENAI_API_KEY=your_openai_key_here ANTHROPIC_API_KEY=your_anthropic_key_here GOOGLE_GENAI_API_KEY=your_google_key_here OLLAMA_HOST=http://localhost:11434 # Optional, defaults to localhost
# Generate docstrings for a Python file using OpenAI GPT-4o
theagent --file main.py --agent doc --provider openai --model gpt-4o
# Use Anthropic Claude 3
theagent --file main.py --agent doc --provider anthropic --model claude-3-haiku-20240307
# Use Google Gemini
theagent --file main.py --agent doc --provider google --model gemini-2.5-flash
# Use Ollama (local)
theagent --file main.py --agent doc --provider ollama --model llama2
# Start interactive chat with Gemini
theagent --chat --provider google --model gemini-2.5-flash
# Use enhanced mode with Anthropic Claude 3
theagent --file main.py --agent doc --enhanced --provider anthropic --model claude-3-haiku-20240307
Option | Description | Default | Required |
---|---|---|---|
--file, -f |
Python file to process | None | For file processing |
--agent, -a |
Type of agent (doc, summary, test, bug, refactor, type, migration) | None | For file processing |
--output, -o |
Output mode (console, in-place, new-file) | console | No |
--provider |
LLM provider (openai, anthropic, google, ollama) | openai | No |
--model |
LLM model to use (e.g., gpt-4o, claude-3-haiku-20240307, gemini-2.5-flash) | None | No |
--enhanced |
Use enhanced flow with safety checks | False | No |
--chat |
Start interactive chat mode | False | No |
--verbose, -v |
Enable verbose output | False | No |
--no-confirm |
Skip user confirmation prompts | False | No |
--migration-target |
Target for code migration | Python 3 | No |
--save-session |
Save chat session to file on exit | None | No |
--load-session |
Load chat session from file at start | None | No |
--context-files |
Comma-separated list of files to load as project context | None | No |
--openai-api-key |
OpenAI API key (overrides env/config) | None | No |
--anthropic-api-key |
Anthropic API key (overrides env/config) | None | No |
--google-api-key |
Google Gemini API key (overrides env/config) | None | No |
--ollama-host |
Ollama host URL (overrides env/config) | None | No |
- Use
theagent --help
for full CLI help. - Use
theagent --version
to print the current version.
You can also store your API keys and Ollama host in a .theagent.toml
file in your project root:
openai_api_key = "sk-..."
anthropic_api_key = "..."
google_api_key = "..."
ollama_host = "http://localhost:11434"
Precedence order:
- CLI argument (e.g.
--openai-api-key
) .theagent.toml
config file- Environment variable (e.g.
OPENAI_API_KEY
) .env
file (auto-loaded)- Provider default (for Ollama host)
This makes it easy to manage credentials for different projects or environments.
# Generate docstrings for all functions in main.py
theagent --file main.py --agent doc --output in-place
# Get a summary of your code
theagent --file main.py --agent summary
# Detect potential bugs
theagent --file main.py --agent bug --verbose
# Start chat mode for interactive help
theagent --chat
# In chat mode, try these commands:
# - "list files in current directory"
# - "read main.py"
# - "generate docstrings for main.py"
# - "what does this code do?"
# Use enhanced mode with safety checks and user approval
theagent --file main.py --agent doc --enhanced
# This will:
# 1. Check file safety before modification
# 2. Generate the requested changes
# 3. Ask for user approval
# 4. Allow refinement if needed
TheAgent uses a modular architecture with:
- Flow-based Processing: Uses PocketFlow for orchestration
- Node-based Agents: Specialized nodes for different tasks, each aware of provider/model
- LLM Integration: Supports OpenAI, Anthropic, Google Gemini, and Ollama (local)
- Safety Features: Built-in checks and user approval workflows
- Error Handling: Robust error handling with fallback responses
# Run all tests
pytest
# Run specific test file
pytest tests/test_agent_nodes_comprehensive.py
# Run with verbose output
pytest -v
theagent/
βββ src/theagent/
β βββ __init__.py
β βββ main.py # Main CLI entry point
β βββ flow.py # Flow definitions
β βββ nodes.py # Agent node implementations
β βββ utils/
β βββ __init__.py
β βββ call_llm.py # LLM integration
β βββ visualize_flow.py # Flow visualization
βββ docs/ # Documentation
βββ tests/ # Test files
βββ requirements.txt # Dependencies
βββ pyproject.toml # Package configuration
βββ README.md # This file
- Create a new node in
src/theagent/nodes.py
- Add the node to the flow in
src/theagent/flow.py
- Update the CLI options in
src/theagent/main.py
- Add tests and documentation
# Visualize a specific flow
python -m src.theagent.utils.visualize_flow src.theagent.flow:create_chat_flow
# This generates a Mermaid diagram showing the flow structure
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Issues: Report bugs and request features on GitHub
- Discussions: Join discussions about features and improvements
- Documentation: Check the
docs/
folder for detailed documentation
- Web interface
- More LLM providers (OpenAI, Anthropic, Ollama)
- Advanced code analysis
- Integration with IDEs
- Batch processing
- Custom agent training
TheAgent - Making code development easier with AI! π€β¨