|
| 1 | +# A3S Code — Python SDK |
| 2 | + |
| 3 | +Native Python bindings for the A3S Code AI coding agent, built with PyO3. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +pip install a3s-code |
| 9 | +``` |
| 10 | + |
| 11 | +## Quick Start |
| 12 | + |
| 13 | +```python |
| 14 | +from a3s_code import Agent |
| 15 | + |
| 16 | +agent = Agent.create("agent.hcl") |
| 17 | +session = agent.session("/my-project") |
| 18 | + |
| 19 | +result = session.send("What files handle authentication?") |
| 20 | +print(result.text) |
| 21 | +``` |
| 22 | + |
| 23 | +## Slash Commands |
| 24 | + |
| 25 | +Every session includes built-in slash commands dispatched before the LLM: |
| 26 | + |
| 27 | +```python |
| 28 | +# List all available commands |
| 29 | +commands = session.list_commands() |
| 30 | +for cmd in commands: |
| 31 | + print(f"/{cmd['name']:15s} {cmd['description']}") |
| 32 | + |
| 33 | +# Built-in commands |
| 34 | +result = session.send("/help") # List all commands |
| 35 | +result = session.send("/model") # Show current model |
| 36 | +result = session.send("/cost") # Token usage and cost |
| 37 | +result = session.send("/history") # Conversation stats |
| 38 | +result = session.send("/cron-list") # List scheduled tasks |
| 39 | +``` |
| 40 | + |
| 41 | +### Custom Commands |
| 42 | + |
| 43 | +```python |
| 44 | +def my_handler(args: str, ctx: dict) -> str: |
| 45 | + return f"Model: {ctx['model']}, History: {ctx['history_len']} msgs, args: {args!r}" |
| 46 | + |
| 47 | +session.register_command("status", "Show session info", my_handler) |
| 48 | +result = session.send("/status hello") |
| 49 | +``` |
| 50 | + |
| 51 | +## Scheduled Tasks |
| 52 | + |
| 53 | +Schedule recurring prompts that fire after each `send()` call: |
| 54 | + |
| 55 | +```python |
| 56 | +# Via /loop slash command |
| 57 | +r = session.send("/loop 30s check deployment status") |
| 58 | +print(r.text) # Scheduled [a1b2c3d4]: "check deployment status" — fires every 30s |
| 59 | + |
| 60 | +# Programmatic API |
| 61 | +task_id = session.schedule_task("summarize recent commits", 300) # every 5 min |
| 62 | + |
| 63 | +# List active tasks |
| 64 | +for t in session.list_scheduled_tasks(): |
| 65 | + print(f"[{t['id']}] every {t['interval_secs']}s — \"{t['prompt']}\"") |
| 66 | + |
| 67 | +# Cancel |
| 68 | +session.cancel_scheduled_task(task_id) |
| 69 | +session.send(f"/cron-cancel {task_id}") |
| 70 | +``` |
| 71 | + |
| 72 | +**Interval syntax:** `30s`, `5m`, `2h`, `1d`. Leading or trailing with `every` clause. |
| 73 | + |
| 74 | +## Full API |
| 75 | + |
| 76 | +```python |
| 77 | +from a3s_code import Agent, SessionOptions, DefaultSecurityProvider, FileMemoryStore, FileSessionStore |
| 78 | + |
| 79 | +agent = Agent.create("agent.hcl") |
| 80 | +session = agent.session("/my-project", |
| 81 | + model="openai/gpt-4o", |
| 82 | + builtin_skills=True, |
| 83 | + planning=True, |
| 84 | +) |
| 85 | + |
| 86 | +# Send / Stream |
| 87 | +result = session.send("Explain the auth module") |
| 88 | +for event in session.stream("Refactor auth"): |
| 89 | + if event.event_type == "text_delta": |
| 90 | + print(event.text, end="", flush=True) |
| 91 | + |
| 92 | +# Direct tools (bypass LLM) |
| 93 | +session.read_file("src/main.py") |
| 94 | +session.bash("pytest") |
| 95 | +session.glob("**/*.py") |
| 96 | +session.grep("TODO") |
| 97 | + |
| 98 | +# Slash commands & scheduling |
| 99 | +session.list_commands() |
| 100 | +session.register_command("ping", "Pong!", lambda args, ctx: "pong") |
| 101 | +task_id = session.schedule_task("daily report", 86400) |
| 102 | +session.list_scheduled_tasks() |
| 103 | +session.cancel_scheduled_task(task_id) |
| 104 | + |
| 105 | +# Memory |
| 106 | +session.remember_success("task", ["tool"], "result") |
| 107 | +session.recall_similar("auth", 5) |
| 108 | + |
| 109 | +# Hooks |
| 110 | +session.register_hook("audit", "pre_tool_use", handler_fn) |
| 111 | + |
| 112 | +# MCP |
| 113 | +session.add_mcp_server("github", command="npx", args=["-y", "@modelcontextprotocol/server-github"]) |
| 114 | +session.mcp_status() |
| 115 | +session.tool_names() |
| 116 | +session.remove_mcp_server("github") |
| 117 | + |
| 118 | +# Persistence |
| 119 | +opts = SessionOptions() |
| 120 | +opts.session_store = FileSessionStore('./sessions') |
| 121 | +opts.session_id = 'my-session' |
| 122 | +opts.auto_save = True |
| 123 | +session2 = agent.session(".", opts) |
| 124 | +resumed = agent.resume_session('my-session', opts) |
| 125 | +``` |
| 126 | + |
| 127 | +## License |
| 128 | + |
| 129 | +MIT |
0 commit comments