Skip to main content

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,
    ArtifactStoreLimits,
    ConfirmationPolicy,
    PermissionPolicy,
    SessionOptions,
    WorkerAgentSpec,
    DefaultSecurityProvider,
    FileMemoryStore,
    FileSessionStore,
    HttpTransport,
    LocalWorkspaceBackend,
    S3WorkspaceBackend,
)

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")
opts.artifact_store_limits = ArtifactStoreLimits(max_artifacts=64, max_bytes=8 * 1024 * 1024)
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()
artifact = session.get_artifact("a3s://tool-output/read/abc123")

# S3-compatible workspace — point the same direct tools at object storage.
# `bash`, `git`, `grep`, `glob` are automatically hidden because object
# storage cannot service them. Works with AWS S3, MinIO, RustFS, R2, B2.
s3_opts = SessionOptions()
s3_opts.workspace_backend = S3WorkspaceBackend(
    bucket="workspace",
    prefix="users/u1/sessions/s1",
    access_key_id="AKIA...",
    secret_access_key="...",
    endpoint="https://minio.local:9000",         # omit for AWS S3
    region="us-east-1",
    force_path_style=True,                       # True for MinIO/RustFS/R2
)
s3_session = agent.session("s3://workspace/users/u1/sessions/s1", s3_opts)
s3_session.write_file("notes/hello.txt", "one\ntwo\n")
s3_session.read_file("notes/hello.txt")
s3_session.ls("notes")

# 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."},
])

# Automatic subagent delegation controls
opts = SessionOptions()
opts.auto_delegation = AutoDelegationConfig(enabled=True, max_tasks=4)
opts.max_parallel_tasks = 8
opts.auto_parallel = False  # disables automatic fan-out; manual session.tasks(...) still works
session = agent.session("/my-project", opts)

# 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")

# Evidence
session.record_verification_reports([{
    "schema": "a3s.verification_report.v1",
    "subject": "sdk:tests",
    "status": "passed",
    "checks": [{
        "id": "check:sdk",
        "kind": "test",
        "description": "Run SDK tests",
        "status": "passed",
        "required": True,
    }],
}])
session.verification_reports()
session.verification_summary_text()

# 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


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

a3s_code-3.1.0-cp313-cp313-win_amd64.whl (15.6 MB view details)

Uploaded CPython 3.13Windows x86-64

