Python Runtime API
Configuration inputs
from sagents.v2 import SAgentBuilder
from sagents.v2.package.manifest import SageManifest, SageManifestLoader
# YAML text; no file is created.
manifest = SageManifestLoader().loads(yaml_text)
# Or validate a Python dictionary:
# manifest = SageManifest.model_validate(config_dict)
app = await SAgentBuilder().with_defaults(session_root="runtime").build(manifest)
build() also accepts a ResolvedSageManifest or a path to a file named sage.yaml. Raw strings are paths. loads() does not resolve relative instruction files; use inline instructions or the file loader.
Execution and ownership
- Obtain
app.entrypoint(). - Create a
RequestContextwith the authenticatedActorRefsupplied by your host. - Submit
StartRunthroughrun_stream(command, context). - Consume
stream.events;await stream.wait()returns aRunSnapshotwith.state. - Close
appin afinallyblock.
Use a new idempotency key for each logical request, and reuse it only when retrying that same request. Production adapters must not trust a client-supplied user ID. Access Sessions through app.service("session.access") with context; the raw SessionStore is a trusted internal port.
Cancellation, steering, resumption, and interaction replies are explicit commands; disconnecting an event stream only detaches that observer. A snapshot may be suspended rather than terminal.