A3S Code - Native Python bindings for the coding-agent runtime
Project description
A3S Code — Python SDK
Native Python bindings for the A3S Code AI coding agent, built with PyO3.
Installation
pip install a3s-code
Quick Start
from a3s_code import Agent
agent = Agent.create("agent.acl")
session = agent.session("/my-project")
result = session.send({"prompt": "What files handle authentication?"})
print(result.text)
Slash Commands
Every session includes built-in slash commands dispatched before the LLM:
# List all available commands
commands = session.list_commands()
for cmd in commands:
print(f"/{cmd['name']:15s} {cmd['description']}")
# Built-in commands
result = session.send("/help") # List all commands
result = session.send("/model") # Show current model
result = session.send("/cost") # Token usage and cost
result = session.send("/history") # Conversation stats
Custom Commands
def my_handler(args: str, ctx: dict) -> str:
return f"Model: {ctx['model']}, History: {ctx['history_len']} msgs, args: {args!r}"
session.register_command("status", "Show session info", my_handler)
result = session.send("/status hello")
Full API
from a3s_code import (
Agent,
ConfirmationPolicy,
PermissionPolicy,
SessionOptions,
WorkerAgentSpec,
DefaultSecurityProvider,
FileMemoryStore,
FileSessionStore,
HttpTransport,
LocalWorkspaceBackend,
)
agent = Agent.create("agent.acl")
session = agent.session("/my-project",
model="openai/gpt-4o",
builtin_skills=True,
planning_mode="auto", # "enabled" forces planning, "disabled" turns it off
)
# Send / Stream
result = session.send({"prompt": "Explain the auth module"})
for event in session.stream({"prompt": "Refactor auth"}):
if event.event_type == "text_delta":
print(event.text, end="", flush=True)
# Streams with no custom history update session history and verification evidence
# when the stream completes. Passing explicit history keeps the stream isolated.
# send(...) and stream(...) accept prompt strings or object-shaped requests
# with optional history and attachments.
# Planning events
# Prefer planning_mode="auto" | "enabled" | "disabled". The legacy planning
# bool still works: True forces planning, False disables it. In streaming mode,
# render task_updated as the current task list; step_start and step_end are
# per-step progress events.
# Run replay
runs = session.runs()
if runs:
print(runs[-1]["id"], runs[-1]["status"])
print(session.run_events(runs[-1]["id"]))
print(session.active_tools())
# Cancels only if that run is still active; stale IDs are ignored.
session.cancel_run(runs[-1]["id"])
# Direct tools (bypass LLM)
opts = SessionOptions()
opts.workspace_backend = LocalWorkspaceBackend("/my-project")
session = agent.session("/my-project", opts)
session.write_file("notes.txt", "one\ntwo\n")
session.read_file("src/main.py")
session.ls()
session.edit_file("notes.txt", "one", "uno")
session.patch_file("notes.txt", "@@ -1,2 +1,2 @@\n uno\n-two\n+dos")
session.bash("pytest")
session.glob("**/*.py")
session.grep("TODO")
session.tool_names()
session.tool_definitions()
# Programmatic Tool Calling (embedded QuickJS)
program = session.program({
"source": """
export default async function run(ctx, inputs) {
const hits = await ctx.grep(inputs.query, { glob: '*.py' });
const files = await ctx.glob('src/**/*.py');
return { hits, files: files.slice(0, 10) };
}
""",
"inputs": {"query": "PermissionPolicy"},
"allowed_tools": ["grep", "glob"],
"limits": {"timeoutMs": 30000, "maxToolCalls": 20, "maxOutputBytes": 65536},
})
print(program.output)
# Delegation helpers (wrappers around task / parallel_task)
session.task({
"agent": "explore",
"description": "Find auth entry points",
"prompt": "Inspect the repository and summarize the auth-related files.",
})
session.tasks([
{"agent": "explore", "description": "Find tests", "prompt": "Locate auth tests."},
{"agent": "verification", "description": "Check risk", "prompt": "Review auth edge cases."},
])
# Disposable worker agents (cattle mode)
opts = SessionOptions()
frontend = WorkerAgentSpec.implementer("frontend-cow", "Small verified frontend fixes")
frontend.model = "openai/gpt-4o"
frontend.max_steps = 24
frontend.prompt = "Keep patches focused and run the narrowest relevant check."
frontend.confirmation_inheritance = "auto_approve" # child runs auto-approve Ask decisions
opts.add_worker_agent(frontend)
session = agent.session("/my-project", opts)
session.task({
"agent": "frontend-cow",
"description": "Fix admin chat loading state",
"prompt": "Find and fix the loading-state regression, then summarize verification.",
})
# Confirmation inheritance controls how child runs resolve Ask decisions:
# - "auto_approve" (default): Child runs auto-approve all Ask decisions
# - "deny_on_ask": Child runs fail immediately when encountering an Ask
# - "inherit_parent": Child runs inherit the parent's confirmation policy
restricted = WorkerAgentSpec("restricted-writer", "Write files with parent confirmation", "implementer")
restricted.confirmation_inheritance = "inherit_parent" # requires parent approval
opts.add_worker_agent(restricted)
# Object-shaped direct tools
session.git({"command": "status"})
session.git({"command": "worktree", "subcommand": "list"})
# git_command(...) and positional git(...) remain for compatibility.
# Live registration and top-level worker sessions are also supported.
session.register_worker_agent(WorkerAgentSpec.verifier("verify-cow", "Run focused checks"))
worker_session = agent.session_for_worker(
"/my-project",
WorkerAgentSpec.reviewer("review-cow", "Adversarial code review"),
)
# AHP-supervised background advice
opts = SessionOptions()
opts.ahp_transport = HttpTransport("http://localhost:8080/ahp")
session = agent.session("/my-project", opts)
# The AHP harness owns background advice, context supplements, and PTC proposals.
# Proposed scripts should be run explicitly with session.program(...) if approved.
# Slash commands
session.list_commands()
session.register_command("ping", "Pong!", lambda args, ctx: "pong")
# Memory
session.remember_success("task", ["tool"], "result")
session.recall_similar("auth", 5)
# Hooks
session.register_hook("audit", "pre_tool_use", handler_fn)
# MCP
session.add_mcp({
"name": "github",
"transport": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
},
"timeout_ms": 30_000,
})
session.mcps()
session.tool_names()
session.remove_mcp("github")
# Persistence
opts = SessionOptions()
opts.session_store = FileSessionStore('./sessions')
opts.session_id = 'my-session'
opts.auto_save = True
session2 = agent.session(".", opts)
resumed = agent.resume_session('my-session', opts)
HITL Confirmations
Use PermissionPolicy to decide which tools ask, then ConfirmationPolicy to
control confirmation runtime behavior such as timeout and YOLO lanes. Invalid
permission decisions, timeout actions, and lane names are rejected when the
session is created so unsafe fallbacks do not silently change policy.
opts = SessionOptions()
opts.permission_policy = PermissionPolicy(ask=["bash*"], default_decision="allow")
opts.confirmation_policy = ConfirmationPolicy(
enabled=True,
default_timeout_ms=30_000,
timeout_action="reject",
yolo_lanes=["query"],
)
session = agent.session(".", opts)
for pending in session.pending_confirmations():
session.confirm_tool_use(pending["tool_id"], approved=True, reason="Reviewed")
For the streaming event-driven loop used by UIs, see
examples/hitl_confirmation_loop.py.
Delegation
Routine multi-agent work uses the model-visible task and parallel_task
tools. Use session.task(...) and session.tasks(...) for SDK-native calls,
or session.tool("task", {...}) when you need raw access.
The old standalone lifecycle control-plane API is intentionally removed from
the 2.0 SDK surface.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file a3s_code-2.6.0-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: a3s_code-2.6.0-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 15.1 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2bcb1d4bd9df0758154e3d6a434caa76f69133863fe901d41135739b146696f
|
|
| MD5 |
469b8c29084fac26bf60255beb6cfa5a
|
|
| BLAKE2b-256 |
7d35f9c3dc4b089732f03c7030a9981992c2e5c3153a9f5d8d8d920a19395821
|
File details
Details for the file a3s_code-2.6.0-cp313-cp313-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: a3s_code-2.6.0-cp313-cp313-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 17.1 MB
- Tags: CPython 3.13, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8746cc9763272ed8ba44b5c15a34c1b206bb1c8540b52a1ccc87ed46f130791c
|
|
| MD5 |
574e9cb79d1cd06806cd667ac2043111
|
|
| BLAKE2b-256 |
36bd40134c8221f21482b9a7ed5449f42dd1d6dc0b6fe373cb3054fa425f6608
|
File details
Details for the file a3s_code-2.6.0-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: a3s_code-2.6.0-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 15.1 MB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b9914c176f780d99f3093fb6c0d2d5c8fc92187787dcea7761c02e52cb2e9fa
|
|
| MD5 |
35ed6b18a5ccc1bdc67a8c5d2b82fe8f
|
|
| BLAKE2b-256 |
f05d3d7e36ef7be96e1f6efb07e30aeac279feaebd884f3a7a56d60509df92e3
|
File details
Details for the file a3s_code-2.6.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: a3s_code-2.6.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 15.1 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a03f30af503e740eb8dde5a0a305a0b11cf618dab7750f47dbc2864375a9d53
|
|
| MD5 |
ff39a1748651e63a771f5203982f1d58
|
|
| BLAKE2b-256 |
8a77e06eda96840ded85bcb9eed3747726ae2dabd6cdb9e7a2b1dfaf384e7bfc
|
File details
Details for the file a3s_code-2.6.0-cp312-cp312-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: a3s_code-2.6.0-cp312-cp312-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 17.1 MB
- Tags: CPython 3.12, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a4c49429e462ad871752891b792397e8ccc7cfa96c6fbbf96127d81268a590d
|
|
| MD5 |
ca099fe36fff044e1fd6a1f7ba065f91
|
|
| BLAKE2b-256 |
9e5f186b55ca6d9f6c9247446fcecee74168dc67ff346f7035bcc95a685f1c24
|
File details
Details for the file a3s_code-2.6.0-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: a3s_code-2.6.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 15.1 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9620b51ce6241e293b0efce9031c74c12a823668100f5a4604ec84f381a22e6
|
|
| MD5 |
3e4ff98c4f1239ed651d43009eecd888
|
|
| BLAKE2b-256 |
b94d5df6e9b0365b02a090de06efa6f5b63374b9129fa5fb8938eada36e5f4dd
|
File details
Details for the file a3s_code-2.6.0-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: a3s_code-2.6.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 15.1 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19e03f2426e0e81e5d5c95d7e11aa5874f6da32945f86ec64f0b81e591a4ca11
|
|
| MD5 |
6a24024198390fa5b0150135eedae8fd
|
|
| BLAKE2b-256 |
af349abeb861a4576e842742ea6de1e377c798345f7b24068d908b5eeac6dae5
|
File details
Details for the file a3s_code-2.6.0-cp311-cp311-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: a3s_code-2.6.0-cp311-cp311-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 17.1 MB
- Tags: CPython 3.11, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83967a075516e33dd38ce9054e1d72f980084f8b0c5f7e5ad879b48bfb6d0435
|
|
| MD5 |
197426327679fbbffb613aa1b04f58de
|
|
| BLAKE2b-256 |
d0e4fb058ef87e572ef93c20ce7655155027ef1948ae2d1230061565917bbdf4
|
File details
Details for the file a3s_code-2.6.0-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: a3s_code-2.6.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 15.1 MB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
119a49d2c03ba9b739f5d18b27754e41407813e8bf3bb3dfc5411ac8600bd3ee
|
|
| MD5 |
db07b9ebb467084295d9e0629c3a7bd7
|
|
| BLAKE2b-256 |
6f0b2ee93cce0fe01a3fb2be88bdcb35d003f836295a14d9c795fd6a5e8b677e
|
File details
Details for the file a3s_code-2.6.0-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: a3s_code-2.6.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 15.1 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ffb57f0e79eda0fd2657b0a97ed2acc0c004839dc90a1f7a52f5eec72c6be03
|
|
| MD5 |
36a731f761399af6fcb5629f0332fef4
|
|
| BLAKE2b-256 |
09989982e3d0ae2bcd99abea6d7b0d00f2af7394dba8464d25a902db7b73473a
|
File details
Details for the file a3s_code-2.6.0-cp310-cp310-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: a3s_code-2.6.0-cp310-cp310-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 17.1 MB
- Tags: CPython 3.10, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af13767f76dd7babfff433303b98a37fb4cf03e10bf427e9d00c7f46fbd4ace6
|
|
| MD5 |
f93de2ffe917298300fdad6a79f691a7
|
|
| BLAKE2b-256 |
dc0d5a047107b8881beb66d6ae7f1bc1bf7b2ce359286a9391e93d6458b0a733
|
File details
Details for the file a3s_code-2.6.0-cp310-cp310-macosx_11_0_arm64.whl.
File metadata
- Download URL: a3s_code-2.6.0-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 15.1 MB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e2f4927ebc069a95e61f537cc5ee0580513eabbd4825d10236a966bd4cb0d5e
|
|
| MD5 |
e3674d3c4c1bc55b25d655a3b774bad2
|
|
| BLAKE2b-256 |
5f2745669acfbd94dffcfce8bd8f3e5bed77d8434c74d506e09ba7e053a553c2
|