Skip to main content

AgentM SDK Core

This worktree is the reduced AgentM SDK core. It keeps the substrate small: session lifecycle, trajectory persistence, extension loading, provider streams, tool execution, operations ports, and observability hooks. CLI, gateway peers, contrib scenarios, catalog machinery, and product-specific policies are outside this branch until the core abstraction is stable.

Core Abstraction

The SDK is mechanism, not policy. Policy enters through atoms.

Layer Responsibility
AgentSession Public session handle: create, run, prompt, interrupt, spawn, fork, resume, shutdown.
Driver Persistent async loop: consume triggers, call the provider, execute tools, commit turns.
Trigger Unified input shape for user input, background completion, monitor fire, subagent result, continuation, and injection.
TriggerEnvelope Queue/routing metadata around a trigger: priority (now/next/later), target identity, origin, mode, and presenter/system flags.
PromptRun Lifecycle of one accepted external trigger. Its receipt stays open across model/tool continuations, while run_id and run_step group the resulting turns.
MessageMeta Control-plane metadata for synthetic messages, hidden attachments, no-response prompts, replay policy, token accounting, origin, mode, and target identity.
Turn Durable transaction unit: exactly one assistant response, all tool results requested by that response, outcome, timing, and usage.
TrajectoryStore The single replaceable persistence boundary for session metadata, incomplete checkpoints, committed turns, message-node indexes, heads, and cache/compaction state.
TrajectoryNode A committed message or compact-boundary index record used for fork, resume, sidechains, compaction, and prompt-cache lookup. Content replacement is state attached atomically to a compact boundary, not another node kind.
ContextPolicy Replaceable context reconstruction policy. Durable compaction and cache decisions use ContentReplacementState and PromptCacheState in the selected TrajectoryStore, so they survive resume/fork without a second policy-owned store.
EventBus Immutable event dispatch surface for observation and policy hooks.
AtomAPI The only surface atoms receive at install time.
CancelSignal Cooperative cancellation boundary shared by provider streams, tools, operations, and optionally foreground child sessions. Its typed reason carries causes such as user cancel, submit interrupt, shutdown, or task stop.
BackgroundTaskRegistry Shared helper for atom-owned detached work: task handles, slot caps, and cooperative cancel.
StreamFn / ProviderConfig Replaceable LLM provider boundary.
ProviderResolver Replaceable active-provider selection policy.
ToolExecutor Replaceable tool execution boundary. Tool requirements declare isolation, filesystem/network access, concurrency, and interrupt behavior; executor capabilities declare what the backend can honor.
ToolOrchestrator Replaceable batch scheduler for tool calls: exclusive vs parallel-safe partitioning, sibling-error cascading, and cooperative cancellation.
PermissionPolicy Replaceable async permission boundary. It returns a final allow or deny; policies that require user interaction await it internally instead of exposing a deferred runtime state.
BashOperations / ResourceWriter Replaceable external-world ports for execution and resource mutation.

Extension Contract

An atom is a Python module with:

from agentm.extensions import ExtensionManifest

MANIFEST = ExtensionManifest(
    name="my_atom",
    description="What this atom contributes.",
    registers=("tool:my_tool",),
    requires=(),
)

def install(api, config):
    ...

Atoms may depend on agentm.core.abi, agentm.core.lib, and the public agentm.extensions surface. The load-time validator rejects imports from agentm.core.runtime and agentm.core._internal; atoms must reach stateful runtime subsystems through AtomAPI methods and services.

Session Creation

The public path is AgentSession.create(AgentSessionConfig(...)).

from pathlib import Path

from agentm import AgentSession, AgentSessionConfig, LoopConfig, builtin_scenario_loader
from agentm.storage.trajectory import JsonlTrajectoryStore

session = await AgentSession.create(AgentSessionConfig(
    cwd=".",
    scenario="minimal",
    scenario_loader=builtin_scenario_loader,
    provider=("agentm.extensions.builtin.llm_openai", {"model": "gpt-4o"}),
    trajectory_store=JsonlTrajectoryStore(Path(".agentm/trajectory")),
    loop_config=LoopConfig(max_turns=8, max_tool_calls=32),
    tool_allowlist=["read", "bash"],
))

messages = await session.run("summarize src/agentm/core/abi")
await session.shutdown()

Use extensions=[...] to bypass scenario lookup entirely. The core runtime has no built-in scenario registry; pass builtin_scenario_loader to opt into the packaged scenario names in this reduced worktree:

