Skip to main content

aihi-agent

[English] | 简体中文

Provider-neutral, recoverable agent runtime for AIHI.

aihi-agent turns model contracts into a durable execution system. It provides the loop, sessions, tools, policy, approvals, sandbox boundary, context management, integrations, and observability that an application can compose for a specific product.

Responsibilities

  • Run bounded model/tool turns with explicit runtime composition.
  • Persist an append-only event log and recover sessions after interruption.
  • Compile context and compact it into derived summaries without rewriting history.
  • Register and execute tools through policy, approvals, hooks, and a sandbox backend.
  • Integrate Skills, MCP servers, subagents, memory, artifacts, telemetry, replay, and evaluations.

The package does not select a provider, implement a UI, provide a model router/gateway, or hide tool defaults. Applications pass those choices to RuntimeBuilder.

Architecture

Model Provider (aihi-models)
              │
              ▼
RuntimeBuilder ──► Runtime / RunCoordinator ──► EventStore
              │                  │
              │                  ├── ContextCompiler / Compaction
              │                  ├── ToolRegistry ──► Policy ──► Approval
              │                  │                         │
              │                  │                         ▼
              │                  └── Hooks ──► SandboxBackend ──► Tool
              │
              └── Skills / MCP / Subagents / Memory / Artifacts / Telemetry

The event store is the source of truth. Tool calls are recorded before execution and have exactly one result. An approval decision of ASK suspends the run so it can be resumed later.

Installation

From the workspace:

uv sync

For a local editable install:

uv pip install -e packages/aihi/agent

aihi-agent requires Python 3.11+ and depends on aihi-models 0.1.x.

Minimal runtime

from pathlib import Path

from aihi.agent import HostBackend, InMemoryEventStore, ReadFileTool, RuntimeBuilder, Session
from aihi.models import FakeProvider, FakeStep, Message

provider = FakeProvider([FakeStep(text="I inspected the workspace.")])
runtime = (
    RuntimeBuilder(
        provider=provider,
        model="fake-model",
        sandbox=HostBackend(Path.cwd(), unsafe=True),
        tools=[ReadFileTool()],
    )
    .with_max_turns(20)
    .build()
)

session = Session.create(
    InMemoryEventStore(),
    cwd=Path.cwd(),
    provider="fake",
    model="fake-model",
)

result = await runtime.coordinator.run(
    session,
    model=runtime.model,
    user_message=Message.text("user", "Inspect this project."),
)
print(result.state)

For real applications, prefer an isolated backend when available. HostBackend is a controlled local execution backend, not a security isolation boundary, and requires an explicit unsafe=True acknowledgement.

Runtime composition

RuntimeBuilder requires the important dependencies up front:

  • provider and model;
  • a sandbox backend;
  • the application-approved tools collection.

Optional extensions are added explicitly with methods such as:

  • .with_max_turns(...) and .with_context_window(...);
  • .with_policy(...), .with_approvals(...), and .with_hooks(...);
  • .with_skills(...), .with_memory(...), .with_compaction(...);
  • .with_subagents(...), .with_artifacts(...), and .with_telemetry(...).

The default coordinator turn budget is finite (100) and can be lowered for a product-specific safety envelope.

Core modules

Area Main API
Runtime and runs Runtime, RuntimeBuilder, RunCoordinator, RunResult, RunState
Sessions and storage Session, EventStore, InMemoryEventStore, SQLiteEventStore, Event
Context ContextCompiler, summaries, compaction generators
Tools Tool, ToolSpec, ToolContext, ToolRegistry, built-in file/shell tools
Policy and approval PermissionMode, DefaultPolicyEngine, Approval, approval resolvers
Sandbox HostBackend, LocalIsolatedBackend, DockerBackend
Integrations Skills, MCP, plugins, subagents, memory, artifacts
Observability Telemetry, JsonlTelemetrySink, InMemoryTelemetrySink
Verification replay, golden tasks, evals, and contract helpers

Tool and approval model

Tools are registered with explicit ToolSpec metadata. The policy engine decides whether an invocation is allowed, denied, or must ask for approval. Approval leases can scope a decision to a request, a tool, or a run according to the application policy.

Use the built-in tools only with a sandbox and policy appropriate for the workspace. File reads, glob/grep, edits, writes, and shell execution should not be treated as interchangeable capabilities.

Observability

Telemetry is an observation stream, not the event log. JsonlTelemetrySink emits redacted, bounded records and creates owner-only files by default. Use the event store for recovery and audit the telemetry stream for operational diagnosis; do not use UI output as a source of truth.

Development

uv run pytest packages/aihi/agent/tests
uv run ruff check packages/aihi/agent
uv run mypy
uv run python -m build --wheel --no-isolation packages/aihi/agent

See the repository architecture guide and the code-agent README for an application-level composition.

Security model

  • Keep credentials in the application/provider boundary, never in prompts or event payloads.
  • Treat model output, tool arguments, Skills, MCP responses, and subagent output as untrusted.
  • Do not claim that HostBackend isolates a process; use LocalIsolatedBackend or DockerBackend when isolation is required.
  • Set a finite turn limit and review approval/policy defaults before exposing tools to a model.

Download files

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

Source Distribution

aihi_agent-0.1.0.tar.gz (192.9 kB view details)

Uploaded Source

Built Distribution

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

aihi_agent-0.1.0-py3-none-any.whl (185.0 kB view details)

Uploaded Python 3

File details

Details for the file aihi_agent-0.1.0.tar.gz.

File metadata

  • Download URL: aihi_agent-0.1.0.tar.gz
  • Upload date:
  • Size: 192.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for aihi_agent-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0e459dc6b945c5c5c1d86e1d63bb89211569363f9b9c2e6feb87c839e59e0078
MD5 35d07acc77c7fb06688f50ac99fc58a4
BLAKE2b-256 cf28eeb2c1135757973ffc551072bc9950633ef36b0280e769c09136f737d9a5

See more details on using hashes here.

File details

Details for the file aihi_agent-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: aihi_agent-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 185.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for aihi_agent-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 167a68d271bf213bca0bf261f2f9cba1faa0ad26483a2280dba193bfa89ae420
MD5 f900b0db5a140c91e2558b53df4732f4
BLAKE2b-256 cc238c92d0998ecd09893e8efceaa9b546772330c991a21e8d2aa0d3de06af1e

See more details on using hashes here.

Supported by

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