Skip to main content

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 the agent-runtime binary (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

  1. Collect the full trace with on_event=trace.append
  2. On RunError, filter [ev for ev in trace if ev.error] to find the failing node
  3. Inspect ev.inputs, ev.args, and ev.output on surrounding events to understand the data at that point
  4. Fix the bundle or tool, then re-run

Binary Resolution

The SDK locates the agent-runtime binary in this order:

  1. binary argument passed to Runtime()
  2. AGENT_RUNTIME_BIN environment variable
  3. Bundled platform binary (included in the package)
  4. agent-runtime on PATH

Development

uv run pytest          # run tests
uv run ruff check .    # lint

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

lp_agent_runtime_sdk-0.1.9-py3-none-win_amd64.whl (43.0 MB view details)

Uploaded Python 3Windows x86-64

lp_agent_runtime_sdk-0.1.9-py3-none-macosx_11_0_arm64.whl (8.4 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

lp_agent_runtime_sdk-0.1.9-py3-none-macosx_10_12_x86_64.whl (17.4 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file lp_agent_runtime_sdk-0.1.9-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for lp_agent_runtime_sdk-0.1.9-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 5aad6275bbc2bcac495a3a16a2aa85ecf000a0b1461356bdf94c3c2d87469fd8
MD5 b4bf6631298e3cce9b6a6dc00cff19b9
BLAKE2b-256 0cf6a07e63af28f14f9e1712c3b03b9aa72901c93ef841c794b192d7a1d09ecb

See more details on using hashes here.

Provenance

The following attestation bundles were made for lp_agent_runtime_sdk-0.1.9-py3-none-win_amd64.whl:

Publisher: publish.yml on levelplaneai/agent-runtime-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lp_agent_runtime_sdk-0.1.9-py3-none-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for lp_agent_runtime_sdk-0.1.9-py3-none-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ba7de6a055b645dfb66fb43a395ab3c8393d3cfd6267a257be25be767e168124
MD5 b4a0050f4c6a5824bd9057b8751f24f5
BLAKE2b-256 1851cc1454eb92ca3ceca71469a76a1579e2b06cce9bae7db24652fc5a747e7c

See more details on using hashes here.

Provenance

The following attestation bundles were made for lp_agent_runtime_sdk-0.1.9-py3-none-manylinux2014_x86_64.whl:

Publisher: publish.yml on levelplaneai/agent-runtime-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lp_agent_runtime_sdk-0.1.9-py3-none-manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for lp_agent_runtime_sdk-0.1.9-py3-none-manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b00d90f0f5b5e7ad5b2a20d7182df4d1084f97dc99aebdcf40b32bba2aa29c3d
MD5 cbc5d4deffef532861b50bcb121b1c4c
BLAKE2b-256 ffc0b3c78da7f392c935e98da92e5a7b4ba8312f2ef3d3300d8fa1fb4693b235

See more details on using hashes here.

Provenance

The following attestation bundles were made for lp_agent_runtime_sdk-0.1.9-py3-none-manylinux2014_aarch64.whl:

Publisher: publish.yml on levelplaneai/agent-runtime-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lp_agent_runtime_sdk-0.1.9-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for lp_agent_runtime_sdk-0.1.9-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8ad673bcb441c82de810e9980e541e703763e67b1aa37010a7ec33ff931f4f9c
MD5 f45ac57f44de58ca7586908f71f6a78b
BLAKE2b-256 d3a2b436106714826cbc2b2c6416f36840ed394dba391c9efb4bc487420fba3c

See more details on using hashes here.

Provenance

The following attestation bundles were made for lp_agent_runtime_sdk-0.1.9-py3-none-macosx_11_0_arm64.whl:

Publisher: publish.yml on levelplaneai/agent-runtime-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lp_agent_runtime_sdk-0.1.9-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for lp_agent_runtime_sdk-0.1.9-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e09552db476e542a91c96d666bb797f4c7e57f53c9d7e4941203ef4ed0936bd6
MD5 f846da1269d4b74bc19b45e9de09e41f
BLAKE2b-256 df0585c8aa09081b7688d6734485bc8f9f777eff8d81d311d31809001934164b

See more details on using hashes here.

Provenance

The following attestation bundles were made for lp_agent_runtime_sdk-0.1.9-py3-none-macosx_10_12_x86_64.whl:

Publisher: publish.yml on levelplaneai/agent-runtime-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page