Scenario Meaning
empty No atoms; host code must provide provider/tools directly.
minimal Observability, local bash operations, retry policy, result caps, file tools, bash tool, and system prompt atom.

Hosts that need named scenarios beyond these should pass AgentSessionConfig.scenario_loader.

pip install agentm is enough to run any atom this package ships, providers and observability included. The only extras are storage backends and the Harbor adapter, which a deployment opts into by naming one: agentm[storage-postgres], agentm[storage-clickhouse], agentm[harbor].

Persistence

TrajectoryStore owns durable session metadata, the current incomplete Turn checkpoint, committed turns, message nodes, explicit heads, and cache/compaction state. Every model/tool continuation commits a separate Turn with its own resource/effect transaction; all Turns produced by one external trigger share a run_id and increasing run_step. A committed Turn and its node/head indexes share one atomic publication boundary. Root metadata is created automatically before the session starts; child and forked sessions register their own metadata through the session graph path. SessionMeta.config persists the minimal resumable context (root_session_id, depth, scenario, and scenario_dir) so a child or fork can be loaded in a later process without losing its lineage.

AgentSessionConfig(trajectory_store=None) lets the SDK host resolver select the configured/default backend. Low-level core factories remain explicitly ephemeral when no store is supplied. Host programs that need resume or trace queries must select one store. Provider requests that fail after retries are persisted as non-replayable ProviderRequestFailed turns before the trigger receipt raises, so failed sessions do not collapse to an empty session header.

Built-in stores:

Store Use
InMemoryTrajectoryStore Tests and ephemeral embedding.
JsonlTrajectoryStore Local append-only persistence, one JSONL file per session.
PostgresTrajectoryStore Durable transactional session, turn, node/head, and policy-state persistence.

SQL-backed adapters are opened through the shared SQLAlchemy entry point in agentm.storage.sql; PostgreSQL and ClickHouse still require their optional driver extras.

The same TrajectoryStore exposes committed message-tree queries with stable node ids and portable index fields:

Field group Fields Purpose
Identity id, session_id, root_session_id, parent_session_id, seq Stable lookup, per-session append order, and trace-scope scans.
Links parent_id, logical_parent_id Visible chain reconstruction, fork prefix sharing, and compact-boundary lineage.
Ownership agent_id, is_sidechain Subagent sidechains and agent-specific resume.
Turn join turn_id, turn_index, run_id, run_step, message_index Join message nodes back to committed Turns and group them by PromptRun.
Shape kind, role, timestamp Distinguish committed message and compact-boundary nodes, then filter message roles such as user, assistant, and tool result. Incomplete checkpoints are turn-level records outside the committed node graph.

SQL stores implement these as normal indexed columns. JSONL stores replay the same per-session journal; they do not maintain a separately recoverable sidecar truth. ClickHouse is an optional OTLP observability backend, not a trajectory store. The SDK relies on the Protocol semantics, not on a JSONL layout.

Verification

uv sync
uv run ruff check src/ tests/
uv run mypy src/
uv run pytest --tb=short

Keep project-index.yaml synchronized with every code and test change, then validate it with:

python3 ${CLAUDE_PLUGIN_ROOT}/scripts/validate_index.py project-index.yaml

Download files

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

Source Distribution

agentm-0.2.5.tar.gz (473.8 kB view details)

Uploaded Source

Built Distribution

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

agentm-0.2.5-py3-none-any.whl (563.0 kB view details)

Uploaded Python 3

File details

Details for the file agentm-0.2.5.tar.gz.

File metadata

  • Download URL: agentm-0.2.5.tar.gz
  • Upload date:
  • Size: 473.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for agentm-0.2.5.tar.gz
Algorithm Hash digest
SHA256 c8ad277873b17ee25c70bd677db7a38f7e033b79d1d140903544d3b7edb7b5ca
MD5 4cfe1d6f7a51b9a31251362f8c4f0a33
BLAKE2b-256 582f2d77bb5c43d40ce1ed194d29968003ee258f5e619e15e1d87f68df0a7c16

See more details on using hashes here.

File details

Details for the file agentm-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: agentm-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 563.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for agentm-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c5bb93edf86c74ee5b5af80b9996e3be7df1818c67d273bf5e03af1f32207ce3
MD5 8dcc2b30ea3adf422a0de780c2c726d6
BLAKE2b-256 18ebcbc54989c138d0334fadf3b4a8fe9e9cfc2f240f62d9b8074b357d20db4b

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.7

2 files

0.2.6

2 files

This release

0.2.5 This release

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.1

2 files

0.1.0

2 files

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