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

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

Uploaded CPython 3.13Windows x86-64

a3s_code-2.3.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.3.0-cp313-cp313-macosx_11_0_arm64.whl (12.9 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

a3s_code-2.3.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.3.0-cp312-cp312-macosx_11_0_arm64.whl (12.9 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

a3s_code-2.3.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.3.0-cp311-cp311-macosx_11_0_arm64.whl (12.9 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

a3s_code-2.3.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.3.0-cp310-cp310-macosx_11_0_arm64.whl (12.9 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: a3s_code-2.3.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.3.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6e885e698dd83991b66ecf197f3acef0ebb0ac79159c051262b708931a3067c5
MD5 3976fadcd1af003474ef9cadb4821710
BLAKE2b-256 3c4a2ddc8ff8e7bdd3d77a6ad89fd25319b046f71fd98070fbbba3551c1143f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.3.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 87c6a4f171c1cadcdeaec768757eb2bac1859940c7d12fb625b9d6de6b7cee0f
MD5 b4d3b35de06a3a0e0519ca8d477fe916
BLAKE2b-256 e2f6793095754438615e131bfc2ea55db848fef8fd1c0409ff318fee4b909722

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.3.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3ec2c7ac5f08abe2701f5e479ebc7625e37ca95ef9fc1331a740acc96666a71b
MD5 a170d2a5b8de8fe7730fe0f181872f75
BLAKE2b-256 ea44a7bb6ca0395db82b093b981e9de041e833f16e9d2704f6f8a75696c8e0dd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: a3s_code-2.3.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.3.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 edc21a9b5f7cc5921bf8686cc8efd79fd905726d6500d08429c0065a9d6764a1
MD5 67c52328171e51597e70d3e39dcca810
BLAKE2b-256 f0c1069c428c9b222e3e58d2793d58da07355ea100e040a14f4b168c96c02171

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.3.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dd462b50902d1f5ddf7c35a19c64b9aa776fa7bed7c9ecb7e95b1da5df08f081
MD5 88f3198afaf8481ec05d533650e43082
BLAKE2b-256 7e76b68c130b89938e86624d07b46d37c42dbf05e070c468839f0fb1c2c2d20d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a1abf2451002401ecd8668351af2ab9a17b1142af0d810ec41129c79fe029a14
MD5 93999ffa8ed8a094f6b601054b74c929
BLAKE2b-256 15e732f78f9a10150adfc5952a48234f40d902e44a8b4c8da4b2acea7c37be8c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: a3s_code-2.3.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 12.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-2.3.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b22f078106d874c66827f394a0bebacb045d9068e24ef1b923b984fda874f5ea
MD5 d075f98ca24ff568ce57bbfb8b96518e
BLAKE2b-256 9318899a8944a70897390a3c462046378a0dfdb7e2ffa84588967016384ac99a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.3.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a6f9a4b9495ea3ec53953bdf13345afcc1470b45393ecf248e86fdbfc88af319
MD5 4fdbb8d2b586bf8b2fe319f8ef6a0770
BLAKE2b-256 84582a57dd60dfd45d247affd4680ea5614d7462a6a4aa4632603cc9cae96c96

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5e25e8d0507bcf1d88820029b6974251b1a0199c51248c01d434609cb5f87d4f
MD5 8ad0c721a2b77c8a71f6d6d0d376eab5
BLAKE2b-256 e19a04ad9743c69f5c8a65f1ffa97c5b282356dd811679b38e6a47fdcfdbb94f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: a3s_code-2.3.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.3.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f1b5f359c1a65a2e30cf06e43f066c822d32a3bc82a335999029b645944ca817
MD5 f0dd653b192fae048c88e7e51345b77d
BLAKE2b-256 78c344726a2268ddb0e37cac20930bed180b8c0e26b2f64ffd675341b3a13397

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.3.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 de7215ba65966e64b14ccb4f88b47aa4867992ca80431c3f95a17dc2c0cc8c22
MD5 daf81f21435cfb2221a7d1098a8a789a
BLAKE2b-256 741a50e7b8ef11fa8cf3de5696ee5b7cee9608a179496a525d257b564afafef9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.3.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bdcaec9302c36dd49e7d0d4165880f793a069560cb4958fb274bb29ad7e858aa
MD5 aa8770bd5b7820da299318b4db62d020
BLAKE2b-256 540b750a7089e0e2b8292a59125656af120f7fa661d748d935f8c99050ca8181

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