Skip to main content

Pattern Agentic Messaging

An async SLIM wrapper with a FastAPI-like interface

Installation

pip install pattern_agentic_messaging

Server

Route messages to decorated handlers based on a discriminator field:

from pattern_agentic_messaging import PASlimApp, PASlimConfig
from .models import QuestionRequest, StatusRequest, AnswerResponse

config = PASlimConfig(
    local_name="org/ns/server",
    endpoint="https://slim.example.com",
    auth_secret="shared-secret-at-least-32-bytes!",
    message_discriminator="type",
)

app = PASlimApp(config)

@app.on_session_connect
async def on_connect(session):
    session.context["agent"] = await create_agent(...)

@app.on_message
async def handle_prompt(session, msg: QuestionRequest):
    agent = session.context["agent"]
    response = await agent.ask(msg.question)
    await session.send(AnswerResponse(answer=response))

@app.on_message
async def handle_status(session, msg: StatusRequest):
    await session.send({"type": "status", "value": "ready"})

@app.on_message
async def handle_other(session, msg):
    await session.send({"error": f"Unknown message type: {msg}"})

app.run()

Discriminator models are Pydantic models with a Literal field matching the discriminator:

from pydantic import BaseModel
from typing import Literal

class QuestionRequest(BaseModel):
    type: Literal["question"] = "question"
    prompt: str

class AnswerResponse(BaseModel):
    type: Literal["answer"] = "answer"
    answer: str

Authentication

Fluent configuration for three auth modes:

from pattern_agentic_messaging import PASlimConfig

# No auth (for local dev / data planes configured with auth: none)
config = PASlimConfig(local_name="org/ns/app", endpoint="...").with_no_auth()

# Shared secret
config = PASlimConfig(local_name="org/ns/app", endpoint="...").with_shared_secret("my-secret-key-at-least-32-bytes!")

# JWT with JWKS verification
config = PASlimConfig(
    local_name="org/ns/app", endpoint="...",
).with_jwt_auth(
    "path/to/service.token",
    jwks_url="https://auth.example.com/.well-known/jwks.json",
    issuer="my-issuer",
    audience=["svc-b"],
)

Passing auth_secret= directly still works for backward compatibility with shared secret auth.

MessageContext

Handlers can optionally receive SLIM message context (sender identity, metadata, etc.) by adding a typed parameter:

from pattern_agentic_messaging import MessageContext

@app.on_message
async def handle(session, msg, msg_context: MessageContext):
    print(msg_context.source_name)       # sender identity
    print(msg_context.destination_name)   # destination
    print(msg_context.metadata)           # sender-supplied k/v pairs

Handlers without this parameter work as before.

Client

Connect to a specific peer:

config = PASlimConfig(
    local_name="org/ns/client",
    endpoint="https://slim.example.com",
    auth_secret="shared-secret-at-least-32-bytes!",
)

async with PASlimApp(config) as app:
    async with await app.connect("org/ns/server") as session:
        await session.send({"type": "prompt", "prompt": "Hello world!"})
        async for msg in session:
            print(f"RECEIVED: {msg}")

Join a group channel:

async with PASlimApp(config) as app:
    async with await app.join_channel() as session:
        async for msg in session:
            await session.send({"type": "response", "msg": "received"})

A2A Message Models

Lightweight Pydantic models for the A2A protocol message types, useful for constructing A2A-compliant payloads from clients:

from pattern_agentic_messaging.a2a import Message, Part, Role

msg = Message(role=Role.USER, parts=[Part.from_text("What time is it?")])
await session.send(msg.model_dump(by_alias=True, exclude_none=True))

Low-level usage

The decorator pattern's underlying API can be used directly:

async with PASlimApp(config) as app:
    async for session, msg in app:
        result = await process(msg["prompt"])
        await session.send({"result": result})

Message Types

All messages carry a metadata.__pa_type discriminator. See docs/message-types.md.

Metadata

Release files for pattern-agentic-messaging 1.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pattern-agentic-messaging 1.5.0
File Size Uploaded Provenance Actions
pattern_agentic_messaging-1.5.0.tar.gz 46.1 kB Without provenance Details for pattern_agentic_messaging-1.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pattern-agentic-messaging 1.5.0
File Interpreter ABI Platform Actions
pattern_agentic_messaging-1.5.0-py3-none-any.whl Python 3 none any Details for pattern_agentic_messaging-1.5.0-py3-none-any.whl

Total release size: 69.2 kB

Release files / pattern_agentic_messaging-1.5.0.tar.gz

Download URL pattern_agentic_messaging-1.5.0.tar.gz
Size 46.1 kB
Tags Source
SHA-256 checksum
How to use checksums
126a5487e7fa3c2f9105abd702ce55dc8402b1ffba8f17bc0aaf130320e37868
BLAKE2b-256 checksum
How to use checksums
1338fd1fd38f301ab07da0debdc2c5565aac8237a3bdd476121962664812aa48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / pattern_agentic_messaging-1.5.0-py3-none-any.whl

Download URL pattern_agentic_messaging-1.5.0-py3-none-any.whl
Size 23.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76819a551481f814b659023510baa26b9155b0961a45eae793630536af553e86
BLAKE2b-256 checksum
How to use checksums
dd940facde24b6ecdc83a34028192d2f7265aff285b5cb8d17fb287d29a1a3af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for pattern-agentic-messaging 1.5.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page