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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_code_agent-0.1.0.tar.gz (11.8 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_code_agent-0.1.0-py3-none-any.whl (78.3 kB view details)

Uploaded Python 3

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

Hashes for py_code_agent-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0419ea29d5cdfa543ec637b691b3e6a92ec2cfa50a3022e5c173ee1294bfbb62
MD5 eeafc954a046ab0a814487ebee7c8cf5
BLAKE2b-256 019446d780b0f876ec2ea9e2fd3ac3914e79540608e946b1d5ccf02a96638353

See more details on using hashes here.

File details

Details for the file py_code_agent-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for py_code_agent-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c2121b03763c088764090255b9bc6da097f8e2438ec3b36a2fecb46ee96fdfe7
MD5 6d54c716f6c0bb350a1d578e684ada7c
BLAKE2b-256 8f814bbeca69a8fa2ae1645920e24139d599204a338b6466dc2001cd35b1efbe

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page