Skip to main content

Minimal, streaming-first, protocol-driven foundation for LLM-powered agents

Project description

axio

PyPI Python License: MIT

Minimal, streaming-first, protocol-driven foundation for LLM-powered agents.

One dependency (pydantic). Three protocols. An agent loop that just works.

Features

  • Streaming agent looprun_stream() yields typed events as they arrive; no buffering, no polling
  • Three clean protocolsCompletionTransport, ContextStore, PermissionGuard; swap any piece without touching the rest
  • Concurrent tool dispatch — all tool calls in a turn run via asyncio.gather automatically
  • Context compactioncompact_context() summarises old history to stay within token limits
  • Testing helpersStubTransport, make_tool_use_response(), make_echo_tool() ship in axio.testing
  • Plugin-ready — entry-point groups (axio.tools, axio.transport, axio.guards) for drop-in extensions

Installation

pip install axio

Quick start

import asyncio
from axio.agent import Agent
from axio.context import MemoryContextStore
from axio.tool import Tool, ToolHandler

# 1. Define a tool
class Greet(ToolHandler):
    """Return a greeting for the given name."""
    name: str

    async def __call__(self) -> str:
        return f"Hello, {self.name}!"

greet_tool = Tool(name="greet", description="Greet someone by name", handler=Greet)

# 2. Wire up the agent (transport comes from an axio-transport-* package)
from axio_transport_openai import OpenAITransport

transport = OpenAITransport(api_key="sk-...", model="gpt-4o-mini")
agent = Agent(system="You are helpful.", transport=transport, tools=[greet_tool])

# 3. Run
async def main() -> None:
    ctx = MemoryContextStore()
    async for event in agent.run_stream("Please greet Alice", ctx):
        print(event)

asyncio.run(main())

Architecture

  User message
       │
       ▼
  ┌─────────┐   stream()    ┌─────────────────────┐
  │  Agent  │ ────────────▶ │ CompletionTransport  │
  │  loop   │ ◀──────────── │ (Anthropic, OpenAI, …) │
  └─────────┘  StreamEvent  └─────────────────────┘
       │
       │ tool_use?
       ▼
  ┌──────────┐   check()   ┌─────────────────┐
  │   Tool   │ ──────────▶ │ PermissionGuard │
  │ handler  │             │ (path, LLM, …)  │
  └──────────┘             └─────────────────┘
       │
       ▼
  ┌──────────────┐
  │ ContextStore │  append() / get_history() / fork() / compact()
  └──────────────┘

Protocols

CompletionTransport

from typing import Protocol, runtime_checkable
from collections.abc import AsyncIterator
from axio.events import StreamEvent
from axio.messages import Message
from axio.tool import Tool

@runtime_checkable
class CompletionTransport(Protocol):
    def stream(
        self, messages: list[Message], tools: list[Tool], system: str
    ) -> AsyncIterator[StreamEvent]: ...

ContextStore

from axio.context import ContextStore
from axio.messages import Message

class MyContextStore(ContextStore):
    def __init__(self) -> None:
        self._messages: list[Message] = []

    async def append(self, message: Message) -> None:
        self._messages.append(message)

    async def get_history(self) -> list[Message]:
        return list(self._messages)

    # Everything else — session_id, close(), fork(), clear(),
    # get/set_context_tokens(), add_context_tokens(), list_sessions()
    # — has a default implementation.

PermissionGuard

PermissionGuard is an abstract base class (ABC). Subclass it and implement check():

from typing import Any
from axio.permission import PermissionGuard

class MyGuard(PermissionGuard):
    async def check(self, handler: Any) -> Any:
        # return handler to allow, raise GuardError to deny
        return handler

Stream events

Event Description
TextDelta Incremental assistant text chunk
ToolUseStart Tool call begins (name + id)
ToolInputDelta Streaming JSON fragment for tool arguments
ToolResult Tool execution result
IterationEnd One LLM round complete — carries Usage + StopReason
Error Transport or tool exception
SessionEndEvent Agent loop finished — carries total Usage

Tools

from axio.tool import Tool, ToolHandler

class Summarise(ToolHandler):
    """Summarise the given text in one sentence."""
    text: str
    max_words: int = 20

    async def __call__(self) -> str:
        # your implementation
        return "..."

tool = Tool(
    name="summarise",
    description="Summarise text",   # overrides docstring if set
    handler=Summarise,
    concurrency=4,                   # max parallel executions
)

Testing

from axio.agent import Agent
from axio.testing import (
    StubTransport,
    make_tool_use_response,
    make_text_response,
    make_ephemeral_context,
    make_echo_tool,
)

async def test_agent_calls_tool():
    transport = StubTransport([
        make_tool_use_response("echo", tool_input={"msg": "hi"}),
        make_text_response("Done"),
    ])
    agent = Agent(system="", tools=[make_echo_tool()], transport=transport)
    result = await agent.run("say hi", make_ephemeral_context())
    assert result == "Done"

Plugin entry points

[project.entry-points."axio.tools"]
my_tool = "my_package:MyHandler"

[project.entry-points."axio.transport"]
my_backend = "my_package:MyTransport"

[project.entry-points."axio.guards"]
my_guard = "my_package:MyGuard"

Ecosystem

Package Purpose
axio-transport-anthropic Anthropic Claude transport
axio-transport-openai OpenAI-compatible transport (OpenAI, Nebius, OpenRouter, custom)
axio-transport-codex ChatGPT OAuth transport
axio-context-sqlite SQLite-backed persistent context store
axio-tools-local Shell, file, Python tools
axio-tools-mcp MCP server bridge
axio-tools-docker Docker sandbox tools
axio-tui Textual TUI application
axio-tui-guards Permission guard plugins

License

MIT

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

axio-0.6.2.tar.gz (61.2 kB view details)

Uploaded Source

Built Distribution

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

axio-0.6.2-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file axio-0.6.2.tar.gz.

File metadata

  • Download URL: axio-0.6.2.tar.gz
  • Upload date:
  • Size: 61.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for axio-0.6.2.tar.gz
Algorithm Hash digest
SHA256 3b6ec97c917e00b171719304a91eb806cd73c498e1c7ccc35309b90661454486
MD5 f67c46cbc263f86225bd3ebd990bbad9
BLAKE2b-256 03f87611f5f2fefe09bcb3e48cdbd3d10cba9e6f2ec7ab43426d5b163e38831c

See more details on using hashes here.

Provenance

The following attestation bundles were made for axio-0.6.2.tar.gz:

Publisher: publish.yml on axio-agent/monorepo

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

File details

Details for the file axio-0.6.2-py3-none-any.whl.

File metadata

  • Download URL: axio-0.6.2-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for axio-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 09b984e39c1e9496e6a37cd7177763702457f4f295e2db553f1b0722217ece53
MD5 61320453b04c54399ab68a1eadd5a0bf
BLAKE2b-256 c2fdd5c3bb5e230cfec0ce911de8911e416a9b7886fcf06f8b0ea1d6f972b7ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for axio-0.6.2-py3-none-any.whl:

Publisher: publish.yml on axio-agent/monorepo

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