Skip to main content

Minimal Python CLI agent with native tools for shell execution and file operations

Project description

BitterAgent - Minimal Python CLI Agent

A ultra-minimal, extensible Python CLI agent with native tools for shell execution and file operations.

Core Components

1. Tool System

  • Base Tool Class: Abstract class defining tool interface
    • name: Tool identifier
    • description: Human-readable description
    • parameters: JSON Schema for tool parameters
    • execute(): Method to run the tool
  • ToolRegistry: Manages tool registration and discovery
    • Register built-in tools on startup
    • Lookup tools by name
    • List available tools
  • ToolResult: Structured response from tool execution
    • success: Boolean status
    • output: Tool output/result
    • error: Error message if failed

2. Provider Interface

  • Provider ABC: Abstract base for LLM providers in providers/base.py
    • complete(messages, tools): Generate completion with tool support
    • get_tools_schema(registry): Convert tools to provider-specific format
    • Provider-specific configuration
    • Built-in retry logic with exponential backoff
    • Error handling for rate limits, timeouts, API errors
  • AnthropicProvider: Implementation using Anthropic SDK in providers/anthropic.py
    • Handle streaming responses
    • Process tool use blocks
    • Return structured responses
    • Auto-retry on 429/500/502/503 errors
    • Configurable max retries and timeout
  • Extensible: Easy to add OpenAI, Ollama, or other providers

3. Agent Core

  • Conversation Management
    • Maintain message history
    • Handle user input
    • Process model responses
    • System prompt loading from system.md file
  • Tool Execution Loop
    • Parse tool calls from model
    • Parallel execution for multiple tool calls
    • Execute tools with parameters
    • Return results to model in order

4. Native Tools

  • ShellTool
  • ReadFileTool
  • WriteFileTool
  • EditFileTool

5. CLI Interface

  • Commands
    • chat: Interactive conversation mode
    • run: Execute single command
    • tools: List available tools
  • Options
    • --api-key: Model API key
    • --model: Model selection
    • --system-prompt: Path to system.md file (default: ./system.md if exists)
    • --verbose: Debug logging

Installation

# Install uv if not already installed
curl -LsSf https://astral.sh/uv/install.sh | sh

# Clone the repository
git clone https://github.com/yourusername/bitteragent.git
cd bitteragent

# Install dependencies with uv
uv sync

# Set up environment variables
cp .env.example .env
# Edit .env with your API key

Usage Examples

# Interactive chat
uv run python -m bitteragent chat

# Run single command
uv run python -m bitteragent run "Create a Python hello world script"

# List available tools
uv run python -m bitteragent tools

# With specific model
uv run python -m bitteragent chat --model claude-sonnet-4-20250514

# With custom system prompt
uv run python -m bitteragent chat --system-prompt ./custom-prompt.md

Configuration

# .env file
ANTHROPIC_API_KEY=your-api-key-here

Running Tests

# Install test dependencies
pip install pytest

# Run all tests
pytest tests/

# Run with verbose output
pytest tests/ -v

# Run a specific test file
pytest tests/test_agent.py

# Run with coverage (requires pytest-cov)
pip install pytest-cov
pytest tests/ --cov=bitteragent --cov-report=term-missing

License

MIT

Contributing

This is a minimal reference implementation. Feel free to fork and extend!

Project details


Download files

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

Source Distribution

bitteragent-0.1.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

bitteragent-0.1.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file bitteragent-0.1.0.tar.gz.

File metadata

  • Download URL: bitteragent-0.1.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for bitteragent-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d03ec76fd7030af32bfc47555f6ef894bdef2bfadc44ee1d74606ea19c93584e
MD5 eaaf5a4732fb67f9fab30dd644706073
BLAKE2b-256 e3a5b42d1478e310558935b2719b564dd3e2112349821c2c189c38cf0b8e893e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bitteragent-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for bitteragent-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb02f98eb54a59f3a465bb93234852f319c9dbbae55a5ff55e43cab17bbce2ce
MD5 26e2cadb9ebf97ba1593e1d5693ae535
BLAKE2b-256 c51f94ff2e396bd92d2d9c30941a766b395432a7c3c6c8f988779a3284a7d7b9

See more details on using hashes here.

Supported by

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