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,
    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")
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()

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

# 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


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.0.0-cp313-cp313-win_amd64.whl (15.3 MB view details)

Uploaded CPython 3.13Windows x86-64

a3s_code-3.0.0-cp313-cp313-manylinux_2_28_x86_64.whl (17.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

a3s_code-3.0.0-cp313-cp313-macosx_11_0_arm64.whl (15.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

a3s_code-3.0.0-cp312-cp312-win_amd64.whl (15.3 MB view details)

Uploaded CPython 3.12Windows x86-64

a3s_code-3.0.0-cp312-cp312-manylinux_2_28_x86_64.whl (17.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

a3s_code-3.0.0-cp312-cp312-macosx_11_0_arm64.whl (15.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

a3s_code-3.0.0-cp311-cp311-win_amd64.whl (15.2 MB view details)

Uploaded CPython 3.11Windows x86-64

a3s_code-3.0.0-cp311-cp311-manylinux_2_28_x86_64.whl (17.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

a3s_code-3.0.0-cp311-cp311-macosx_11_0_arm64.whl (15.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

a3s_code-3.0.0-cp310-cp310-win_amd64.whl (15.2 MB view details)

Uploaded CPython 3.10Windows x86-64

a3s_code-3.0.0-cp310-cp310-manylinux_2_28_x86_64.whl (17.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

a3s_code-3.0.0-cp310-cp310-macosx_11_0_arm64.whl (15.3 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: a3s_code-3.0.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 15.3 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.0.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 e2655f69e1524c5734e49d5cb4ed4a08a5d2ff6a336d4db2e69eed2588a17d0a
MD5 c6126cd87fc6c46ea154a662c6e65933
BLAKE2b-256 03ba39a80cb3b617bb03b0020417333e7011f3971020edcf83941538c5989527

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-3.0.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1fa8e0776ceb3e26650a65eb59a59e8343d9a9f13368aec67082087c43d541b3
MD5 d1c6f5c9a621e046695edd71ecc2de38
BLAKE2b-256 c7e0d950d14978e20a21f3235104a0954a190027bbf8eac0e0c5adb480740527

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-3.0.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b8fbdb76fb69a4bc403e4f12adf48a13f4733f94b5d1a1a42b65024c89940d40
MD5 3ea4925ae65ecc55d6acdc80f73a3451
BLAKE2b-256 4a2ad7a65b4efb1ad1e9e423b1d8bad80bcda3c1e51146013bcb7242cedb2885

See more details on using hashes here.

File details

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

File metadata

  • Download URL: a3s_code-3.0.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 15.3 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.0.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 dd7b3ee62aa363d70c0eae911ad5c965fdb34d25fac1356bc37d8faa1ae78f2d
MD5 254909f4d245d92c42dc9b450c05f43a
BLAKE2b-256 b61e71e9ea878feda2efe60f1297768717be8c91841d294eb02d1396d2809e6d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-3.0.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e1db3544bac565d8f75ce04fdc12d7c25ea24189b8887550dabbcc482c4c965c
MD5 51c0df83a668ebcfab0ded426492a98e
BLAKE2b-256 5399ff6065fd4b2e921ec03f367ce2a27f2c66bc92d5bd8de41597ad648022de

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-3.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4c1225644c6f062915ce9f4639d12314c78ba4ac2a5beceafdc0e9b7e389ec3b
MD5 d452cdab39cc0cd4a26a24387ca7a8c4
BLAKE2b-256 cd708c72ca68cdedd05b99461a2baa026b9cb74469621bc339881d89766b5f98

See more details on using hashes here.

File details

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

File metadata

  • Download URL: a3s_code-3.0.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 15.2 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.0.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8977a44b98566e76c643dd605155066554a45c4bcb460d4abeb6440dc647c44a
MD5 5f5c44ffa44e16612a6f25992e4415f1
BLAKE2b-256 ed7c774edbc779619da6e5d9d7a2332dd61a3ca4736d6007f6b05ddff0d3af15

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-3.0.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8e33c556a37221efa5d23dabc11a0e838f789f61d618455f17d9ef074c9f1eb8
MD5 4b1283f30d34dabc30dcdca8340318ac
BLAKE2b-256 8383526494480bb118317c4d09e0934a30176748ea9d9f7a93b835cc5e9eaa57

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-3.0.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6d28e22f0bfa78cd91debef4ff8a2dfe3f2fb6137abbfd5f6eabd54008262c8f
MD5 708954f321b295ea3515aea638368de7
BLAKE2b-256 19bb69a4bf700e26fbe94170eaedf093d29782e085cbfa379bc81404248a7e40

See more details on using hashes here.

File details

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

File metadata

  • Download URL: a3s_code-3.0.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 15.2 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.0.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 4053aa2c749ee1e3f5a94a599846f11732d26ead539fa0641edb96eb6e0d23e8
MD5 adc2170e0ec2353dd821f55d49d2bf43
BLAKE2b-256 c6c60e405307beccebe026230c2e8ea8ff993093066a23d9c340800857a4f418

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-3.0.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4efe5b636d849ee9f2762111f052bae332674b8077128e0473911c825468abce
MD5 52dad222cb71fce192a24c15d70cbbd2
BLAKE2b-256 69164b4ebaa39007cf46ead465ec0abb25aa6ae1bb059d0ec8b3d23ab32286b5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-3.0.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 127e3d5d77e95af083d640bdcaed1a97186dd6921217f336e19c65a4bf972181
MD5 167f13565715be9b276fc239f7a2e2c3
BLAKE2b-256 cf106c1cd0a411e171380f988cc6b2e32c05f3b5a37782566ea546b2b61e4d3c

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