Skip to main content

A library for spawning and managing agents through the Agent Client Protocol (ACP)

Project description

acp-factory

A Python library for spawning and managing AI agents through the Agent Client Protocol (ACP).

Installation

pip install acp-factory

Prerequisites

  • Python 3.10+
  • Claude Code installed and authenticated (run claude once to set up)
  • Or set ANTHROPIC_API_KEY environment variable

Quick Start

import asyncio
from acp_factory import AgentFactory

async def main():
    # Spawn a Claude Code agent
    agent = await AgentFactory.spawn("claude-code", {
        "permission_mode": "auto-approve",
    })

    # Create a session
    session = await agent.create_session(".")

    # Send a prompt and stream responses
    async for update in session.prompt("What files are in this directory?"):
        if update.get("session_update") == "agent_message_chunk":
            content = update.get("content", {})
            if content.get("type") == "text":
                print(content.get("text", ""), end="")

    # Clean up
    await agent.close()

asyncio.run(main())

API Reference

AgentFactory

Static class for managing agent types and spawning agents.

# List available agents
AgentFactory.list_agents()  # ["claude-code", "codex", "gemini", "opencode"]

# Register a custom agent
AgentFactory.register("my-agent", AgentConfig(
    command="my-agent",
    args=["--acp"],
    env={"MY_VAR": "value"},
))

# Spawn an agent
agent = await AgentFactory.spawn("claude-code", options)

AgentHandle

Represents a running agent process.

# Agent capabilities
agent.capabilities  # {"loadSession": True, ...}

# Create a new session
session = await agent.create_session("/path/to/cwd", SessionOptions(
    mode="code",
    mcp_servers=[],
))

# Load an existing session
session = await agent.load_session(session_id, "/path/to/cwd")

# Close the agent
await agent.close()

# Check if running
agent.is_running()  # True/False

Session

High-level interface for interacting with an agent session.

# Session properties
session.id       # Session ID
session.modes    # Available modes ["code", "ask", ...]
session.models   # Available models ["claude-sonnet-4-...", ...]

# Send a prompt (returns async iterator)
async for update in session.prompt("Hello!"):
    # Handle updates
    pass

# Cancel the current prompt
await session.cancel()

# Set the session mode
await session.set_mode("ask")

# Interrupt and redirect with new context
async for update in session.interrupt_with("Focus on tests only"):
    # Handle updates from new prompt
    pass

Permission Modes

Control how permission requests are handled:

from acp_factory import SpawnOptions

# Auto-approve all requests (default)
await AgentFactory.spawn("claude-code", SpawnOptions(
    permission_mode="auto-approve",
))

# Auto-deny all requests
await AgentFactory.spawn("claude-code", SpawnOptions(
    permission_mode="auto-deny",
))

# Use a callback handler
async def handle_permission(request):
    return {"outcome": {"outcome": "selected", "option_id": "allow"}}

await AgentFactory.spawn("claude-code", SpawnOptions(
    permission_mode="callback",
    on_permission_request=handle_permission,
))

# Interactive mode - permissions emitted as session updates
await AgentFactory.spawn("claude-code", SpawnOptions(
    permission_mode="interactive",
))

Development

Setup

# Clone the repository
git clone https://github.com/sudocode-ai/acp-factory.git
cd acp-factory/python

# Install with dev dependencies
make dev
# or
pip install -e ".[dev]"

Commands

# Run tests
make test

# Run linter
make lint

# Format code
make format

# Type check
make typecheck

# Clean build artifacts
make clean

Publishing to PyPI

Prerequisites

  1. Create accounts on PyPI and TestPyPI
  2. Create API tokens for both
  3. Configure ~/.pypirc:
[distutils]
index-servers =
    pypi
    testpypi

[pypi]
username = __token__
password = pypi-YOUR_PYPI_TOKEN

[testpypi]
username = __token__
password = pypi-YOUR_TESTPYPI_TOKEN

Release Process

  1. Update version in both files:

    • pyproject.tomlversion = "X.Y.Z"
    • src/acp_factory/__init__.py__version__ = "X.Y.Z"
  2. Update CHANGELOG.md with release notes

  3. Test on TestPyPI first:

    make publish-test
    
    # Test installation from TestPyPI
    pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ acp-factory
    
  4. Publish to PyPI:

    make publish
    
  5. Create git tag:

    git tag v0.0.1
    git push --tags
    

Manual Publishing

If you prefer not to use Make:

# Install build tools
pip install build twine

# Build package
python -m build

# Upload to TestPyPI
python -m twine upload --repository testpypi dist/*

# Upload to PyPI
python -m twine upload dist/*

License

MIT

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

acp_factory-0.0.1.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

acp_factory-0.0.1-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file acp_factory-0.0.1.tar.gz.

File metadata

  • Download URL: acp_factory-0.0.1.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for acp_factory-0.0.1.tar.gz
Algorithm Hash digest
SHA256 7312e111b01b06c4f52141714ca3ede87512f800a81c88bcdf2aca25d628764e
MD5 cf9b5547ff30de233df81400af5d3b12
BLAKE2b-256 a5658e742a0947af7e1ba99918a9a9c7db609b00bc1291526ba104ec1b752919

See more details on using hashes here.

File details

Details for the file acp_factory-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: acp_factory-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for acp_factory-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 feafdd06ed71d7833309774019988be670f7b432eb384b23a398d0b9ad037e8e
MD5 fc50cc8108efb729656f97f7d028da59
BLAKE2b-256 175bd3bdb8f807991a6769a921087d950f69fcd61586dbd71afa751f8333581f

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