Skip to main content

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)

Testing

You can test the compliance of your agent using the following script:

URL=http://127.0.0.1:8000 bash -c "$(curl -fsSL https://agentprotocol.ai/test.sh)"

What this does is run a series of GET and POST requests against your agent to verify that it's compliant with the Agent Protocol.

Docs

You can find more info and examples in the docs.

Development

If you want to use the agent_protocol package from the cloned repository, you should be able to use poetry to set it up, like below.

git clone git@github.com:AI-Engineers-Foundation/agent-protocol.git
cd agent-protocol/sdk/python
poetry install
poetry run python examples/minimal.py

Feel free to open an issue if you run into any problems!

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

agent_protocol-1.0.2.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

agent_protocol-1.0.2-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file agent_protocol-1.0.2.tar.gz.

File metadata

  • Download URL: agent_protocol-1.0.2.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.13 Linux/5.15.0-1051-azure

File hashes

Hashes for agent_protocol-1.0.2.tar.gz
Algorithm Hash digest
SHA256 cc767ac6534fd73699d81b9f2101a57a03d9b2e65c9cf17c0cff36b958237691
MD5 dd548220a21ccf8cb8bb817a3c589837
BLAKE2b-256 ab77c8a414bc3d2e989b2af7bf288465a31b37b79e1bd7ade252a4a468bb1547

See more details on using hashes here.

File details

Details for the file agent_protocol-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: agent_protocol-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.13 Linux/5.15.0-1051-azure

File hashes

Hashes for agent_protocol-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 883914cd4dbcd2641d2634d13b5bd6049a18d26c7c528b4d7809e529f4de464e
MD5 fab7fa4388c9bfd80881627cc1f8b6ff
BLAKE2b-256 2263ee6284b2389d480a6065b3867ea053e302cce9c13f37ad4ee5c6b8075296

See more details on using hashes here.

Supported by

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