Metadata-Version: 2.1
Name: agent-protocol
Version: 1.0.0
Summary: API for interacting with Agents that use the Agent Protocol
Home-page: https://agentprotocol.ai/
License: MIT
Author: AI Engineers Foundation
Author-email: aiengineersfoundation@gmail.com
Requires-Python: >=3.7,<4.0.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Requires-Dist: aiofiles (>=23.1.0,<24.0.0)
Requires-Dist: click (>=8.1.6,<9.0.0)
Requires-Dist: fastapi (>=0.100.0,<0.101.0)
Requires-Dist: hypercorn (>=0.14.4,<0.15.0)
Requires-Dist: pydantic (>=1.10.5,<2.0.0)
Requires-Dist: pytest (>=7.0.0,<8.0.0)
Requires-Dist: python-multipart (>=0.0.6,<0.0.7)
Requires-Dist: requests (>=2.31.0,<3.0.0)
Project-URL: Bug Tracker, https://github.com/AI-Engineers-Foundation/agent-protocol-sdk-python/issues
Project-URL: Repository, https://github.com/AI-Engineers-Foundation/agent-protocol-sdk-python/tree/main/
Description-Content-Type: text/markdown

# Agent Protocol - Python SDK

Reference implementation of the Agent Protocol in Python by the AI Engineers Foundation (AIEF). This SDK allows you to easily wrap your agent in a webserver compatible with the protocol - you only need to define the task and step handlers for your agent.

## Installation

```sh
pip install agent-protocol
```

Then add the following code to your agent:

```python
from agent_protocol import Agent, Step, Task


async def task_handler(task: Task) -> None:
    # TODO: Create initial step(s) for the task
    await Agent.db.create_step(task.task_id, ...)


async def step_handler(step: Step) -> Step:
    # TODO: handle next step
    if step.name == "print":
        print(step.input)
        step.is_last = True

    step.output = "Output from the agent"
    return step


if __name__ == "__main__":
    # Add the task handler and start the server
    Agent.setup_agent(task_handler, step_handler).start()
```

## Customization

### Database

By default, the SDK stores data in memory. You can customize the database by setting db to your own database object.

```python
Agent.db = your_database
```

The database object must implement the methods from [db.py](./agent_protocol/db.py).

### Routes

You can also add your own routes to the server. For example:

```python
from agent_protocol import Agent, router
from fastapi import APIRouter

my_router = APIRouter()


@my_router.get("/hello")
async def hello():
    return {"hello": "world"}

my_router.include_router(router)

task_handler = ...
step_handler = ...
Agent.setup_agent(task_handler, step_handler).start(router=my_router)
```

## Docs

You can find more info and examples in the [docs](https://agentprotocol.ai/sdks/python).

