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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

a3s_code-2.4.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.4.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.4.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: a3s_code-2.4.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.4.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2d3364eeaed8ed515d87551c27a11f8542cc06fdbff37a6595dfd8734b2216a5
MD5 07957a3b3c50362a7c5699ef37d3bc9a
BLAKE2b-256 2212de43aeec84bc287abf916707872a571f0bc854bfa4be7f4faf188b0fe94d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.4.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 adc1ae7aec1a4f7625ae9ea4799fb8b710904c8efe8c5acda2a8c9b82c627af8
MD5 b63d52fa72ee4a8e47c4257746c1e90c
BLAKE2b-256 1756bca755f61f2f2234784338593e4a9bc84de42d5cef849f1031a5bec9e37b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.4.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a22a122bb429294edc487280b20dd6354fe6e64dc6b3270ea351f6631425a78b
MD5 9ae67693bc4fb1c23c61fdf332af374f
BLAKE2b-256 196428f830ef75b5517de32b455426b9b1cdb4914cc7ec7ce2d17299396d6ab8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: a3s_code-2.4.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.4.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 66f5cd6d1651a9dfcb7dbf3ce4e7303db98d93b15026b61557ea52d5ba3ae54f
MD5 b8bb1b1e619fb29daafb3cd0f6c246fb
BLAKE2b-256 c28d8aadc567c6bda55e1d34152476a2c0bd80b25b8a6037741815b63ca5d7c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.4.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 604db25cb5f95a74941781ab8f5e309e2619008cff725e26cdefb77ac968b1b9
MD5 68c2d0e99455c5598b9b9e791237c4c1
BLAKE2b-256 9c92b98b21dbe45131e54ff1a128f951de4227487fed32ac4617cf9de0440ef7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.4.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ce4b5050cf9002635bfba7c0c52f29a43831cfaf8ef656c3a8f9669c5147ba46
MD5 a873e7eb9bd0e9b643c73ccb4f46e41c
BLAKE2b-256 ea46c063f945a80cd659497c3fa180fce14fb64e992158522d5b4fd7ae1b3260

See more details on using hashes here.

File details

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

File metadata

  • Download URL: a3s_code-2.4.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.4.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c9bb92530a751bbded55050522ab03f1b0d8fb74fdb334fdccdaac026a54aae5
MD5 f94a9e8efdf311322147cae44e9c9777
BLAKE2b-256 9e80c02861ff323356923e3af63d3b138cf12fc24b52444cccc7a51d608ddbc9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.4.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c06865561c6169487f56a90b2ccf79a47cdb06ae31eb215bb26b026c2b81d10d
MD5 92953e3d7cf783dd4b656843b1cd9a2a
BLAKE2b-256 5a39be8ec1a1130b5dab0b388691b6f550cabf776ee8effa485971ebdc45497e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.4.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9ca1d138667c95ff8c30109ed865a59a68fc84a60ff16a8250a1a71651dde366
MD5 19ea068909086b69ac4d67770bdb7a15
BLAKE2b-256 cc0e1002674ab9add65f352eb0f327f6bd7f5d6417be1cdc00f3f9cc28490145

See more details on using hashes here.

File details

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

File metadata

  • Download URL: a3s_code-2.4.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.4.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2be49b070a4066ce85a5193947df4b8e661fa1edcb49190d64313283f5d0ed6c
MD5 57328620733d5dde758308509d6f14ef
BLAKE2b-256 c8c8d7abc5eb1c7123ff8651186719a4752bd804bcc530b1ac108fa2e2678464

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.4.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 e97ed3d33577e9413dad0c0b56bd17b93fedcfccb348cf0c9744d0d427c2a75f
MD5 97b2f7449b68197d1e077b0c8aa6ff7c
BLAKE2b-256 71d847ddb5c7cf6c5c7a8f2fadc19738e4b32f992ccfe8ea003c94195e4eeb97

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.4.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 07fb5cfe5460c3645e6219ca03ec13e62ce7c79f4dcc69c6f5455d639ac2489b
MD5 94d9ad34694733dd9ee459168fe6ee28
BLAKE2b-256 8ef981fe05e10a210650b5872bb59763954bf139bdd335893a498f1491c5ffd1

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