Skip to main content

haikeilabs-agentware

Policy enforcement and audit middleware for LLM agent tool calls.

haikeilabs-agentware sits between an agent (the LLM orchestrator) and tool execution. Every tool call is checked against policy (allow, deny, or filter with redacted arguments, rate limits, caller-context conditions) and every decision is audited. It is the Python implementation of agentware, which also ships Go and TypeScript implementations with the same behaviour.

Install

pip install haikeilabs-agentware

Quick start with Kei policies: socket client first

For an executable allow/deny walkthrough through the kei-proxy socket, see the Python getting started guide and the examples/python/minimal-harness example. KeiProxySocketAuthorizeClient is the recommended client; KeiProxyAuthorizeClient (kei-proxy authorize subprocess) is deprecated. The package install lines and supported runtime versions are listed in the repository README.

from haikeilabs.agentware.middleware import AuditedToolClient
import haikeilabs.agentware.kei

The distribution is haikeilabs-agentware (like the npm package @haikeilabs/agentware); the import package is haikeilabs.agentware, under the haikeilabs namespace. Python 3.10 or later.

Middleware first

Python is middleware-first by design. llm/backend.py defines an abstract backend; it has no concrete model backend or agent loop. Wrap tool calls from frameworks such as LangGraph with AuditedToolClient. For example, a LangGraph tool node can call this async function:

from haikeilabs.agentware.middleware import AuditedToolClient

client = AuditedToolClient(source="example")


def lookup_topic(topic: str) -> str:
    return f"Notes about {topic}"


async def lookup_topic_node(topic: str) -> str:
    return await client.Execute(
        "lookup_topic", {"topic": topic},
        user_id="alice", channel_id="session-1", guild_id=None,
        func=lookup_topic,
    )

Without an evaluator, the Python client allows calls and records them. Supply an evaluator to enforce a policy before running the tool. For the adapters in this repo and what they wrap, see Framework integrations.

Quick start

from haikeilabs.agentware.middleware import (
    Action,
    AuditedToolClient,
    CallerContext,
    Policy,
    Rule,
    SimplePolicyEvaluator,
)

policy = Policy(rules=[
    Rule(name="no-repo-deletes", tools=["github.delete_repo"], action=Action.DENY),
    Rule(name="default", tools=["*"], action=Action.ALLOW),
])
evaluator = SimplePolicyEvaluator(policy)

# The human who started the request. Trusted defaults to False (fail closed).
caller = CallerContext(user_id="ada", invoking_subject="ada")
decision = evaluator.evaluate("github.delete_repo", {"repo": "pipeline"}, caller)
assert decision.action is Action.DENY

# AuditedToolClient enforces the decision and records it, allow or deny.
client = AuditedToolClient(evaluator=evaluator)

When an agent delegates to a subagent, CallerContext.delegate() carries the invoking subject unchanged and records the parent span and delegation depth, so the audit trail always leads back to the human who authorized the request.

Audit records stay in process (InMemoryAuditor); Kei sees only kei-proxy's decision record. See Seeing protected tool calls in Kei.

What's in the package

  • haikeilabs.agentware.middleware: the policy evaluator, rules and conditions, rate limits, auditors, AuditedToolClient, and agent-loop guardrails.
  • haikeilabs.agentware.kei: Kei integration. KeiProxyEvaluator is a policy evaluator backed by kei-proxy that fails closed on everything except an explicit allow. The Python-only HarnessContract helper and manifest loading also live here; that helper is not a cross-language SDK contract.
  • haikeilabs.agentware.toolformat: tool-call formatting and parsing for open models without native tool-call APIs (Llama, Mistral, Qwen, Nemotron and others).
  • haikeilabs.agentware.llm, haikeilabs.agentware.llmcontext: token counting, context-window accounting and conversation compaction.
  • haikeilabs.agentware.tools, executor, jobs, prompts: the tool registry, dispatch, background jobs and system-prompt generation.

The Guardrails facade follows the Forge guardrails API design. Forge is MIT licensed; attribution and the license text are in THIRD_PARTY_NOTICES.md.

from haikeilabs.agentware.middleware.guardrails import Guardrails

guardrails = Guardrails.from_config(config_document)
result = guardrails.check(response)
if result["outcome"] in {"retry", "step_blocked"}:
    messages.append({"role": "user", "content": result.get("nudge_text", "Try again")})
elif result["outcome"] == "fatal":
    raise RuntimeError("guardrail retry limit reached")
else:
    for call in result["tool_calls"]:
        policy.require_allowed(call["tool"], call["args"])
        tool_result = execute(call)
        if tool_result.is_error:
            recorded = guardrails.record({"tool": call["tool"], "category": "unknown"})
            if "nudge_text" in recorded:
                messages.append({"role": "user", "content": recorded["nudge_text"]})
        else:
            guardrails.record({"tool": call["tool"], "args": call["args"]})

Migrating from pedro_agentware

The import package used to be pedro_agentware. It still works as a deprecated alias: import pedro_agentware.kei.evaluator gives you the same module object as haikeilabs.agentware.kei.evaluator, and emits a DeprecationWarning. Replace pedro_agentware with haikeilabs.agentware in your imports; the alias will be removed in a future release.

Documentation

MCP route client

Use haikeilabs.agentware.kei.mcproute.Client to call a connector through the local kei-proxy MCP route. It supports tools/list and tools/call over the configured Unix socket or loopback TCP listener:

from haikeilabs.agentware.kei.mcproute import Client

client = Client("github-connector")
tools = client.list_tools()
result = client.call_tool("get_issue", {"id": "42"})

KEI_MCP_ROUTE_KEY is read from the environment per request and is never cached or logged. Non-loopback hosts are rejected; provider traffic stays in the tenant runtime.

License

Apache-2.0. See LICENSE.

Metadata

Release files for haikeilabs-agentware 0.17.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for haikeilabs-agentware 0.17.0
File Size Uploaded Provenance Actions
haikeilabs_agentware-0.17.0.tar.gz 228.5 kB With provenance Details for haikeilabs_agentware-0.17.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for haikeilabs-agentware 0.17.0
File Interpreter ABI Platform Actions
haikeilabs_agentware-0.17.0-py3-none-any.whl Python 3 none any Details for haikeilabs_agentware-0.17.0-py3-none-any.whl

Total release size: 362.4 kB

Release files / haikeilabs_agentware-0.17.0.tar.gz

Download URL haikeilabs_agentware-0.17.0.tar.gz
Size 228.5 kB
Tags Source
SHA-256 checksum
How to use checksums
19ca9e9b0addb27d776b8b09efb28761a09b590cf6b8746c6bc2023c613c5bb6
BLAKE2b-256 checksum
How to use checksums
f49ae1a9c3ec629a1e66aeb0f18f03457d7f9abf1f4d09f2212ab1729658fc3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Release files / haikeilabs_agentware-0.17.0-py3-none-any.whl

Download URL haikeilabs_agentware-0.17.0-py3-none-any.whl
Size 133.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a270b73d07c02234f65db37aef49e09f018676b0514806f8724411441effca3
BLAKE2b-256 checksum
How to use checksums
7479e7432890df7bd32d13f7492e4a5fc28417beb6773bbb3db10f05da888552
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

Security for haikeilabs-agentware 0.17.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for haikeilabs_agentware-0.17.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page