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("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,
    SessionOptions,
    DefaultSecurityProvider,
    FileMemoryStore,
    FileSessionStore,
)

agent = Agent.create("agent.acl")
session = agent.session("/my-project",
    model="openai/gpt-4o",
    builtin_skills=True,
    planning=True,
)

# Send / Stream
result = session.send("Explain the auth module")
for event in session.stream("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.

# Direct tools (bypass LLM)
session.read_file("src/main.py")
session.bash("pytest")
session.glob("**/*.py")
session.grep("TODO")

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

# Rich document parsing metadata
tool = session.tool("agentic_parse", {"path": "docs/scanned.pdf"})
print(tool.metadata)  # parsed dict

query_tool = session.tool(
    "agentic_parse",
    {"path": "docs/scanned.pdf", "query": "overview"},
)
for block in query_tool.agentic_parse_llm_blocks_info:
    location = block.location.display if block.location else None
    print(block.index, block.kind, block.label, location)

search = session.tool("agentic_search", {"query": "invoice total", "mode": "fast"})
for result in search.agentic_search_results_info:
    for match in result.matches:
        print(match.line_number, match.locator, match.content)

# 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_server("github", command="npx", args=["-y", "@modelcontextprotocol/server-github"])
session.mcp_status()
session.tool_names()
session.remove_mcp_server("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)

Agentic Search Match Locators

agentic_search_results_info now exposes typed match and sampled-line entries so you can inspect page / section locators without parsing raw metadata.

search = session.tool("agentic_search", {"query": "overview", "mode": "fast"})

for result in search.agentic_search_results_info:
    for match in result.matches:
        print(match.line_number, match.locator, match.content)
        if match.context_before:
            print("before:", match.context_before[-1])

deep = session.tool("agentic_search", {"query": "overview", "mode": "deep"})
for result in deep.agentic_search_results_info:
    for sampled in result.sampled_lines:
        print(sampled.line_number, sampled.locator, sampled.distance, sampled.weight)

Agentic Parse LLM Blocks

When agentic_parse runs with a query, the SDK also exposes which structured document blocks were actually selected for the LLM input.

tool = session.tool(
    "agentic_parse",
    {"path": "docs/scanned.pdf", "query": "overview"},
)

for block in tool.agentic_parse_llm_blocks_info:
    location = block.location.display if block.location else None
    print(block.index, block.kind, block.label, location)

Advanced Sub-Agent Events

Orchestrator.create(agent=agent) is the advanced lifecycle-control API for real LLM-backed sub-agents. Routine delegation should use task / parallel_task; use handle.events() when you need direct event monitoring.

from a3s_code import Agent, Orchestrator, SubAgentConfig

agent = Agent.create("agent.acl")
orch = Orchestrator.create(agent=agent)
handle = orch.spawn_subagent(SubAgentConfig(
    agent_type="general",
    prompt="Use bash to print hello, then explain it.",
    max_steps=5,
))

events = handle.events()
while True:
    event = events.recv(timeout_ms=1000)
    if event is None:
        continue

    event_type = event["event_type"]

    if event_type == "sub_agent_internal_event" and event.get("type") == "text_delta":
        print(event.get("text", ""), end="", flush=True)
    elif event_type == "tool_execution_started":
        print("tool args:", event["args"])
    elif event_type == "tool_execution_completed":
        print("tool duration_ms:", event["duration_ms"])
    elif event_type == "sub_agent_completed":
        break

Important details:

  • Event names use sub_agent_*, not subagent_*.
  • sub_agent_internal_event payloads are flattened. For example, a text delta is: {"event_type": "sub_agent_internal_event", "type": "text_delta", "text": "..."} rather than nesting under event.
  • tool_execution_started.args contains the accumulated tool input.
  • tool_execution_completed.duration_ms is guaranteed to be at least 1 for real tool calls.

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

Uploaded CPython 3.13Windows x86-64

a3s_code-2.0.1-cp313-cp313-manylinux_2_28_x86_64.whl (13.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

a3s_code-2.0.1-cp313-cp313-macosx_11_0_arm64.whl (12.7 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

a3s_code-2.0.1-cp312-cp312-win_amd64.whl (12.2 MB view details)

Uploaded CPython 3.12Windows x86-64

a3s_code-2.0.1-cp312-cp312-manylinux_2_28_x86_64.whl (13.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

a3s_code-2.0.1-cp312-cp312-macosx_11_0_arm64.whl (12.7 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

a3s_code-2.0.1-cp311-cp311-win_amd64.whl (12.2 MB view details)

Uploaded CPython 3.11Windows x86-64

a3s_code-2.0.1-cp311-cp311-manylinux_2_28_x86_64.whl (13.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

a3s_code-2.0.1-cp311-cp311-macosx_11_0_arm64.whl (12.6 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

a3s_code-2.0.1-cp310-cp310-win_amd64.whl (12.2 MB view details)

Uploaded CPython 3.10Windows x86-64

a3s_code-2.0.1-cp310-cp310-manylinux_2_28_x86_64.whl (13.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

a3s_code-2.0.1-cp310-cp310-macosx_11_0_arm64.whl (12.6 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: a3s_code-2.0.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 12.2 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.0.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 a5767511a629ceb6041e5641ff7012acde513ea285eeb9ec7630742220bf3d7a
MD5 ff423c8dd739062910cee485e693faa3
BLAKE2b-256 54cf90ad9a6a42a9bdbb1dfcf7de230c80f745090ba81e685a24b318f43da2f4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.0.1-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a4e10d042799d42fb13ece9933f0df58507f5dbc6b245d38500d8bba5dcc7f6a
MD5 c055855513d3e972a8daed92716456f7
BLAKE2b-256 8a130ac759f9bc5ce2689416e46c9e6798b79c071145bd9fbd3f54695dd5b9ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.0.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c6ae27ac292ae50029c43afd75edbda775e84451200de31819cf4baee9ef28b7
MD5 e1c360e2b6acd7d6b2451ade82eb2897
BLAKE2b-256 4435a692661b72bdd9370e26216a9b4cafff047eda63039ad1d8e0b2d4aa7cf5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: a3s_code-2.0.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 12.2 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.0.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9afe4d3f312417992147f57765104aebc2b268aff46742f0d1e68791adfcc9df
MD5 cd527b5b2d445f5ef022b00abb37ae27
BLAKE2b-256 97909fe84d10ae6d4025070e3d3d5e974876871b5edf04a301e75306872b3e80

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.0.1-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7ffea678020ff5ccfef86d65ea935d5b11b602a52510545b197c531ef1cf61a2
MD5 4ae7abc0832f3c1409ea94d074fe61f0
BLAKE2b-256 46f4289a16f2281c1bfb16f4691e57b47a9675e47ddec9ba39a35bfe28505f06

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.0.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5f357257209392a8656ec306f2af55ad0e8a29021f4fe9c672fc5555a6643c98
MD5 3bbc06aaea1a9911e78e30d955de7b3c
BLAKE2b-256 3e8c694e4d17260e2a399087a2161c24a893c9a5a2bcfc025799a3aa63b8d889

See more details on using hashes here.

File details

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

File metadata

  • Download URL: a3s_code-2.0.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 12.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-2.0.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0d35669ddf6bd04179b77667eb5e7b2b9192da18c6bfc1430892b9a4bda382aa
MD5 c5c5a2658a473af21356fc060c61c674
BLAKE2b-256 306b394fef92b2670399ae51f1076c4a19b6f1563cd70efa1de902a84be20aaf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.0.1-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 22a355d4a051859cc0ba48bc5b7e5ce9c0165d4ce6743ed83c9fc69aa7b34a44
MD5 625ed857612358a5c28dc7dc02665fa1
BLAKE2b-256 9d1286412851c13934703917eb99b652e95a2859f79d6d8b87f6143a8d364bed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.0.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 91d79e1cae1694a4860892c2e73d189318f57b6bf518572b39ec25925225f8c7
MD5 3cfa686bb0f14c4e9fae3439fe124229
BLAKE2b-256 e3165be11c992e4e6372b8126ddb790c34712dd65bf4e4c730cfd137eb34b305

See more details on using hashes here.

File details

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

File metadata

  • Download URL: a3s_code-2.0.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 12.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-2.0.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 adb3d0c11522b345965611af4a7df8ee3b0fe969390f997767ca6b0ee25c95b2
MD5 a6e6054aa731eff8caefa4a046a23875
BLAKE2b-256 b4ab71e3ca3c5f93dfcae8a0e7aaef44d92c7a6225722a02dc6d145460d109a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.0.1-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7bf565a371b4d281d5b1387e6760ae184dad0f147b6bc0c49b83a447e60bc3a5
MD5 25ce696b72c8a7410d25f9c53f1e9972
BLAKE2b-256 0b23cf9a68ed09097de8f1570db8d695ba36e772cbfad38e7c4c97e76d642c02

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.0.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 518e35be859ba1491a9de47666299dff1d50e758ecced91499e9e4cb33b3f0e8
MD5 d38709abec9b79c8a1362fd9f9ee6ffa
BLAKE2b-256 d8f59e76189de68bf8cc5f987014928e0809e6894da052202968d1cc113ac781

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