Skip to main content

Agnara

Capability-native Python for the agentic era.

Agnara is a Python 3.14-native capability framework for services meant to be consumed by humans, applications and AI agents without making HTTP the centre of the architecture. A capability is declared once, with its effects, risk and confirmation requirements, and later exposed through whichever protocol the caller needs.

This distribution is agnara, the capability-first, transport-neutral execution kernel: the capability model, registry, execution context, dependency graph, policies, execution planning and canonical errors. It depends on nothing but the standard library.

Stable 1.x kernel

This 1.0.3 distribution follows Agnara's stable 1.x public API contract. The source tree prepares the package; consult PyPI for publication status. The kernel remains standard-library-only. HTTP, MCP, CLI and telemetry live in separate, synchronized distributions; the A2A and events packages currently reserve namespaces without runtime APIs.

Install

pip install agnara

For reproducible installations, pin the synchronized version:

pip install "agnara==1.0.3"

Requires CPython 3.14 or newer.

Quick start

import asyncio

from agnara import Agnara, Principal, Risk, StandardEffect
from agnara.di import DIContainer, DIRegistry
from agnara.execution import (
    ExecutionContext,
    ExecutionPlan,
    Invocation,
    invoke_result,
)

app = Agnara("billing")


@app.capability(
    description="Refund a captured payment.",
    scopes=("billing:write",),
    effects=(StandardEffect.FINANCIAL_WRITE,),
    risk=Risk.HIGH,
)
def refund(payment_id: str, amount_cents: int) -> str:
    return f"refunded {amount_cents} cents for {payment_id}"


async def main() -> None:
    capabilities = app.compile()
    dependencies = DIRegistry()
    plan = ExecutionPlan.compile(capabilities["billing.refund"], dependencies)

    container = DIContainer(dependencies)
    try:
        outcome = await invoke_result(
            plan,
            ExecutionContext(
                Invocation(
                    capability_id=plan.definition.id,
                    payload={"payment_id": "pay_123", "amount_cents": 2500},
                    metadata={},
                ),
                container,
                principal=Principal("quickstart", scopes={"billing:write"}),
            ),
        )
        print(outcome)
    finally:
        await container.aclose()


asyncio.run(main())

The declared function is returned unchanged, so it stays directly callable and directly testable. Registration is a side effect on the application, not a transformation of the function.

Kernel capabilities

  • capability declaration and a deterministic, freezable registry;
  • stable capability identity, plus effect, risk, idempotency and confirmation metadata;
  • a schema port with a standard-library adapter and compiled per-parameter input validation; see the runnable schema contracts guide;
  • dependency injection with compile-time graph validation and scoped resolution; see the runnable dependency lifecycle guide;
  • execution plans, direct invocation and optional monotonic deadlines; see the runnable deadline and cancellation guide;
  • protocol-neutral policies, principals and scope evaluation;
  • canonical Success / Failure outcomes with stable failure codes;
  • protocol-neutral introspection snapshots and explicit discovery visibility; see the runnable filtering guide;
  • structured execution telemetry hooks with per-invocation identity; see the runnable telemetry guide.

What it does not include

The HTTP/ASGI, OpenAPI, MCP, CLI and OpenTelemetry functionality lives in separate distributions -- agnara-http, agnara-mcp, agnara-cli and agnara-telemetry -- and is not bundled into this standard-library-only kernel. Each is versioned in step with this one; check its PyPI project page for the versions available to install. Events remains a zero-API reserved namespace. The published 1.0.3 A2A wheel also has no runtime API; this checkout adds an unreleased, experimental projection with provisional exports in agnara-a2a. See the A2A guide for its exact evidence and limits before using that separate adapter.

Frozen value semantics

Core value types such as CapabilityId and CapabilityDefinition are immutable and slotted. Assigning or deleting either a declared field or an unknown attribute raises dataclasses.FrozenInstanceError; a typo never attaches new state and does not leak CPython's internal slots error.

Confirmation boundary

Capabilities declared with confirmation="required" need an application-provided ConfirmationVerifier when their ExecutionPlan is compiled. Each invocation may carry an explicit opaque ConfirmationEvidence on ExecutionContext; values in generic invocation metadata are not approval.

The verifier receives the exact capability id, invocation, and principal and owns authenticity, input canonicalization, expiry, and replay protection. Missing evidence terminates execution with an interaction request. Rejected evidence terminates it as forbidden. Both outcomes occur before dependency construction or handler effects, and invoke_result() maps them to stable protocol-neutral failure codes.

Telemetry hooks

The core port is agnara.execution.TelemetryHook, with synchronous on_invocation_start(InvocationStartEvent) and on_invocation_terminal(InvocationTerminalEvent) callbacks. Register observers with ExecutionPlan.compile(definition, registry, hooks=[observer]); inheriting from the protocol is optional. Events expose capability, invocation and tracking identity; terminal events also contain monotonic duration and execution outcome, without handler inputs, returned payloads or exception objects.

Both plan construction paths copy the hook collection to a tuple. Missing or non-callable callbacks, coroutine functions and generator functions fail at startup with DefinitionError. Valid callbacks accept one event, return None synchronously and must not block. Their ordinary exceptions are ignored during execution.

Observers own synchronization of their mutable state and must keep their callbacks stable after compilation. Tracking IDs are caller-provided and may repeat; they are not unique span identifiers and should contain no secrets. Exporter startup, flushing and shutdown belong to adapters, not the core runtime. The separate agnara-telemetry package provides metrics and tracing hooks over an application-supplied meter and tracer.

Identity: code constructing InvocationStartEvent or InvocationTerminalEvent supplies invocation_id. Use the same identity for matching start and terminal events; tracking_id is not unique. Hooks that only read events are unaffected, and plans without hooks skip event construction entirely.

License

Apache License 2.0.

Metadata

Release files for agnara 1.0.4

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

Source distribution (sdist)

Source distribution for agnara 1.0.4
File Size Uploaded Provenance Actions
agnara-1.0.4.tar.gz 80.0 kB With provenance Details for agnara-1.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for agnara 1.0.4
File Interpreter ABI Platform Actions
agnara-1.0.4-py3-none-any.whl Python 3 none any Details for agnara-1.0.4-py3-none-any.whl

Total release size: 187.5 kB

Release files / agnara-1.0.4.tar.gz

Download URL agnara-1.0.4.tar.gz
Size 80.0 kB
Tags Source
SHA-256 checksum
How to use checksums
aadca6cb6cdeb013e72eb5ebb01a86e833b33da84e94648030bc0dde259e1185
BLAKE2b-256 checksum
How to use checksums
e074a91ca46cdb769e7be0b3cddc5d405b193edb3b2d6efd08efd3f291352138
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 / agnara-1.0.4-py3-none-any.whl

Download URL agnara-1.0.4-py3-none-any.whl
Size 107.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b4cd1b864b80a163096b432b6e9142541e410c52c56515d7ebb00bbdfebf6f8b
BLAKE2b-256 checksum
How to use checksums
4a1179514628859e9378dbd987e31c975a3f672f134bec2d6561b6f9070be6c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 agnara 1.0.4

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 agnara-1.0.4.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