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
claudeonce to set up) - Or set
ANTHROPIC_API_KEYenvironment 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
[distutils]
index-servers =
pypi
testpypi
[pypi]
username = __token__
password = pypi-YOUR_PYPI_TOKEN
[testpypi]
username = __token__
password = pypi-YOUR_TESTPYPI_TOKEN
Release Process
-
Update version in both files:
pyproject.toml→version = "X.Y.Z"src/acp_factory/__init__.py→__version__ = "X.Y.Z"
-
Update CHANGELOG.md with release notes
-
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
-
Publish to PyPI:
make publish -
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
Metadata
Release files for acp-factory 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| acp_factory-0.1.1.tar.gz | 22.4 kB | Without provenance | Details for acp_factory-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| acp_factory-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for acp_factory-0.1.1-py3-none-any.whl |
Total release size: 41.1 kB
Release files / acp_factory-0.1.1.tar.gz
| Download URL | acp_factory-0.1.1.tar.gz |
|---|---|
| Size | 22.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
09863b34858ee32e93160c763864b96248d0af3edf35249716f39a907f2cb9b3
|
|
BLAKE2b-256 checksum How to use checksums |
d5314d810f5cf645c0af4acbdb1d939e3e6711418ee2fc4aa4f356c25fbf2d63
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.6
|
Release files / acp_factory-0.1.1-py3-none-any.whl
| Download URL | acp_factory-0.1.1-py3-none-any.whl |
|---|---|
| Size | 18.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5536fcaecae8679e820b3f04b43168d7ebe91439ff1c17009260b75c2863c2ad
|
|
BLAKE2b-256 checksum How to use checksums |
e43677ed86e31e014e85b1ae3d3f17dcd686f8c6f20b9db4b8e6b3fd53c541ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.6
|
Security for acp-factory 0.1.1
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.