Using the Python SDK
Use AbtRunner when you want the same behavior as the CLI from Python (tests, jobs, notebooks):
from abt import AbtRunner
runner = AbtRunner(project_root="/path/to/project")
assert runner.invoke(["compile"]).success
res = runner.invoke(["run", "-s", "my-agent", "-p", "Hi"]) # my-agent: any agent in the project; calls the model
assert res.success
invoke never raises for a bad invocation: it returns a result with success=False and the error in res.exception.
- Async:
await runner.ainvoke([...])when a loop is already running. - Dry run:
runner.invoke([...], dry_run=True)is the SDK form of--dry-run. It is accepted forrunandtest. For any other command, such ascompile, the result hassuccess=Falseand aValueErrorinres.exception. - Manifest cache: pass
manifest=intoAbtRunnerto skip recompile. .envfiles:AbtRunner(project_root=..., load_dot_env=True)(orload_dot_env=Trueon anyabt.sdkoperation such assdk.run) loads the nearest.envinproject_rootor its ancestors before the project is resolved — independent of the process's current working directory. Real environment variables always win. See Environment variables — Secret interpolation.
Generate files from a prompt
sdk.create(...) is the programmatic equivalent of abt create -p "..." — see the CLI reference for behavior and flags.
from abt import sdk
result = await sdk.create("/path/to/project", "read a Slack thread and post a summary to Confluence")
print(result.written) # list[Path]
# Agent only, no test suite — same as --no-test.
await sdk.create("/path/to/project", "a customer-support triage agent", skip_dirs=frozenset({"tests"}))
Watch mode
Run the event-driven watcher (programmatic abt watch run) from Python. Same features as the CLI — entrypoint selectors, tags, concurrency/cooldown, reconcile interval, health port, graceful shutdown — minus the process-level concerns (signal handlers, console logging) that belong to your application:
import asyncio
from abt import sdk
# Fire-and-forget: blocks until the task is cancelled.
asyncio.run(sdk.watch("/path/to/project", watch_all=True))
For control over stop() / health, build the runner and drive it yourself:
runner = sdk.build_watch_runner(
"/path/to/project",
entrypoint_selectors=["investigator"],
tags=["team:infra"],
health_port=8080,
)
task = asyncio.create_task(runner.run())
# ... later ...
await runner.stop() # signal graceful shutdown; drains in-flight dispatches
await task
Both activate the project profile first (publishing env: to os.environ) so MCP env_var(...) calls resolve during reconcile compiles. Pass publish_profile_env=False for process isolation.
Distributed watch mode
sdk.triggerer / sdk.worker are the programmatic counterparts of abt watch produce / abt watch consume (see Deploying to Kubernetes): the trigger plane publishes normalized dispatch requests to a Redis Streams queue instead of running them in-process, and any number of workers compete for jobs off that queue. Same shape as watch/build_watch_runner above — a fire-and-forget coroutine, or a build_*_runner for explicit stop()/health control:
import asyncio
from abt import sdk
# Trigger plane: owns event sources, safe with replicas > 1 (Redis-backed leader election).
# Execution plane: pure competing consumer, run as many as you want against the same queue.
asyncio.run(sdk.triggerer("/path/to/project", "redis://localhost:6379", watch_all=True))
asyncio.run(sdk.worker("/path/to/project", "redis://localhost:6379"))
runner = sdk.build_triggerer_runner(
"/path/to/project",
"redis://localhost:6379",
entrypoint_selectors=["investigator"],
lease_seconds=15.0,
health_port=8801,
)
task = asyncio.create_task(runner.run())
# ... later ...
await runner.stop()
await task
queue falls back to the ABT_WATCH_QUEUE env var, matching the CLI's --queue. Requires the queue extra: uv pip install "abt-core[queue]".
To let other services run an access: public agent over HTTP, add the agent invoke API to a worker: sdk.build_worker_runner(..., health_port=8080, invoke_api=InvokeApiConfig(token=...)). Import InvokeApiConfig from abt.sdk.watch.
Full API, RunResult, and parity table: Python SDK reference. Profiles without disk: Inline profiles.