Python SDK for agent-runtime — invoke declarative agent workflows from Python
Project description
lp-agent-runtime-sdk
Python SDK for running agent-runtime workflows. Wraps the agent-runtime binary to execute declarative .agent bundles from Python, with support for registering Python functions as callable tools.
Installation
pip install lp-agent-runtime-sdk
# or
uv add lp-agent-runtime-sdk
The package ships pre-built binaries for macOS (arm64, amd64), Linux (amd64, arm64), and Windows (amd64) — no separate install required.
Quick Start
from agent_runtime import Runtime, RunError
rt = Runtime()
@rt.tool("pricing.get_quote", version="v1")
def get_quote(sku: str, quantity: int) -> dict:
return {"unit_price": 9.99, "currency": "USD"}
try:
output = rt.run("./my_bundle.agent", inputs={"sku": "ABC-1", "quantity": 10})
print(output)
except RunError as e:
print(f"Flow failed: {e} (run_id={e.run_id})")
Authoring Bundles
Bundles are directories with a .agent extension containing a declarative flow definition. See FLOWS.md in the main repo for the full authoring guide.
API Reference
Runtime(binary=None, env=None)
Creates a runtime instance.
binary— explicit path to theagent-runtimebinary (optional)env— extra environment variables merged into the subprocess environment
@rt.tool(name, version="v1")
Decorator that registers a Python function as a tool callable by the workflow. The tool reference inside the bundle must match name@version.
@rt.tool("supplier_api.get_price", version="v1")
def get_price(item_code: str) -> dict:
return {"price": 42.0}
# Async tools are also supported
@rt.tool("data.fetch_record", version="v1")
async def fetch_record(record_id: str) -> dict:
...
rt.run(bundle, inputs=None, on_event=None) -> dict
Executes a bundle synchronously and returns the flow output as a dict.
rt.arun(bundle, inputs=None, on_event=None) -> dict
Async version of run. Use with await inside an async context.
result = await rt.arun("./bundle.agent", inputs={"query": "hello"})
rt.validate(bundle)
Validates a bundle directory. Raises RuntimeError if the bundle is invalid.
File Inputs
Use FileInput to pass a local file as a flow input. The path is resolved to an absolute path automatically.
from agent_runtime import Runtime, FileInput
rt = Runtime()
output = rt.run("./ocr_bundle.agent", inputs={"document": FileInput("./invoice.pdf")})
Streaming Events
Pass an on_event callback to receive TraceEvent objects as the workflow executes.
def on_event(event: TraceEvent) -> None:
print(f"[{event.event}] node={event.node} duration={event.duration_ms}ms")
rt.run("./bundle.agent", inputs={...}, on_event=on_event)
Key TraceEvent fields:
| Field | Type | Description |
|---|---|---|
event |
str |
Event type (e.g. node.start, node.done, tool.call) |
node |
str |
Node name in the flow |
node_type |
str |
Node type (e.g. llm, tool, router) |
tool |
str |
Tool reference if a tool was called |
model |
str |
Model name for LLM nodes |
input_tokens |
int |
Tokens consumed |
output_tokens |
int |
Tokens produced |
duration_ms |
int |
Node execution time |
error |
str |
Error message if the node failed |
output |
dict |
Node output |
Traces & Debugging
Where traces go
Trace events are emitted by the runtime binary to stdout as newline-delimited JSON and streamed to you in real time via the on_event callback. There is no separate log file — if you don't attach a callback, events are silently consumed and discarded.
To capture a full trace for debugging, collect all events into a list:
from agent_runtime import Runtime, TraceEvent, RunError
rt = Runtime()
trace: list[TraceEvent] = []
try:
output = rt.run("./bundle.agent", inputs={...}, on_event=trace.append)
except RunError as e:
# Flow-level failure — the error message and run_id are on the exception.
# Check the trace for the node that produced the error.
failed = [ev for ev in trace if ev.error]
for ev in failed:
print(f"node={ev.node} error={ev.error}")
raise
Event types
| Event | When it fires |
|---|---|
flow_start |
Flow begins executing |
flow_done |
Flow completed successfully |
node_start |
A node begins executing |
node_done |
A node finished (check ev.error for failure) |
tool_call |
The runtime is calling a registered tool |
tool_done |
Tool call returned |
Error channels
There are two ways a run can surface an error:
Node-level — a node fails but the flow may continue (e.g. a retry). Delivered as a TraceEvent with event="node_done" and a non-empty error field. The attempt and max_retries fields indicate retry state.
Flow-level — the flow terminates in an error state. The SDK raises RunError with the message and run_id. Check the collected trace to find which node caused it.
Binary crash — the agent-runtime process exits with a non-zero code (misconfigured bundle, missing env var, etc.). The SDK raises RuntimeError with the stderr output as the message. This is distinct from a flow error and does not produce a RunError.
Typical debug loop
- Collect the full trace with
on_event=trace.append - On
RunError, filter[ev for ev in trace if ev.error]to find the failing node - Inspect
ev.inputs,ev.args, andev.outputon surrounding events to understand the data at that point - Fix the bundle or tool, then re-run
Binary Resolution
The SDK locates the agent-runtime binary in this order:
binaryargument passed toRuntime()AGENT_RUNTIME_BINenvironment variable- Bundled platform binary (included in the package)
agent-runtimeonPATH
Development
uv run pytest # run tests
uv run ruff check . # lint
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lp_agent_runtime_sdk-0.1.6-py3-none-win_amd64.whl.
File metadata
- Download URL: lp_agent_runtime_sdk-0.1.6-py3-none-win_amd64.whl
- Upload date:
- Size: 43.0 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f2d97ce9ff5299e73b34483add12f29965daa882d559aa304bd73bcd78e8f49
|
|
| MD5 |
7f47d9683677307fcaa83c5342ddfb6c
|
|
| BLAKE2b-256 |
2ac4a3939847fbbcf78c5f575207cfe9b0945f4b4ad1e479165e88b68d844807
|
Provenance
The following attestation bundles were made for lp_agent_runtime_sdk-0.1.6-py3-none-win_amd64.whl:
Publisher:
publish.yml on levelplaneai/agent-runtime-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lp_agent_runtime_sdk-0.1.6-py3-none-win_amd64.whl -
Subject digest:
4f2d97ce9ff5299e73b34483add12f29965daa882d559aa304bd73bcd78e8f49 - Sigstore transparency entry: 2084384794
- Sigstore integration time:
-
Permalink:
levelplaneai/agent-runtime-python@c3dfd8a3dace012a2943cc3c7451bac90456b72f -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/levelplaneai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c3dfd8a3dace012a2943cc3c7451bac90456b72f -
Trigger Event:
push
-
Statement type:
File details
Details for the file lp_agent_runtime_sdk-0.1.6-py3-none-manylinux2014_x86_64.whl.
File metadata
- Download URL: lp_agent_runtime_sdk-0.1.6-py3-none-manylinux2014_x86_64.whl
- Upload date:
- Size: 26.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e627fd75b40d764adfcf59152fdea079f498a45f6fdfc0248951a303fb2b5538
|
|
| MD5 |
495c0897b84538403e249450ce2f845b
|
|
| BLAKE2b-256 |
23159d6df21d7f63af408c7f4697506084538040f72ddc878a906b92e0d68f50
|
Provenance
The following attestation bundles were made for lp_agent_runtime_sdk-0.1.6-py3-none-manylinux2014_x86_64.whl:
Publisher:
publish.yml on levelplaneai/agent-runtime-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lp_agent_runtime_sdk-0.1.6-py3-none-manylinux2014_x86_64.whl -
Subject digest:
e627fd75b40d764adfcf59152fdea079f498a45f6fdfc0248951a303fb2b5538 - Sigstore transparency entry: 2084384782
- Sigstore integration time:
-
Permalink:
levelplaneai/agent-runtime-python@c3dfd8a3dace012a2943cc3c7451bac90456b72f -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/levelplaneai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c3dfd8a3dace012a2943cc3c7451bac90456b72f -
Trigger Event:
push
-
Statement type:
File details
Details for the file lp_agent_runtime_sdk-0.1.6-py3-none-manylinux2014_aarch64.whl.
File metadata
- Download URL: lp_agent_runtime_sdk-0.1.6-py3-none-manylinux2014_aarch64.whl
- Upload date:
- Size: 34.0 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b62b8dce73cc8f154a444edcad396609cd726a84297b7555d8aff87ce1a5228b
|
|
| MD5 |
e8331f1122eb720232f2bf5f0b7721ac
|
|
| BLAKE2b-256 |
1da2fb3042eaefff6fc8d2178362042e9ba9133cafdcf7e8aab49d877d5bc4d2
|
Provenance
The following attestation bundles were made for lp_agent_runtime_sdk-0.1.6-py3-none-manylinux2014_aarch64.whl:
Publisher:
publish.yml on levelplaneai/agent-runtime-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lp_agent_runtime_sdk-0.1.6-py3-none-manylinux2014_aarch64.whl -
Subject digest:
b62b8dce73cc8f154a444edcad396609cd726a84297b7555d8aff87ce1a5228b - Sigstore transparency entry: 2084384834
- Sigstore integration time:
-
Permalink:
levelplaneai/agent-runtime-python@c3dfd8a3dace012a2943cc3c7451bac90456b72f -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/levelplaneai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c3dfd8a3dace012a2943cc3c7451bac90456b72f -
Trigger Event:
push
-
Statement type:
File details
Details for the file lp_agent_runtime_sdk-0.1.6-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: lp_agent_runtime_sdk-0.1.6-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 8.4 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73e042df9924764f05d860bb8e1c8511f47dde1eb8a686a38096f3ee424dd986
|
|
| MD5 |
585d935cfadd3fc5498ef2c1c2d1a6ad
|
|
| BLAKE2b-256 |
fd1d523ccd33a52ab491d8f8a646dc55261e7606216ed67df262592477454306
|
Provenance
The following attestation bundles were made for lp_agent_runtime_sdk-0.1.6-py3-none-macosx_11_0_arm64.whl:
Publisher:
publish.yml on levelplaneai/agent-runtime-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lp_agent_runtime_sdk-0.1.6-py3-none-macosx_11_0_arm64.whl -
Subject digest:
73e042df9924764f05d860bb8e1c8511f47dde1eb8a686a38096f3ee424dd986 - Sigstore transparency entry: 2084384766
- Sigstore integration time:
-
Permalink:
levelplaneai/agent-runtime-python@c3dfd8a3dace012a2943cc3c7451bac90456b72f -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/levelplaneai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c3dfd8a3dace012a2943cc3c7451bac90456b72f -
Trigger Event:
push
-
Statement type:
File details
Details for the file lp_agent_runtime_sdk-0.1.6-py3-none-macosx_10_12_x86_64.whl.
File metadata
- Download URL: lp_agent_runtime_sdk-0.1.6-py3-none-macosx_10_12_x86_64.whl
- Upload date:
- Size: 17.4 MB
- Tags: Python 3, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3871a92d6ca44f81fb0298d4838a5d0f0b305f846e11bed33c00f78038a58821
|
|
| MD5 |
fd932873274535011ca94fd09937a0dc
|
|
| BLAKE2b-256 |
00b496b98942cc75fcb5debfd09f844d86f292650ab51a4e75509d1fcc20353b
|
Provenance
The following attestation bundles were made for lp_agent_runtime_sdk-0.1.6-py3-none-macosx_10_12_x86_64.whl:
Publisher:
publish.yml on levelplaneai/agent-runtime-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lp_agent_runtime_sdk-0.1.6-py3-none-macosx_10_12_x86_64.whl -
Subject digest:
3871a92d6ca44f81fb0298d4838a5d0f0b305f846e11bed33c00f78038a58821 - Sigstore transparency entry: 2084384813
- Sigstore integration time:
-
Permalink:
levelplaneai/agent-runtime-python@c3dfd8a3dace012a2943cc3c7451bac90456b72f -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/levelplaneai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c3dfd8a3dace012a2943cc3c7451bac90456b72f -
Trigger Event:
push
-
Statement type: