Py Code Agent - AI Coding Assistant with LiteLLM
Project description
Py Code Agent
AI coding assistant with ReAct reasoning, pluggable architecture, and 5-layer self-healing. Powered by LiteLLM for 100+ model providers.
๐ Features
- ๐ค Multi-LLM Support: 100+ providers via LiteLLM (OpenAI, Anthropic, Azure, Ollama, etc.)
- ๐ง ReAct Reasoning: Thought โ Action โ Observation loop for autonomous task execution
- ๐ Plugin System: pluggy-based extensible architecture with 5-layer self-healing
- ๐ Channel System: CLI, WebSocket, and pluggable transport channels
- ๐งฉ Skills System: Claude Code-compatible skill loading from
SKILL.mdfiles - ๐ MCP Gateway: Connect to 10,000+ tools via Model Context Protocol servers
- ๐ค A2A Protocol: Agent-to-agent communication via A2A v0.3.0
- ๐ฆ Package Management: npm-like plugin install/enable/disable/search via CLI
- ๐ก๏ธ Error Enhancement: intelligent error classification with automatic fix suggestions
- โ
Task Verification:
task_doneverifies actual file output against expected results
๐ฆ Installation
No Install โ uvx (Recommended)
uvx py-code-agent chat
uvx py-code-agent chat --model gpt-4
uvx py-code-agent run "Hello world"
Note:
uvxrequiresuv. Install via:curl -LsSf https://astral.sh/uv/install.sh | sh
From PyPI
pip install py-code-agent
pip install py-code-agent[all] # all optional dependencies
pip install py-code-agent[dev] # dev dependencies
pip install py-code-agent[gateway] # MCP/A2A gateway support
From Source
git clone https://github.com/your-org/py-code-agent.git
cd py-code-agent
pip install -e .
๐ Quick Start
1. Configure API Key
# OpenAI
export PY_LLM_API_KEY=sk-...
# Anthropic
export PY_LLM_API_KEY=sk-ant-...
# Azure OpenAI
export PY_LLM_API_KEY=...
export PY_LLM_BASE_URL=https://your-resource.openai.azure.com
# Or via .env file (auto-loaded from project root)
echo "PY_LLM_API_KEY=sk-..." > .env
2. Start Interactive Chat
py-code-agent chat --model gpt-4
py-code-agent chat --model claude-3-opus
py-code-agent chat --model ollama/llama2 # local Ollama
3. Run a Single Task
py-code-agent run "Create a Python script that prints the Fibonacci sequence"
4. Start WebSocket Server
py-code-agent channel websocket --port 8080 --no-auth
๐ง Configuration
Config file resolution order (first found wins):
~/.config/py-code-agent/config.yaml./.py-code-agent/config.yaml
llm:
provider: ${PY_LLM_PROVIDER:-openai}
model: ${PY_LLM_MODEL:-gpt-4}
api_key: ${PY_LLM_API_KEY}
base_url: ${PY_LLM_BASE_URL:-http://localhost:8000/v1}
timeout: ${PY_LLM_TIMEOUT:-300}
temperature: ${PY_LLM_TEMPERATURE:-0.7}
max_tokens: ${PY_LLM_MAX_TOKENS:-4000}
tools:
enabled:
- read_file
- write_file
- execute_bash
timeout: ${PY_TOOLS_TIMEOUT:-30}
allow_bash: ${PY_TOOLS_ALLOW_BASH:-true}
allowed_paths:
- ./
blocked_paths:
- ~/.ssh
- ~/.aws
react:
enabled: true
max_turns: 10
plugins:
enabled: []
disabled: []
Config CLI
py-code-agent config get llm.model
py-code-agent config set llm.model gpt-4
py-code-agent config list
py-code-agent config path
py-code-agent config init
py-code-agent config set llm.api_key sk-xxx --global
py-code-agent config set llm.model gpt-4 --local
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ CLI Layer โ
โ chat โ run โ config โ plugin โ channel websocket โ
โโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Core Layer โ
โ Agent (ReAct loop) โ Session โ Events โ PluginManager โ
โโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ
โโโโโโโโโโโโผโโโโโโโโโโโ โโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโ
โ LLM Layer โ โ Plugin System โ
โ LiteLLMProvider โ โ Manager + 5-layer auto-repair โ
โ stream/complete โ โ Built-in + Local + Global + PyPI โ
โโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโ
โ Tools + Channels โ
โ read_file โ write_file โ execute_bash โ task_done โ
โ WebSocket โ CLI โ pluggable transports โ
โ MCP Gateway (10,000+ tools) โ A2A Protocol โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Plugin System
Built-in Plugins
| Plugin Name | Class | Description |
|---|---|---|
file:soul |
SoulPlugin | Agent personality โ loads soul.md |
file:agent_identity |
AgentIdentityPlugin | Agent self-awareness โ loads agent.md |
file:plan |
PlanPlugin | Complex task planning with mandatory rules |
file:skills |
ClaudeSkillsPlugin | Loads Claude Code skills from SKILL.md |
file:context |
ContextPlugin | Context sharing across turns |
file:heartbeat |
HeartbeatPlugin | Real-time agent status monitoring |
file:log |
LogPlugin | Logs tool/agent lifecycle events |
file:edit_file |
EditFilePlugin | File editing operations |
External Plugins
| Plugin | Description |
|---|---|
py-code-agent-git |
Git status and operations |
py-code-agent-search |
Web search via DuckDuckGo |
py-code-agent-mcp-gateway |
MCP server connections (10,000+ tools) |
py-code-agent-a2a-gateway |
Agent-to-agent communication (A2A v0.3.0) |
py-code-agent-omo |
OMO mode: subagent dispatch, intent gate, category routing |
py-code-agent-grep |
Code search engine (text + AST) |
py-code-agent-plan-orchestrator |
Advanced task orchestration |
Plugin Directory Structure
Plugins are loaded from four tiers (first match wins).
| Tier | Directory | Purpose |
|---|---|---|
| Built-in | <repo>/plugins/builtin/ |
Shipped with package |
| Local | ./.py-code-agent/plugins/ |
Project-specific |
| Global | ~/.config/py-code-agent/plugins/ |
User-wide |
| Entry Points | PyPI packages | Community plugins |
Plugin Self-Healing
5 layers of auto-repair.
| Layer | Scenario | Fix |
|---|---|---|
| 1 | Hook method crashes | Wrap with try/except at runtime |
| 2 | Plugin missing hook methods | Inject no-op stubs |
| 3 | Import errors (missing packages) | pip install then retry |
| 4 | Attribute errors | Inject missing attributes |
| 5 | Tool execute() crashes |
AST-patch source file + reload |
CLI Plugin Management
# List all available plugins
py-code-agent plugin available
# Enable / Disable
py-code-agent plugin enable file:soul
py-code-agent plugin disable file:search
# Search & Install
py-code-agent plugin search web-search
py-code-agent plugin install py-code-agent-some-plugin
py-code-agent plugin install git+https://github.com/user/repo.git
# List / Uninstall
py-code-agent plugin list
py-code-agent plugin uninstall py-code-agent-some-plugin
# Scaffold new plugin
py-code-agent plugin init my-awesome-plugin
๐ง ReAct Mode
When react.enabled: true, the agent follows a Thought โ Action โ Observation loop:
- Thought: The LLM reasons about what to do next
- Action: The LLM calls a tool (or provides a final answer)
- Observation: The tool result is fed back as context
- Repeat until
task_doneis called or max turns reached
This enables autonomous coding โ the agent can write files, run tests, fix errors, and iterate until the task is complete.
๐ Channel System
Channels provide pluggable transport for agent communication.
CLI Channel
Interactive terminal via py-code-agent chat.
WebSocket Channel
py-code-agent channel websocket --port 8080 --api-key your-secret-key
Message format:
{ "type": "message", "content": "Hello, agent!" }
Response:
{ "type": "response", "content": "Hello! How can I help?", "status": "done" }
Custom Channels
Implement BaseChannel interface:
get_channel_prompt()โ context injectionget_channel_tools()โ channel-specific toolsreceive()โ async message iteratorsend(response)โ send responses
๐งฉ Skills System
Skills are reusable workflows stored in SKILL.md files, compatible with Claude Code.
Discovery paths (highest priority first):
./.py-code-agent/skills/<name>/SKILL.md~/.config/py-code-agent/skills/<name>/SKILL.md~/.claude/skills/<name>/SKILL.md
# List available skills
> list_skills
# Get skill content
> get_skill(name="frontend-design")
๐ ๏ธ Development
git clone https://github.com/your-org/py-code-agent.git
cd py-code-agent
pip install -e ".[dev,all]"
# Run tests
pytest
# Format code
black src/ tests/
# Lint
ruff check src/ tests/
# Type check
mypy src/
Project Structure
py-code-agent/
โโโ src/py_code_agent/ # Main package
โ โโโ core/ # Agent, Session, Events
โ โโโ cli/ # CLI commands (chat, run, config, plugin)
โ โโโ channels/ # Transport channels (CLI, WebSocket)
โ โโโ llm/ # LiteLLM provider
โ โโโ tools/ # BaseTool + built-in tools
โ โโโ plugins/ # Plugin manager, hooks, auto-repair
โ โโโ mcp/ # MCP client (types, transport)
โ โโโ config/ # Pydantic config models
โ โโโ utils/ # Helpers
โโโ plugins/builtin/ # Built-in plugins
โโโ external-plugins/ # External plugin packages
โโโ tests/ # Test suite
โโโ docs/ # Documentation
๐ค Contributing
We welcome all contributions! See CONTRIBUTING.md.
๐ License
MIT License โ see LICENSE.
๐ Acknowledgements
- LiteLLM โ unified LLM API
- Rich โ terminal output
- Textual โ TUI framework
- Pydantic โ data validation
- pluggy โ plugin hooks
Made with โค๏ธ by the Py Code Agent Team
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_code_agent-0.1.0.tar.gz.
File metadata
- Download URL: py_code_agent-0.1.0.tar.gz
- Upload date:
- Size: 11.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0419ea29d5cdfa543ec637b691b3e6a92ec2cfa50a3022e5c173ee1294bfbb62
|
|
| MD5 |
eeafc954a046ab0a814487ebee7c8cf5
|
|
| BLAKE2b-256 |
019446d780b0f876ec2ea9e2fd3ac3914e79540608e946b1d5ccf02a96638353
|
File details
Details for the file py_code_agent-0.1.0-py3-none-any.whl.
File metadata
- Download URL: py_code_agent-0.1.0-py3-none-any.whl
- Upload date:
- Size: 78.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2121b03763c088764090255b9bc6da097f8e2438ec3b36a2fecb46ee96fdfe7
|
|
| MD5 |
6d54c716f6c0bb350a1d578e684ada7c
|
|
| BLAKE2b-256 |
8f814bbeca69a8fa2ae1645920e24139d599204a338b6466dc2001cd35b1efbe
|