a3s_code-3.1.0-cp313-cp313-manylinux_2_28_x86_64.whl (17.7 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

a3s_code-3.1.0-cp313-cp313-macosx_11_0_arm64.whl (15.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

a3s_code-3.1.0-cp312-cp312-win_amd64.whl (15.6 MB view details)

Uploaded CPython 3.12Windows x86-64

a3s_code-3.1.0-cp312-cp312-manylinux_2_28_x86_64.whl (17.7 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

a3s_code-3.1.0-cp312-cp312-macosx_11_0_arm64.whl (15.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

a3s_code-3.1.0-cp311-cp311-win_amd64.whl (15.6 MB view details)

Uploaded CPython 3.11Windows x86-64

a3s_code-3.1.0-cp311-cp311-manylinux_2_28_x86_64.whl (17.7 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

a3s_code-3.1.0-cp311-cp311-macosx_11_0_arm64.whl (15.7 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

a3s_code-3.1.0-cp310-cp310-win_amd64.whl (15.6 MB view details)

Uploaded CPython 3.10Windows x86-64

a3s_code-3.1.0-cp310-cp310-manylinux_2_28_x86_64.whl (17.7 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

a3s_code-3.1.0-cp310-cp310-macosx_11_0_arm64.whl (15.7 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file a3s_code-3.1.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: a3s_code-3.1.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 15.6 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

Hashes for a3s_code-3.1.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 bcde36543e05b2a926f385b6ce22686e69ccbc865c9dc4e317676e1b98d3cbdf
MD5 90a084857d3d7dfdf216ec441703b0d3
BLAKE2b-256 9338ec4adf30baeb9ca146b21d1a2bb350ed7bd131d3a70cdd622d3eca4d94e6

See more details on using hashes here.

File details

Details for the file a3s_code-3.1.0-cp313-cp313-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for a3s_code-3.1.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6bd64e8ca93fc1107e7d3859470daa3e8739fb53ca5fe020a5bfe9c2f8e1a40e
MD5 8ae0a6d8011355df4fc4a4c1bdab024c
BLAKE2b-256 b9d93e1449fddc47d4783f7403caa7a9758715853bcb45b23837db185b79778e

See more details on using hashes here.

File details

Details for the file a3s_code-3.1.0-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for a3s_code-3.1.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 767903f84210674ce13f3ba5cfe02ee98a8f484f4128147bbed4cddf66454e3d
MD5 37a3f34ffa7f88429eaf3f6d8ebf2ec8
BLAKE2b-256 a9e09699c7a76414264195282c0d34d69c47a28fb1e48ab88a2410ae7f355394

See more details on using hashes here.

File details

Details for the file a3s_code-3.1.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: a3s_code-3.1.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 15.6 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

Hashes for a3s_code-3.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 4abcf9f20c7619dfd8ee6f25da38793c9db309010dbf6d18f6448279d556f577
MD5 0b5e2851feec8a5b4b5c8a7f8423c728
BLAKE2b-256 519aab042479e51f259c1cfd4c3067d335a229eb98c61cf3584239095a208c66

See more details on using hashes here.

File details

Details for the file a3s_code-3.1.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for a3s_code-3.1.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b547cb6dc394a567365e84b0f7cdf0a65f8763dc6a69c44ce36ce6fc95e14d21
MD5 c2ad7bba922f995151a77cd45a7ee371
BLAKE2b-256 3f1580a11a19a89de6df060e6c4545763e86d9f2945538d4ccdcce7770eeb89f

See more details on using hashes here.

File details

Details for the file a3s_code-3.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for a3s_code-3.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 eab1ead7104893037c5026822da6e6618c527344ffba300caaacc10102a6e387
MD5 1efdb566aa6d28965c401f280fdb0190
BLAKE2b-256 792e5aadb1604ed71cbebe34da546ca5f53d54d4d7a844fe8af62ebbeedd08d0

See more details on using hashes here.

File details

Details for the file a3s_code-3.1.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: a3s_code-3.1.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 15.6 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

Hashes for a3s_code-3.1.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 51528f9b5d81d7cb5dc4acdf4624cda64c5b1fe21219d359f69b3f55ee274d25
MD5 6caeddf1763dede6a27c86ac8acf6ad3
BLAKE2b-256 779d9b4512ac35735fc7817b97f1481371947c33a8c9c1ea532eb5cbd9be2fef

See more details on using hashes here.

File details

Details for the file a3s_code-3.1.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for a3s_code-3.1.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7a7e9c95e1a0bd24e0d27d4e60cb2dea51c41a866f5b20af7e7a08ea1d7b2df1
MD5 4e7e65fc7579858493dde9d2031e39ca
BLAKE2b-256 70e1922b987937706bf6a698b902daa708585b2b19697f5b4beea501d65c62a6

See more details on using hashes here.

File details

Details for the file a3s_code-3.1.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for a3s_code-3.1.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 48f407d91c43485c314186461f715e05b83f56291a2f596a1ac773f82c7908fc
MD5 dbedcd3e53a1ab35762717233e1bb81b
BLAKE2b-256 460dfc2828471bb797df8228cfac65bc9cc0702bb36d5e89a8ab53df55d8acda

See more details on using hashes here.

File details

Details for the file a3s_code-3.1.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: a3s_code-3.1.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 15.6 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

Hashes for a3s_code-3.1.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 babaa9b508dd7539aad85f85d86085e1a55cc69e62a1a4255863db1630b13ceb
MD5 8d559ed3607ae5d9b0fb38b9afb5b887
BLAKE2b-256 5216d48aebf46683fa7bee62b2226261f982575a3d88d30f9ff6745514118601

See more details on using hashes here.

File details

Details for the file a3s_code-3.1.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for a3s_code-3.1.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ebaa24dfc23cb8dd3dc01f7c36a1e84db060f2b5a4196fcfa6d3a1516bfa1488
MD5 ac65532e1e07f957cb6564089dadb46b
BLAKE2b-256 2cdc4c34842828099d296772decfee9dce5267f1bc36bff883809db55f53fa30

See more details on using hashes here.

File details

Details for the file a3s_code-3.1.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for a3s_code-3.1.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e3a6c024e41db687571327ca715f4241ba81b0cd8d2a60b329a7420e48df279d
MD5 51bf748339cd4ffa7d1fa0c18d805e9f
BLAKE2b-256 a8125a804dc91ec8cb4e9e16b6d8c1b7496db82f3bf5e71746adcf6cf4bf1426

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 Pingdom Monitoring Sentry Error logging StatusPage Status page