Skip to main content

Async Simple Agent Protocol - A streamlined protocol for agent-to-agent communication

Project description

ASAP: Async Simple Agent Protocol

A streamlined, scalable, asynchronous protocol for agent-to-agent communication and task coordination.

Why ASAP?

Building multi-agent systems today suffers from three core technical challenges:

  1. $N^2$ Connection Complexity: Most protocols assume static point-to-point HTTP connections that don't scale.
  2. State Drift: Lack of native persistence makes it impossible to reliably resume long-running agentic workflows.
  3. Fragmentation: No unified way to handle task delegation, artifact exchange, and tool execution (MCP) in a single envelope.

ASAP provides a production-ready communication layer that simplifies these complexities. It introduces a standardized, stateful orchestration framework that ensures your agents can coordinate reliably across distributed environments.

Key Features

  • Stateful Orchestration: Native task state machine with built-in snapshotting for durable, resumable agent workflows.
  • Schema-First Design: Strict Pydantic v2 models providing automatic JSON Schema generation for guaranteed cross-agent interoperability.
  • High-Performance Core: Built on Python 3.13+, leveraging uvloop (C) and pydantic-core (Rust) for ultra-low latency validation and I/O.
  • Observable Chains: First-class support for trace_id and correlation_id to debug complex multi-agent delegation.
  • MCP Integration: Uses the Model Context Protocol (MCP) as a tool-execution substrate, wrapped in a high-level coordination envelope.
  • Async-Native: Engineered from the ground up for high-concurrency environments using asyncio and httpx. Supports both sync and async handlers with automatic event loop management.

💡 Performance Note: Pure Python codebase leveraging Rust-accelerated dependencies (pydantic-core, orjson, python-ulid) for native-level performance without build complexity.

Installation

We recommend using uv for dependency management:

uv add asap-protocol

Or with pip:

pip install asap-protocol

For reproducible environments, prefer uv when possible.

Quick Start

1. Create an Agent (Server)

from asap.models.entities import Capability, Endpoint, Manifest, Skill
from asap.transport.handlers import HandlerRegistry, create_echo_handler
from asap.transport.server import create_app

manifest = Manifest(
    id="urn:asap:agent:echo-agent",
    name="Echo Agent",
    version="0.1.0",
    description="Echoes task input as output",
    capabilities=Capability(
        asap_version="0.1",
        skills=[Skill(id="echo", description="Echo back the input")],
        state_persistence=False,
    ),
    endpoints=Endpoint(asap="http://127.0.0.1:8001/asap"),
)

registry = HandlerRegistry()
registry.register("task.request", create_echo_handler())

app = create_app(manifest, registry)

2. Send a Task (Client)

import asyncio
from asap.models.envelope import Envelope
from asap.models.payloads import TaskRequest
from asap.transport.client import ASAPClient

async def main():
    request = TaskRequest(
        conversation_id="conv_01HX5K3MQVN8",
        skill_id="echo",
        input={"message": "hello from client"},
    )
    envelope = Envelope(
        asap_version="0.1",
        sender="urn:asap:agent:client",
        recipient="urn:asap:agent:echo-agent",
        payload_type="task.request",
        payload=request.model_dump(),
    )
    async with ASAPClient("http://127.0.0.1:8001") as client:
        response = await client.send(envelope)
        print(response.payload)

if __name__ == "__main__":
    asyncio.run(main())

API Overview

Core models:

  • Envelope: protocol wrapper with routing and tracing metadata
  • TaskRequest, TaskResponse, TaskUpdate, TaskCancel: task lifecycle payloads
  • MessageSend, ArtifactNotify: messaging and artifacts
  • StateQuery, StateRestore: snapshot state operations
  • McpToolCall, McpToolResult, McpResourceFetch, McpResourceData: MCP integration

Transport:

  • create_app: FastAPI application factory
  • HandlerRegistry: payload dispatch registry (supports both sync and async handlers)
  • ASAPClient: async HTTP client with automatic retry for server errors (5xx)

Documentation

Advanced Examples

State Snapshots

from datetime import datetime, timezone
from asap.models.entities import StateSnapshot
from asap.state import InMemorySnapshotStore

store = InMemorySnapshotStore()
snapshot = StateSnapshot(
    id="snap_01HX5K7R...",
    task_id="task_01HX5K4N...",
    version=1,
    data={"status": "submitted", "progress": 0},
    created_at=datetime.now(timezone.utc),
)
store.save(snapshot)
latest = store.get("task_01HX5K4N...")

Error Recovery

from asap.errors import InvalidTransitionError

try:
    raise InvalidTransitionError(from_state="submitted", to_state="completed")
except InvalidTransitionError as exc:
    payload = exc.to_dict()
    print(payload["code"])

Async Handlers

Handlers can be either synchronous or asynchronous:

# Sync handler
def my_sync_handler(envelope: Envelope, manifest: Manifest) -> Envelope:
    # Process synchronously
    return response_envelope

# Async handler
async def my_async_handler(envelope: Envelope, manifest: Manifest) -> Envelope:
    # Process asynchronously (e.g., database calls, API requests)
    result = await some_async_operation()
    return response_envelope

registry.register("task.request", my_async_handler)  # Works with both!

Multi-Agent Flow

Run the built-in demo to see two agents exchanging messages:

uv run python -m asap.examples.run_demo

CLI Tools

The ASAP CLI provides utilities for schema management:

# Export all JSON schemas
asap export-schemas --output-dir ./schemas

# List available schemas
asap list-schemas

# Show a specific schema
asap show-schema envelope

# Validate JSON against a schema
asap validate-schema message.json --schema-type envelope

# Verbose output
asap export-schemas --verbose

Contributing

We love contributions! Whether it's fixing a bug, improving documentation, or proposing a new feature, your help is welcome.

Check out our Contributing Guidelines to get started. It's easier than you think! 🚀

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

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

asap_protocol-0.1.0.tar.gz (272.7 kB view details)

Uploaded Source

Built Distribution

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

asap_protocol-0.1.0-py3-none-any.whl (65.7 kB view details)

Uploaded Python 3

File details

Details for the file asap_protocol-0.1.0.tar.gz.

File metadata

  • Download URL: asap_protocol-0.1.0.tar.gz
  • Upload date:
  • Size: 272.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for asap_protocol-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d4a869262d325b4f1b03038ae4eeedba59412ea83a352e1dc17cdc3cf80d04b9
MD5 90b5a03d271c2772b39b2221a52514d1
BLAKE2b-256 a78674d97b00d07b39900a66914fd9f6bea336022184cd31e54178776e405fb3

See more details on using hashes here.

Provenance

The following attestation bundles were made for asap_protocol-0.1.0.tar.gz:

Publisher: release.yml on adriannoes/asap-protocol

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file asap_protocol-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: asap_protocol-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 65.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for asap_protocol-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 063a8a4ea79a85a66cf9646dcad46a102db31256eda7e44357f569987cb60c99
MD5 56c8dd4bf66b7676bdd1be04992d132b
BLAKE2b-256 d006d6197e9e7f9f48d6ea250c8c354d24328010088b5bc2749791b33b90c73d

See more details on using hashes here.

Provenance

The following attestation bundles were made for asap_protocol-0.1.0-py3-none-any.whl:

Publisher: release.yml on adriannoes/asap-protocol

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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