Skip to main content

Python SDK for AI Agent Assembly - A governance-native runtime for AI agents

Project description

Agent Assembly Python SDK

PyPI version Python versions CI License: MIT

Python SDK for AI Agent Assembly — a governance-native runtime for AI agents. One init_assembly() call wires your agent into the policy gateway, applies pre-execution allow/deny on tool calls, and emits audit events without changing how the agent itself is written.

Why use it

  • Framework adapters for LangChain, LangGraph, CrewAI, OpenAI Agents, Pydantic AI, and MCP servers — drop in, no SDK rewrites required.
  • Pre-execution policy enforcement via the FrameworkAdapter ABC — block disallowed tool calls before they hit the LLM.
  • Audit trail — every tool call, prompt, and policy decision is emitted to the gateway with full agent lineage (parent / root / team).
  • Native PyO3 fast path (optional) — drop into a Rust runtime client when you need sub-millisecond policy checks.
  • Typed throughout — Pydantic models for every gateway payload, mypy strict on adapter base and registry.

Requirements

  • Python >=3.12,<4.0 (3.12, 3.13, 3.14 are tested in CI)
  • Rust toolchain (stable channel) — only required for building the optional native extension via maturin develop. Pure-Python users do not need Rust.
  • uv ≥ 0.4 — recommended for managing the dev environment. (pip works for plain installs.)

Installation

Use the SDK in your project

pip install agent-assembly

(Once published to PyPI. Until then, install directly from GitHub:)

pip install git+https://github.com/AI-agent-assembly/python-sdk.git

Develop on the SDK

Clone the repo and sync the dev environment with uv:

git clone https://github.com/AI-agent-assembly/python-sdk.git
cd python-sdk
uv sync

To build the optional PyO3 extension locally (requires Rust):

uv tool run maturin develop --manifest-path rust/aa-ffi-python/Cargo.toml --release

The pure-Python SDK works without the native extension — maturin develop is only needed if you want the sub-millisecond RuntimeClient fast path.

Quick Start

A governed LangChain ReAct agent that runs offline against a mock LLM. The example imports LangChain in addition to the SDK, so install both:

pip install agent-assembly langchain langchain-community
from langchain.agents import AgentExecutor, create_react_agent
from langchain.tools import Tool
from langchain_community.llms import FakeListLLM
from langchain_core.prompts import PromptTemplate

from agent_assembly import init_assembly

with init_assembly(
    gateway_url="http://localhost:8080",
    api_key="dev-key",
    agent_id="quickstart-agent",
    mode="sdk-only",
):
    llm = FakeListLLM(responses=[
        "Thought: I should look up the user.\nAction: whoami\nAction Input: alice\n",
        "Thought: I have the answer.\nFinal Answer: alice is in engineering\n",
    ])
    tools = [Tool(name="whoami", func=lambda name: f"{name} is in engineering", description="who")]
    prompt = PromptTemplate.from_template(
        "Use the tools.\n{tools}\nTool names: {tool_names}\nQ: {input}\n{agent_scratchpad}"
    )
    executor = AgentExecutor(agent=create_react_agent(llm, tools, prompt), tools=tools, max_iterations=2)
    print(executor.invoke({"input": "Which team is alice on?"})["output"])

What this does:

  1. init_assembly() registers the agent with the gateway and auto-loads the LangChain adapter — every tool call from now on goes through the policy gate.
  2. The FakeListLLM replays canned responses so the example runs offline with no real LLM.
  3. The with block tears down the gateway connection and unwinds adapter hooks on exit.

Public API

  • init_assembly(gateway_url, api_key, agent_id=None, mode="auto") -> AssemblyContext
  • GatewayClient.register_agent() -> dict
  • GatewayClient.check_policy_compliance(action: str) -> dict
  • Exceptions: AssemblyError, AgentError, PolicyError, GatewayError, ConfigurationError
  • Data models: AgentConfig, AgentState, PolicyEvaluation

Error Handling

from agent_assembly import init_assembly
from agent_assembly.exceptions import ConfigurationError

try:
    context = init_assembly(gateway_url="", api_key="my-api-key", agent_id="my-agent-001")
except ConfigurationError as exc:
    print(f"Invalid configuration: {exc}")

Development

Run tests:

uv run pytest

Run integration tests:

