Skip to content
Pyrula

Client

AgentClient is the async client for an agent server. It wraps the HTTP routes so you submit, stream, and cancel turns without hand-writing requests.

from pyrula.agents.client.client import AgentClient
client = AgentClient("https://agents.example.com")
handle = await client.submit("support", message="where is my order?")
async for event in client.stream("support", handle.turn_id):
print(event.kind, event.payload)

submit returns a handle with the turn id and stream path. stream yields events until the turn finishes.

When you just want the result and don’t care about intermediate events, run submits and drains the stream for you, returning the full event list once the turn ends:

events = await client.run("support", message="where is my order?")

stream takes a last_event_id. Pass the id of the last event you saw and the server resumes from there, so a dropped connection doesn’t lose events or replay ones you already handled.

async for event in client.stream("support", turn_id, last_event_id=seen):
...
info = await client.status("support", turn_id)
await client.cancel("support", turn_id)

idempotency_key on submit and run makes a retried submission safe: the same key returns the existing turn instead of starting a new one.