Skip to main content

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.md files
  • 🔗 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_done verifies 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: uvx requires uv. 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):

  1. ~/.config/py-code-agent/config.yaml
  2. ./.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:

  1. Thought: The LLM reasons about what to do next
  2. Action: The LLM calls a tool (or provides a final answer)
  3. Observation: The tool result is fed back as context
  4. Repeat until task_done is 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 injection
  • get_channel_tools() — channel-specific tools
  • receive() — async message iterator
  • send(response) — send responses

🧩 Skills System

Skills are reusable workflows stored in SKILL.md files, compatible with Claude Code.

Discovery paths (highest priority first):

  1. ./.py-code-agent/skills/<name>/SKILL.md
  2. ~/.config/py-code-agent/skills/<name>/SKILL.md
  3. ~/.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


Made with ❤️ by the Py Code Agent Team

Metadata

Release files for py-code-agent 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-code-agent 0.1.0
File Size Uploaded Provenance
py_code_agent-0.1.0.tar.gz 11.8 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for py-code-agent 0.1.0
File Interpreter ABI Platform
py_code_agent-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.9 MB

Release files / py_code_agent-0.1.0.tar.gz

Download URL py_code_agent-0.1.0.tar.gz
Size 11.8 MB
Tags Source
SHA-256 checksum
How to use checksums
0419ea29d5cdfa543ec637b691b3e6a92ec2cfa50a3022e5c173ee1294bfbb62
BLAKE2b-256 checksum
How to use checksums
019446d780b0f876ec2ea9e2fd3ac3914e79540608e946b1d5ccf02a96638353
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.5

Release files / py_code_agent-0.1.0-py3-none-any.whl

Download URL py_code_agent-0.1.0-py3-none-any.whl
Size 78.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c2121b03763c088764090255b9bc6da097f8e2438ec3b36a2fecb46ee96fdfe7
BLAKE2b-256 checksum
How to use checksums
8f814bbeca69a8fa2ae1645920e24139d599204a338b6466dc2001cd35b1efbe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.6.5

Security for py-code-agent 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page