uv run pytest -m integration

Lint and type-check:

uv run ruff check .
uv run mypy agent_assembly

Native Core Extension (AAASM-55)

Build and install the PyO3 extension locally:

uv tool run maturin develop --manifest-path rust/aa-ffi-python/Cargo.toml --release

Validate native module import:

from agent_assembly._core import RuntimeClient, GovernanceEvent, PolicyResult

Run opt-in native integration tests:

AAASM_RUN_NATIVE_CORE_TESTS=1 uv run pytest test/integration/test_native_core_runtime.py
AAASM_RUN_MATURIN_TESTS=1 uv run pytest test/integration/test_native_core_maturin.py

Documentation

Contributing

Please read CONTRIBUTING.md before opening a PR — it covers dev environment setup, framework adapter authoring, the test/lint command list, branch naming, and the PR checklist.

License

MIT License

Project details


Download files

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

Source Distribution

agent_assembly-0.0.1a4.tar.gz (68.8 kB view details)

Uploaded Source

Built Distributions

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

agent_assembly-0.0.1a4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

agent_assembly-0.0.1a4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

agent_assembly-0.0.1a4-cp312-cp312-macosx_11_0_arm64.whl (6.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

agent_assembly-0.0.1a4-cp312-cp312-macosx_10_12_x86_64.whl (6.8 MB view details)

Uploaded CPython 3.12macOS 10.12+ x86-64

File details

Details for the file agent_assembly-0.0.1a4.tar.gz.

File metadata

  • Download URL: agent_assembly-0.0.1a4.tar.gz
  • Upload date:
  • Size: 68.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for agent_assembly-0.0.1a4.tar.gz
Algorithm Hash digest
SHA256 016a3d785d34e78412ea2b188b055720d078d7bc17529e7769af785475f1a1f1
MD5 51e81cc52fe7a3e7618283d497b0924f
BLAKE2b-256 54c03087f3c4bf1e095787f9da54804f31215cff0f8b50d058a573a02a567475

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_assembly-0.0.1a4.tar.gz:

Publisher: release-python.yml on ai-agent-assembly/python-sdk

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

File details

Details for the file agent_assembly-0.0.1a4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for agent_assembly-0.0.1a4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c0ecddac3663f682a0683fddbccd9369c1739672cebd20cbe6e44af96c446285
MD5 274f0bd6c11e5a980f0103c872ed2f31
BLAKE2b-256 755fc6fcc0569cee0faeec60c57616c692df71c4d13920f0841bb746721fded1

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_assembly-0.0.1a4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release-python.yml on ai-agent-assembly/python-sdk

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

File details

Details for the file agent_assembly-0.0.1a4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for agent_assembly-0.0.1a4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f4eb09f552277260ce05a0b5781d730762aac849c554baad849589554b444ebe
MD5 36ebcde4008bdb203c1cb0cd957f8955
BLAKE2b-256 12c2c2aa1616de5a776363f09580f5a62fc6c0aed756e2267e56de5a08bce2f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_assembly-0.0.1a4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release-python.yml on ai-agent-assembly/python-sdk

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

File details

Details for the file agent_assembly-0.0.1a4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for agent_assembly-0.0.1a4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b116f8d5f13c9fe891a45a0ee6483e697416efd325c89959fa8134fd5ba2acef
MD5 82924a5cdefa4baa9d95bbf10bb1256c
BLAKE2b-256 6f9788fb884843d1ae44fb3208be8a94c084d2fa975706f25047609ea130b69e

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_assembly-0.0.1a4-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: release-python.yml on ai-agent-assembly/python-sdk

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

File details

Details for the file agent_assembly-0.0.1a4-cp312-cp312-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for agent_assembly-0.0.1a4-cp312-cp312-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 66f8cc944abefb382d5a48c91b459e967540b85d647ddd2539362403581d3fcf
MD5 5469a5b66de708e5736dc098cd85859f
BLAKE2b-256 bd4030ecb4f98ca840640c9b04a7acbfe83cce3e30fdb34b29f1d0a49bcb8b43

See more details on using hashes here.

Provenance

The following attestation bundles were made for agent_assembly-0.0.1a4-cp312-cp312-macosx_10_12_x86_64.whl:

Publisher: release-python.yml on ai-agent-assembly/python-sdk

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