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

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)
session.read_file("src/main.py")
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


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

Uploaded CPython 3.13Windows x86-64

a3s_code-2.5.0-cp313-cp313-manylinux_2_28_x86_64.whl (14.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

a3s_code-2.5.0-cp313-cp313-macosx_11_0_arm64.whl (13.0 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

a3s_code-2.5.0-cp312-cp312-win_amd64.whl (12.6 MB view details)

Uploaded CPython 3.12Windows x86-64

a3s_code-2.5.0-cp312-cp312-manylinux_2_28_x86_64.whl (14.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

a3s_code-2.5.0-cp312-cp312-macosx_11_0_arm64.whl (13.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

a3s_code-2.5.0-cp311-cp311-win_amd64.whl (12.6 MB view details)

Uploaded CPython 3.11Windows x86-64

a3s_code-2.5.0-cp311-cp311-manylinux_2_39_x86_64.whl (14.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.39+ x86-64

a3s_code-2.5.0-cp311-cp311-manylinux_2_28_x86_64.whl (14.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

a3s_code-2.5.0-cp311-cp311-macosx_11_0_arm64.whl (13.0 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

a3s_code-2.5.0-cp310-cp310-win_amd64.whl (12.6 MB view details)

Uploaded CPython 3.10Windows x86-64

a3s_code-2.5.0-cp310-cp310-manylinux_2_28_x86_64.whl (14.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

a3s_code-2.5.0-cp310-cp310-macosx_11_0_arm64.whl (13.0 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: a3s_code-2.5.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 12.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-2.5.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 787e88081a23bb406a9c7a1ac3eec9553ae956cae0a9b03290d1ca755c87ddef
MD5 9bfe0986291953176dcbfeefdb9eed4d
BLAKE2b-256 a43c62db70da613f5308716401b774dde19b9d0fb5af91aee31ac5d5324b6023

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.5.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 051183b5c12d06578ed486b6d680ce6d32aaa0fd492fd5af05096b93b72e2003
MD5 c9e05facbe4be66b57b45f502a2d9885
BLAKE2b-256 3d5776d1ac839b205758dbfdeba93f11962c615e361cb3921e373eac8bdfdfd7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.5.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f92d422ba51a6c0e5665380573b6124a12f8b48a4edb120d35311c0ba743889d
MD5 ccc1119e0efb480e78e1964a8c7b06a0
BLAKE2b-256 bb71c69f92fdcee0373237583e253439f943becce2c20d5c52c914a9aa9555f0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: a3s_code-2.5.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 12.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-2.5.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 54a40ec012bc980933c5646cb3568539cb7810d2f275d6c99315cc54dd4d3080
MD5 be664d7f6a5d37c640a7f06d6875397d
BLAKE2b-256 e4e84b3d42b9bbe9cacae2e1f313ff2b85910b2a6c1d25e6be2c3586ff984fb2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.5.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7141e12bb52cdac4e3412805cf6165f37b6dbacc8e8154336ff05329b9ef4e47
MD5 7dfaf42b6e1ec5dcb1caa9cd3129244a
BLAKE2b-256 a2591111fac51c3a2b08309cdf0e4efa2461fc97bd6f9944a6332e7fb64c9710

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.5.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 09bc9b8375ee18bb6c0c03cd0fb953e823d4755f09cab466bf35e5346e30fa9d
MD5 5a3e03229d63fdd4242cf3218f88ecfd
BLAKE2b-256 9954681a8fafbc3160c4ccc8bd8127ea3215603ee3ef6ab220a1cc80b1f8201e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.5.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c0d339866731fbe775a302e46850b567bb9d82f32511fd4a31b31a4ac05bde89
MD5 9c407a64ce2472342b3f7fa0ffd45f1b
BLAKE2b-256 1a00d6f0e9864b558c10424da6dea5c55b9be94142b6a80b52f8ad03083cbb42

See more details on using hashes here.

File details

Details for the file a3s_code-2.5.0-cp311-cp311-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for a3s_code-2.5.0-cp311-cp311-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 b0eec408affadf5c55e98c2b8a5865357083d354618c2edbaa87a05136657f07
MD5 3d38e47a2a4616e7b9a61ac2a59159b7
BLAKE2b-256 e8a9d707cbb75c270d598050904b80c3ea3ddb89801b960bd5a5f168d46cd6e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.5.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 050b3ae45501d0c11de0e883b219f15124f32ff978561390d91c3090fffbdb72
MD5 0f9c27df6f73b56eecaadd1315830c66
BLAKE2b-256 1e0d0d9e19d5e93553ac4d1fede11b0dc3807f79898baa4b10bafae82c9f8b51

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.5.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 581ac8ff6abdb0fb4896a5e318a489051194dcf64831efbc0ad7f40ddce782e1
MD5 94ae4de8d2fea7ad7b10adcd43c61627
BLAKE2b-256 6f5f05018941101fcfb2e3b00def3f705f389a810eb5744f527953832266dde3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: a3s_code-2.5.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 12.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-2.5.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ab735381d26c68904342376d38b58a67284251de243c053480a65a53fa278774
MD5 504c2a3e6bbed0a4425e07a3bd1dfba7
BLAKE2b-256 ddaec09148967ce2801377c98bccddd90695d7aa476c560404c1b30b649d135f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.5.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6e7c12b09594ebf58965e9e300d93cf1f0929f365ab3dc6ef423ef1cd9d119e8
MD5 e06b4126d77aad0985e66ae2d1f92624
BLAKE2b-256 99873abcededfe0e69480bd61e2bcda02eace7b9b272fb6a0527e395261bd6d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.5.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c980a3f8d7d275762bb8845f39068d422e40a11da53fd30a52d6bc65c274fd7a
MD5 a2a776cb7d20460e740dd8525a0ea78d
BLAKE2b-256 56c87c17469261e6c6dd060ab0381039b153e370e3c8d20722542c7d97b7d73e

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