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

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

Uploaded CPython 3.13Windows x86-64

a3s_code-2.0.0-cp313-cp313-manylinux_2_28_x86_64.whl (13.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64

a3s_code-2.0.0-cp313-cp313-macosx_11_0_arm64.whl (12.2 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

a3s_code-2.0.0-cp312-cp312-win_amd64.whl (11.7 MB view details)

Uploaded CPython 3.12Windows x86-64

a3s_code-2.0.0-cp312-cp312-manylinux_2_28_x86_64.whl (13.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

a3s_code-2.0.0-cp312-cp312-macosx_11_0_arm64.whl (12.2 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

a3s_code-2.0.0-cp311-cp311-win_amd64.whl (11.7 MB view details)

Uploaded CPython 3.11Windows x86-64

a3s_code-2.0.0-cp311-cp311-manylinux_2_28_x86_64.whl (13.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

a3s_code-2.0.0-cp311-cp311-macosx_11_0_arm64.whl (12.1 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

a3s_code-2.0.0-cp310-cp310-win_amd64.whl (11.7 MB view details)

Uploaded CPython 3.10Windows x86-64

a3s_code-2.0.0-cp310-cp310-manylinux_2_28_x86_64.whl (13.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

a3s_code-2.0.0-cp310-cp310-macosx_11_0_arm64.whl (12.1 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

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

File metadata

  • Download URL: a3s_code-2.0.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 11.7 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.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 cf29d724ffe6c3520a2a23bb14d59ffddc483a3a96a738258bd98c8bec0058b0
MD5 c232e7261a7dbf77e2f371497f4635b3
BLAKE2b-256 10bd7fc3281e742579af1041c25870a88c8a860c55b0f27941d63690d2732053

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.0.0-cp313-cp313-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 eba22b4565e6c13e71f8b447b63e34dbe64450e1a8f32a886b7f2951dac05a21
MD5 a1e2e507d4b9738c9c8a350ee44fc927
BLAKE2b-256 b6a8c2e12ef56baafe5c4b3badb2f9b4df26c816ac41fcce0254cb3092b20663

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.0.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e137406d34bcdcc404309f14d2da1802974646d96183cd72fdfdb4ecca3b2bc6
MD5 7043639d2f22e0df8a361fc7d6bcbfe3
BLAKE2b-256 771e0358bff427253fc6a662e2ded8f3826cc736da79dfafadff8de96430f874

See more details on using hashes here.

File details

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

File metadata

  • Download URL: a3s_code-2.0.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 11.7 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.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 00d2ad5b4972fbbe8bd506d706e4f4d1f8a603bb3f5f2acacec0d9b0f0c76bcf
MD5 2624ee92c95642d8d5bb8fa5fb971793
BLAKE2b-256 be8b9adf965620216acc7f5d627dc9a55f0c526d946c8e588b9a5e8552a230cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.0.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ffc48ef3c6eba93d89b0d9212734733a4a65e4fefaabf69dd73b539f702de802
MD5 5fba183ec1f58086aef5e8332e457438
BLAKE2b-256 edf427ccfd0e1da0fe5bad98186bceb2e962389843a95b590fb939331c3e0775

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.0.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d5345d3b0adfa31229f39b45897fc64fd54a1591ebc72125d1e0722809bf8c92
MD5 6870f3c741c72347254f85a5f7d729f7
BLAKE2b-256 94ae1db9c5ad8d5b454c51bd11ac3a4c17a33fb8c4bbdb54884fc72f1db91d6d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: a3s_code-2.0.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 11.7 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.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8af0ff942636e3dab67c85164eb8936fdb377bc5f039abdf27cdfb8169265b3c
MD5 93dfb2f06431d2a3825ff8818c335f2d
BLAKE2b-256 ebc8467fbe3c24020ab26d5119d93303df48d444b96becd6ccb4c7eb7cb315ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.0.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6a7ccf8be9a3cb0bc8bdaca11b4c3b1c11c5cf47b0c1117cd0ab38cb7e454bac
MD5 52914c9960ffe2fba446329cdf126ce7
BLAKE2b-256 4057ec61d6b2f637ca90048eca95113ffcd60a3ae78e8fc0b1789f7502abb26c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.0.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 0ed4fe0f2563d8551b62f7b9ad9289a5d6b8d03a7a9e69d9a08455d4d1348cbe
MD5 01aeb8033c7ac8fb743fe780bc7b6c36
BLAKE2b-256 81d0af068a1130709db2e45a01580699f525903e16bd2d47ca93977e2fb8725a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: a3s_code-2.0.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 11.7 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.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 decbfed10536754fa6cc69157b7a6f60ca3e010a9fc14600be6b73b3f774ffa0
MD5 a21d68688e1d226d1c9cd2e05b487ec1
BLAKE2b-256 d2df1a286b4463421b73ec98ce1c1be41d135cfb073d876c00b0cd870067ba0c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.0.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5305ca6dcbf69b15207eb1fa0c2b2c9ed561ba7a53f56763e71b1e680368f650
MD5 0b8f1e2fe00c5162cf5010791ad8a90e
BLAKE2b-256 8c54f5e239547eea55cf239629d22d00ff83bd520adb018897e2300165b4f3f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for a3s_code-2.0.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 13aec790ce54fcd160be0335e6cbf31a019e12f78976c43d480c54b7c21e329c
MD5 92c74466497c048613f9d53bf3cf00ed
BLAKE2b-256 ff9dfe1abe551046e4ea8f05a2a054e1ae241799b1c92a3ff0d32d27be4498ea

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