Skip to content

kangkona/pig-mono

Repository files navigation

pig-mono

Python Monorepo for AI Agents - A comprehensive toolkit inspired by pi-mono

Named "pig-mono" (🐷) - 虾仁猪心 (a Chinese pun meaning "utterly devastating"), our tribute to pi-mono while bringing these excellent ideas to the Python ecosystem

Python Version License: MIT Code style: ruff Test Coverage PyPI

Build AI agents and LLM applications with a powerful, modular Python toolkit. pig-mono provides everything you need: unified LLM APIs, agent runtime, session management, extensions, skills, and multi-platform messaging bots.

🌟 Unique Features:

  • Multi-Platform Bots: Support for Slack, Discord, Telegram, WhatsApp, and Feishu (vs pi-mono's Slack-only)
  • 14 LLM Providers: OpenAI, Anthropic, Google, Azure, Groq, Mistral, and more
  • Complete Agent System: Sessions, extensions, skills, prompts, and context management
  • Production Ready: 99.5%+ feature parity with pi-mono, 84% test coverage

📦 Packages

Package Version Description Status
pig-llm v0.1.1 Unified LLM API for 14 providers ✅ Ready
pig-agent-core v0.1.1 Agent runtime with tools, resilience, observability ✅ Ready
pig-tui v0.1.1 Terminal UI with rich formatting ✅ Ready
pig-web-ui v0.0.1 Web chat interface with FastAPI ✅ Ready
pig-coding-agent v0.1.1 Interactive coding assistant with resilience & cost tracking ✅ Ready
pig-messenger v0.0.3 Multi-platform bot framework ✅ Ready

🚀 Quick Start

Installation

Install individual packages from PyPI:

# Using uv (recommended)
uv pip install pig-llm pig-agent-core pig-coding-agent

# Using pipx (for CLI tools)
pipx install pig-coding-agent

# Using pip
pip install pig-llm pig-agent-core

For development from source:

git clone https://github.com/kangkona/pig-mono.git
cd pig-mono
uv pip install -e ".[dev]"
./scripts/install-dev.sh

Try it Out

Web UI (easiest):

# Install
uv pip install pig-web-ui
# or: pipx install pig-web-ui

export OPENROUTER_API_KEY=your-key
pig-webui --provider openrouter --model moonshotai/kimi-k2.5
# Open http://localhost:8000

Coding Agent (powerful):

# Install
uv pip install pig-coding-agent
# or: pipx install pig-coding-agent

# Interactive startup — prompts for provider and model if omitted
pig

# Or specify directly
pig --provider openrouter --model moonshotai/kimi-k2.5

# Try these features:
> Review @src/main.py for bugs          # @file references
> /tree                                   # View session tree
> /fork alternative-approach              # Branch conversation
> /skill:code-review                      # Invoke skill
> /resilience                             # Check API key status
> /cost                                   # View usage & costs
!Stop and explain what you're doing      # Interrupt with steering

Production Resilience:

# Set multiple API keys for automatic rotation
export OPENAI_API_KEY=sk-...
export OPENAI_API_KEY_2=sk-...
export ANTHROPIC_API_KEY=sk-ant-...

pig
# ✓ Resilience enabled: 3 API keys available
# ✓ Cost tracking enabled

# Agent automatically:
# - Rotates keys on rate limits
# - Falls back to alternative models
# - Tracks costs in real-time

Multi-Platform Bot (setup guide):

import os
from pig_messenger import MessengerBot
from pig_messenger.adapters import SlackAdapter
from pig_agent_core import Agent
from pig_llm import LLM

agent = Agent(llm=LLM(provider="openrouter", model="moonshotai/kimi-k2.5",
                       api_key=os.environ["OPENROUTER_API_KEY"]))
bot = MessengerBot(agent)
bot.add_platform(SlackAdapter(
    app_token=os.environ["SLACK_APP_TOKEN"],
    bot_token=os.environ["SLACK_BOT_TOKEN"],
))
bot.start()

✨ Key Features

14 LLM Providers

  • Major: OpenAI, Anthropic (Claude), Google (Gemini), Azure
  • Fast: Groq, Cerebras, Together AI
  • Specialized: Mistral, Cohere, DeepSeek, Perplexity
  • Aggregators: OpenRouter, Amazon Bedrock, xAI

Complete Agent System

  • Sessions: Tree-based conversation management with branching and forking
  • Extensions: Plugin system for custom tools, commands, and events
  • Skills: Reusable agent capabilities (Agent Skills standard)
  • Prompts: Template system with variable substitution
  • Context: Project-aware via AGENTS.md and SYSTEM.md
  • Resilience: Automatic API key rotation, failure recovery, model fallback
  • Observability: Event emission, billing tracking, metrics collection
  • Streaming: Live tool call output with onUpdate callbacks and any-tool termination

Production-Ready Infrastructure

  • Unified Tool Registry: Single ToolRegistry across all tools; web tools (search, read) built into pig-agent-core
  • Operations Abstraction: FileOperations/ShellOperations protocols for testable, swappable backends
  • API Key Rotation: Automatic failover on rate limits with per-failure-type cooldowns
  • Cost Tracking: Real-time LLM and tool usage monitoring with pricing data
  • Context Management: 3-level compression (truncate → summarize → LLM-compress)
  • Tool System: Fallback mapping, confirmation gates, parallel/sequential execution
  • Memory Protocols: Pluggable memory providers for custom storage backends

Multi-Platform Messaging

  • 5 Platforms: Slack, Discord, Telegram, WhatsApp, Feishu
  • Unified API: Same agent code works everywhere
  • Per-Channel Sessions: Each conversation maintains its own context

Developer Experience

  • 30+ Commands: Comprehensive CLI control
  • Message Queue: Queue messages while agent works (!steering, >>followup)
  • File References: Auto-include files with @filename syntax
  • Export/Share: Export sessions to HTML or GitHub Gist
  • JSON/RPC Modes: Programmatic integration

📖 Documentation


🎯 Use Cases

Code Development

pig --session my-project

> Create a FastAPI web server with authentication
> @src/main.py - Review this code
> /fork add-tests
> Commit changes with message "Add auth"

Team Collaboration

# Same bot across Slack, Discord, Telegram, WhatsApp, Feishu
bot = MessengerBot(agent)
bot.add_platform(SlackAdapter(...))
bot.add_platform(DiscordAdapter(...))
bot.add_platform(TelegramAdapter(...))
bot.add_platform(WhatsAppAdapter(...))
bot.add_platform(FeishuAdapter(...))
bot.start()

Automation

# Use OpenRouter for cost-effective automation
export OPENROUTER_API_KEY=your-key

# JSON mode for CI/CD
echo '{"message": "Review this code"}' | pig --provider openrouter --mode json

# RPC mode for integration
pig --provider openrouter --mode rpc < requests.jsonl > responses.jsonl

📊 Project Stats

  • Code: 14,000+ lines
  • Tests: 330+ tests with 84% coverage
  • Documentation: 55,000+ words
  • Packages: 6 production-ready packages on PyPI
  • CI/CD: Automated PyPI publishing via Trusted Publishing on tag releases

🆚 vs pi-mono

Feature pi-mono pig-mono
Core Development ✅ 99.5%+
LLM Providers 17 14 (all major ones)
Messaging Platforms 1 (Slack) 5 (Slack, Discord, Telegram, WhatsApp, Feishu) 🌟
Test Coverage ~80% 84%
Documentation Excellent More comprehensive
Language TypeScript Python

pig-mono achieves 99.5%+ feature parity with pi-mono and exceeds it in multi-platform support!


🏗️ Architecture

Infrastructure Layer
├── pig-llm (LLM abstraction)
├── pig-agent-core (Agent runtime)
├── pig-tui (Terminal UI)
└── pig-web-ui (Web UI)

Application Layer
├── pig-coding-agent (CLI assistant)
└── pig-messenger (Multi-platform bots)

🛠️ Development

# Install dependencies
uv pip install -e ".[dev]"
./scripts/install-dev.sh

# Run tests
./scripts/test.sh

# Lint code
./scripts/lint.sh

# Run coding agent from source
cd packages/pig-coding-agent
python -m pig_coding_agent.cli

🤝 Contributing

We welcome contributions! See CONTRIBUTING.md for:

  • Development setup
  • Code style guidelines
  • Testing requirements
  • Pull request process

📝 License

MIT License - see LICENSE for details


🙏 Acknowledgments

Inspired by badlogic/pi-mono - an excellent TypeScript AI agent toolkit.

pig-mono (affectionately called "pig-mono" 🐷 by the community) brings these concepts to the Python ecosystem with additional innovations like multi-platform messaging support.

Why "pig-mono"?

The name comes from a playful Chinese pun: "虾仁猪心" (xiā rén zhū xīn), which sounds like "杀人诛心" (shā rén zhū xīn) - meaning to utterly defeat someone not just physically but mentally.

Our tribute to pi-mono: We aim to match it feature-for-feature while adding unique Python-ecosystem value! 🐷💪


⭐ Star History

If you find pig-mono useful, please star the repository!

Star History Chart


Built with ❤️ for the Python AI community

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages