latent.serve.events¶
Events an agent handles inside its serving pod (ADR-015 D5).
An agent method decorated with :func:event handles one named event. Studio's
worker fires it by calling POST /v1/events/{source}/{name} on the version the
conversation is served by; the handler returns an :class:EventResult, which
travels as the contract's EventDecision. Handlers reach Studio's timeboxes
and scratchpad through :class:StudioEvents (the pod-key routes), never through
Studio's database.
Classes¶
EventContext¶
EventContext(conversation_id: str, thread_id: str | None, endpoint_id: str | None, channel: str | None, event_name: str, source: EventSource, studio: StudioEvents, note: str | None = None, payload: dict[str, Any] | None = None, event_id: str | None = None)
What a handler knows about the firing.
EventResult¶
What a handler decided; build it with the class methods.
EventSpec¶
One @event declaration: the wire name, its source and the method.
Secret¶
A scratchpad value stored with secret=True: readable, never rendered.
Mirrors agent-studio's in-worker Secret (agent_studio_shared). A
tool's result is stringified into the model's context and the trace, so
str, repr and format render <redacted:key>, also inside a
dict, list or f-string. reveal() is the one unwrap.
StudioAuthError¶
Studio refused the pod's project key (401/403).
StudioEvents¶
StudioEvents(conversation_id: str, studio_url: str | None = None, api_key: str | None = None, client: httpx.AsyncClient | None = None)
Timebox and scratchpad access for one conversation, over Studio's pod routes.
Authenticates with the pod's project key (AGENT_STUDIO_API_KEY) against
AGENT_STUDIO_URL. Every failure raises: a handler that armed nothing must
not believe it did.
Functions¶
agent_events¶
Every @event handler of agent_cls keyed by (source, name).
event¶
event(name: str, source: EventSource = 'scheduled') -> Callable[[Callable[..., Awaitable[EventResult]]], Callable[..., Awaitable[EventResult]]]
Mark an async agent method as the handler of event name.
source="scheduled" handles a timebox firing; "external" an event a
caller posted to Studio. The method receives an :class:EventContext and
returns an :class:EventResult. Declared events are listed in the agent's
manifest, and Studio calls the pod only for a version that declares the event.
Methods¶
EventResult.finish¶
Send text and finish the conversation.
EventResult.noop¶
Do nothing.
EventResult.run_agent¶
Run an agent turn with prompt as its input.
EventResult.send¶
Send text to the conversation as the assistant.
EventResult.to_wire¶
The contract EventDecision as JSON-ready data.
Secret.reveal¶
The plaintext; the one place a secret becomes renderable.
StudioEvents.arm¶
Arm timebox name to fire in seconds; return the firing nonce.
A retry that passes the same idempotency_key gets the first arm's
nonce and arms no second timer.
StudioEvents.cancel¶
Cancel timebox name.
StudioEvents.peek¶
The state of timebox name, or None when it was never armed.
StudioEvents.scratch_get¶
The scratchpad value under key, or None when absent.
A value stored as a secret comes back as a redacting :class:Secret.
StudioEvents.scratch_remove¶
Remove key from the scratchpad.
StudioEvents.scratch_set¶
Store value (JSON) under key.
secret=True, or a :class:Secret value, stores it as a secret;
secret=False stores it plain, even for a :class:Secret value. Left
out, Studio keeps the flag the key already has.