AGNT5 Python SDK
Build reliable AI agents and durable workflows in Python. AGNT5 checkpoints each workflow step, so a run that fails partway resumes from its last completed step instead of starting over. The SDK provides typed functions and workflows, retries, streaming, tool calling, multi-agent handoffs, human-in-the-loop (HITL) approvals, MCP, evals, and runtime observability.
Documentation · Starter templates · Website
Requirements
- Python 3.11 or newer
- An AGNT5 runtime for deployed execution
Installation
pip install agnt5
Quick start
Define a function. Type hints are used to derive its input and output schema.
from agnt5 import FunctionContext, function
@function(retries=3, backoff="exponential")
async def greet(ctx: FunctionContext, name: str) -> dict[str, str]:
ctx.logger.info("greeting user", extra={"name": name})
return {"message": f"Hello, {name}!"}
Register application components with a worker for runtime-backed execution:
import asyncio
from agnt5 import Worker
async def main() -> None:
worker = Worker(service_name="hello-python")
await worker.run()
asyncio.run(main())
Decorated functions, workflows, agents, tools, and scorers are registered when
their modules are imported. See examples/app.py for a
complete application entrypoint.
Invoke a deployed component
from agnt5 import Client
client = Client(
gateway_url="https://gw.agnt5.com",
api_key="agnt5_sk_...",
deployment_id="deployment-id",
)
result = client.run("greet", {"name": "Ada"})
print(result)
Client also supports asynchronous submission, status and result polling,
streaming events, batches, cancellation, workflow resume, chat, and evaluation.
Configuration can be supplied explicitly or through AGNT5_GATEWAY_URL,
AGNT5_API_KEY, and AGNT5_DEPLOYMENT_ID.
Durable steps
Use @step for an operation inside a durable workflow. Its handler starts
after the runtime acknowledges admission, and its result becomes available
after the runtime acknowledges completion. Those two activation calls also
record the step's lifecycle; the SDK adds no separate function checkpoints.
from agnt5 import StepContext, WorkflowContext, step, workflow
@step(retries=3, backoff="exponential", timeout_ms=5000)
async def prepare_search(ctx: StepContext, topic: str) -> dict[str, str]:
return {"query": topic.strip()}
@workflow
async def research(ctx: WorkflowContext, topic: str) -> dict[str, str]:
return await ctx.step(prepare_search, topic, key="search-query")
Register the workflow with a worker; @step handlers are workflow-local and
are not standalone components. Invoke them through ctx.step(...).
Direct calls and execution without durable activation
support raise an error rather than running without durability. A first
parameter named ctx receives a StepContext; it can be omitted when unused.
Sync handlers run in an executor thread.
Use explicit keys for parallel or repeated work. Completed steps replay their
committed result without executing the handler again. Retries reuse the same
activation identity with runtime-owned attempts. External side effects still
need idempotency: ctx.activation.idempotency_key is available to handlers.
Existing @function handlers remain supported with their function checkpoints.
ctx.step(...) is the only way to run a step. ctx.task(...) and ctx.run(...)
were removed; replace either with ctx.step(...) using the same arguments and
keys.
Core APIs
| API | Purpose |
|---|---|
@function |
Typed, retryable units of work |
@step |
Workflow-local durable operations with acknowledged admission and completion |
@workflow |
Durable multi-step orchestration and checkpointing |
Agent and @agent |
Model and tool orchestration |
@tool |
Typed tools with generated schemas |
ctx.state |
Durable workflow and component state |
ctx.memory |
Conversation and application memory |
Client / AsyncClient |
Invoke and observe deployed components |
Worker |
Register components and serve runtime dispatch |
Functions called inside workflow steps honor their declared retry and backoff policy. With negotiated durable activations, each attempt is admitted and recorded by the runtime; compatibility execution applies the same attempt budget locally. Completed steps replay their recorded output. Make external side effects idempotent so an interrupted attempt can safely run again.
In async workflows, use await ctx.state.set_async(key, value) and
await ctx.state.delete_async(key). These await the runtime's durable
acknowledgment while allowing other workflows to run. Reads remain local via
ctx.state.get(key). The existing synchronous set and delete methods remain
supported, but block their calling thread while waiting for persistence.
The shared Rust runtime foundation lives in
agnt5dev/sdk-core. Vendor sandbox
adapters live in
agnt5dev/sdk-integrations.
Event triggers
Use event(...) or webhook(...) in a workflow's triggers declarations.
Filtering, input mapping, batching, and delays are not supported yet. Leave
filter_expression, input_mapping, batch_window_ms, and delay_expression
unset; workflow registration rejects nonempty expressions and nonzero batch
windows with an error naming the option.
Examples and documentation
examples/contains functions, workflows, agents, tools, streaming, HITL, MCP, chat, and evaluation examples.docs/contains SDK-specific guides.- AGNT5 documentation covers platform concepts and deployment.
Response wait
Run and stream calls wait up to 5 minutes by default. Set the per-call wait to any value from zero to 24 hours. Zero returns a pending receipt immediately after acceptance. This controls response waiting, not the workflow execution deadline: accepted work continues when the wait expires or the client disconnects.
result = client.run("process_order", order, component_type="workflow", wait_timeout=60)
for event in client.stream_events("process_order", order, component_type="workflow", wait_timeout=60):
print(event.event_type, event.run_id)
wait_timeout uses seconds and also applies to async run and stream_events.
Run calls return 202 pending receipts directly, without additional polling.
Event streams emit stream.wait_expired when the wait expires, or
stream.detached for a 202 receipt. Use the run ID to read status/results.
Chunk-only stream raises RunError with the run ID when waiting ends.
The default HTTP timeout allows at least the wait plus 10 seconds, or the client
timeout if longer. Pass timeout=75 to set it explicitly. Python's HTTP timeout
limits individual network operations; wait_timeout bounds the gateway wait.
Structured assertions
structured_assertions is a reserved built-in scorer, so workers need no user
registration. The local helper uses the same SDK-core implementation as the runtime:
from agnt5.eval import ScorerInput, structured_assertions
result = structured_assertions(
ScorerInput(output=[1, 2, 3], expected={"expected_length": 3}),
{"assertions": [
{"name": "unique_ids", "expr": "unique(output_json)"},
{"name": "count", "expr": "size(output_json) == expected.expected_length"},
]},
)
The score is the fraction of assertions that pass; score_threshold defaults to
- Configuration and input errors always fail. See the SDK-core contract for supported expressions and execution limits. Requires the matching native extension.
Serverless signing
Pass signing_secret to agnt5.serverless.serve() or ServerlessApp. It can be a
string or a resolver that reads your provider's environment. Invokes with no
resolved secret return HTTP 503 (WORKERLESS_SIGNING_SECRET_REQUIRED) before
running user code. Missing or invalid signatures with a configured secret return
401. The manifest remains available for discovery.
For local development only, serve(allow_unsigned=True) permits unsigned invokes
when no secret resolves and logs a warning at startup. It still verifies requests
when a secret is configured. Missing static secrets warn at startup; an empty
request-time resolver warns on its first failed invoke. AGNT5 activation and
dispatch still require a signing secret, regardless of this SDK option.
Span payload privacy
Worker dispatch spans and workflow function spans omit input.data and
output.data by default. Identity, status, timing, and native payload-size
attributes remain available. To opt in, set
AGNT5_CAPTURE_CONTENT_MODE=redacted (or full). Both modes always redact known
credential fields, including nested bot_token and Authorization, before
serialization and truncation. Embedded JSON strings are decoded for redaction.
Malformed JSON-like strings are omitted; arbitrary objects have no repr fallback.
For application-specific fields, pass Worker(span_payload_redactor=redact),
where redact(value) is a synchronous function. It receives a detached,
JSON-safe copy of each opted-in input and output, after credential redaction.
Return the replacement value or None to omit that payload. The SDK applies
credential redaction again after the hook. A hook or serialization error omits
the payload without logging its contents. Nested workflows inherit this policy.
Hooks must be fast and must not log sensitive values.
AGNT5_CAPTURE=off disables these span payloads even with an explicit mode.
AGNT5_SPAN_ATTRIBUTE_VALUE_MAX_BYTES caps each UTF-8 attribute, including its
truncation marker (default 8192). Zero, negative, or invalid limits omit capture.
Invalid content modes also omit capture. The legacy
AGNT5_LLM_CAPTURE_CONTENT=true/on/1/yes still opts in when no explicit mode is
set; false/off/0/no disables it. Python third-party integrations now also
default to metadata-only through the same mode parser. Deployments that relied
on their former default must opt in explicitly.
This policy does not change handler arguments, results, durable checkpoints, replay bytes, chat reply credentials, user-authored logs, or exception attributes. It does not govern the native LM client's content recording or other SDKs. Removing credentials from gateway-produced run input needs a separate producer and secret-resolution contract; redacting spans does not remove stored run input.
Development
uv sync --all-groups
uv run ruff check src tests
uv run pytest tests/unit -q
uv build --sdist
Development builds use a sibling checkout of
sdk-core.
Contributing
See CONTRIBUTING.md. Report security issues according to SECURITY.md.
License
Licensed under the Apache License 2.0.
Declared steps keep managed waits such as ctx.sleep() and ctx.wait_for_user() at workflow boundaries. Call them between steps. For a timed-out synchronous handler, failure and retries wait until its executor thread exits; a timeout cannot stop a Python thread.
Metadata
Release files for agnt5 0.16.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| agnt5-0.16.1.tar.gz | 1.0 MB | Without provenance | Details for agnt5-0.16.1.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| agnt5-0.16.1-cp310-abi3-manylinux_2_28_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ x86-64 | Details for agnt5-0.16.1-cp310-abi3-manylinux_2_28_x86_64.whl |
| agnt5-0.16.1-cp310-abi3-manylinux_2_28_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ ARM64 | Details for agnt5-0.16.1-cp310-abi3-manylinux_2_28_aarch64.whl |
| agnt5-0.16.1-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details for agnt5-0.16.1-cp310-abi3-macosx_11_0_arm64.whl |
Total release size: 56.8 MB
Release files / agnt5-0.16.1.tar.gz
| Download URL | agnt5-0.16.1.tar.gz |
|---|---|
| Size | 1.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
04649dfbdea12e5fbe3fc1797354f387f87422fc9d832f5b470d7e8bac751ed4
|
|
BLAKE2b-256 checksum How to use checksums |
d1c84ce231567ce067459fdad4e5be3d822aae391c60f641757b5f180cc2054f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / agnt5-0.16.1-cp310-abi3-manylinux_2_28_x86_64.whl
| Download URL | agnt5-0.16.1-cp310-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 18.9 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
eccec9bba85c51f2cace9da5c92e8e7f34d529b2f91fdc5bb4198846773763bd
|
|
BLAKE2b-256 checksum How to use checksums |
739bcdf8c64fabd80a8e78eeba3a04fda7825e223f34d0ef9bb1b74d2775893c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / agnt5-0.16.1-cp310-abi3-manylinux_2_28_aarch64.whl
| Download URL | agnt5-0.16.1-cp310-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 19.9 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
b113d1fbf34e260216266200ae28ffca23c8bf82c9debf6026a0e057a028ce95
|
|
BLAKE2b-256 checksum How to use checksums |
9e73566ae94f04e650da1dec44a1380a7048dd8c1750273242b31c35a685d4d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / agnt5-0.16.1-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | agnt5-0.16.1-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 17.0 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b724b8fb1a823a6e35cf57572e5a879e0d76c8141152c8caebb9a437e17921ef
|
|
BLAKE2b-256 checksum How to use checksums |
6d079d7f3780117785fa938b38c08ab5d4f5953e7f89adc7827b6d8a64178ee2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for agnt5 0.16.1
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.