API for interacting with Agents that use the Agent Protocol
Project description
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
pip install agent-protocol
Then add the following code to your agent:
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.
Agent.db = your_database
The database object must implement the methods from db.py.
Routes
You can also add your own routes to the server. For example:
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for agent_protocol-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 339b393127f79f7e224eb63b629407b10da2d4a512358da98d27f0f8e736f2a9 |
|
MD5 | 7080245a76119774cb4f9111c6a01850 |
|
BLAKE2b-256 | ebec66166c57fc6d4d03372789b34b7a60cbc04e4552a2ad15830ace5d661434 |