Skip to main content

Overview

HttpChannel keeps a conversation on a remote server and reaches it with three HTTP calls. Agents on different machines that point at the same URL share one conversation. The URL names the conversation, so one server can hold many.

Import

Server contract

The channel needs a server that answers three calls on the conversation’s URL: Any 2xx status counts as success, and the bodies of POST and DELETE replies are ignored. Any other status raises httpx.HTTPStatusError. Extra keys in GET rows are dropped, and agent_name and content are converted with str(). A minimal server with the standard library, keeping each conversation in memory by path:
This server is for local testing. A production server should authenticate requests and store messages durably.

Constructor

str
required
The conversation’s endpoint, such as https://host/channels/research.
Dict[str, str]
default:"None"
Sent with every call, for example an Authorization header.
float
default:"30.0"
Seconds to wait for each call.

Attributes

Methods

post()

POST one message to the server.
Raises: httpx.HTTPStatusError on a non-2xx reply.

messages()

GET every message from the server, oldest first. Each call makes one request.
Raises: httpx.HTTPStatusError on a non-2xx reply.

clear()

DELETE every message on the server.
Raises: httpx.HTTPStatusError on a non-2xx reply.

close()

Close the connection pool. The server keeps every message.

Usage Examples

Two machines, one conversation

Run the first agent on one host:
And the second on another. It reads the Researcher’s answer from the server before it runs:
Both agents run the same task, so it is posted once. More examples are in the HttpChannel quickstart.

Notes

  • No retries. A failed call raises straight away. If the server can be briefly unavailable, wrap the run in your own retry.
  • A failed post fails the run. If the server rejects the answer, run() raises httpx.HTTPStatusError instead of returning the answer.

Source Code