11# A3S Code
22
3- ** Embed AI coding agents into any application .** A3S Code is a Rust library with native Python and Node.js bindings. Give an LLM a workspace, a set of tools, and a system prompt — it reads files, runs commands, searches code, and acts on results.
3+ ** Agentic Agent Framework .** A3S Code is a Rust library with native Python and Node.js bindings. Give an LLM a workspace, a set of tools, and a system prompt — it reads files, runs commands, searches code, and acts on results.
44
55[ ![ crates.io] ( https://img.shields.io/crates/v/a3s-code-core )] ( https://crates.io/crates/a3s-code-core )
66[ ![ PyPI] ( https://img.shields.io/pypi/v/a3s-code )] ( https://pypi.org/project/a3s-code/ )
@@ -17,9 +17,6 @@ pip install a3s-code
1717
1818# Node.js
1919npm install @a3s-lab/code
20-
21- # Rust
22- cargo add a3s-code-core
2320```
2421
2522---
@@ -59,36 +56,27 @@ const result = await session.send('Find all places where we handle authenticatio
5956console .log (result .text );
6057```
6158
62- ``` rust
63- use a3s_code_core :: Agent ;
64-
65- let agent = Agent :: from_file (" agent.hcl" ). await ? ;
66- let session = agent . session (" /my-project" , Default :: default ()). await ? ;
67- let result = session . send (" Find all places where we handle authentication errors" ). await ? ;
68- println! (" {}" , result . text);
69- ```
70-
7159---
7260
7361## What the LLM Can Do
7462
7563** 16 built-in tools** — always available, no configuration:
7664
77- | Category | Tools |
78- | ----------| -------|
79- | Files | ` read ` , ` write ` , ` edit ` , ` patch ` |
80- | Search | ` grep ` , ` glob ` , ` ls ` |
81- | Shell | ` bash ` |
82- | Web | ` web_fetch ` , ` web_search ` |
83- | Git | ` git_worktree ` |
84- | Delegation | ` task ` , ` parallel_task ` , ` run_team ` , ` batch ` , ` Skill ` |
65+ | Category | Tools |
66+ | ---------- | ------------------------------------------------------------- |
67+ | Files | ` read ` , ` write ` , ` edit ` , ` patch ` |
68+ | Search | ` grep ` , ` glob ` , ` ls ` |
69+ | Shell | ` bash ` |
70+ | Web | ` web_fetch ` , ` web_search ` |
71+ | Git | ` git_worktree ` |
72+ | Delegation | ` task ` , ` parallel_task ` , ` run_team ` , ` batch ` , ` Skill ` |
8573
8674** Plugin tools** — opt-in, loaded per session:
8775
88- | Plugin | Tool | What it does |
89- | --------| ------| --------------|
76+ | Plugin | Tool | What it does |
77+ | --------------- | ---------------- | ---------------------------------------------------------------- |
9078| ` AgenticSearch ` | ` agentic_search ` | Natural-language code search with IDF-weighted relevance ranking |
91- | ` AgenticParse ` | ` agentic_parse ` | LLM-enhanced parsing for PDF, Word, CSV, code, and more |
79+ | ` AgenticParse ` | ` agentic_parse ` | LLM-enhanced parsing for PDF, Word, CSV, code, and more |
9280
9381``` python
9482from a3s_code import Agent, SessionOptions, AgenticSearch, AgenticParse
@@ -100,6 +88,64 @@ session = agent.session(".", opts)
10088
10189---
10290
91+ ## Slash Commands
92+
93+ Sessions intercept slash commands before the LLM. Type ` /help ` in any session:
94+
95+ | Command | Description |
96+ | ---------| -------------|
97+ | ` /help ` | List available commands |
98+ | ` /model [provider/model] ` | Show or switch the current model |
99+ | ` /cost ` | Show token usage and estimated cost |
100+ | ` /clear ` | Clear conversation history |
101+ | ` /compact ` | Manually trigger context compaction |
102+ | ` /tools ` | List registered tools |
103+ | ` /loop [interval] <prompt> ` | Schedule a recurring prompt (default: 10m) |
104+ | ` /cron-list ` | List scheduled tasks |
105+ | ` /cron-cancel <id> ` | Cancel a scheduled task |
106+
107+ Register custom commands:
108+
109+ ``` python
110+ session.register_command(" status" , " Show status" , lambda args , ctx : f " Model: { ctx[' model' ]} " )
111+ result = session.send(" /status" )
112+ ```
113+
114+ ---
115+
116+ ## BTW — Ephemeral Side Questions
117+
118+ Ask a side question without it affecting conversation history:
119+
120+ ``` python
121+ btw = session.btw(" What's the default port for PostgreSQL?" )
122+ print (btw.answer) # "5432"
123+ print (btw.total_tokens) # token usage for this query only
124+ # main conversation continues — btw question not in history
125+ ```
126+
127+ ---
128+
129+ ## Scheduled Tasks
130+
131+ Schedule recurring prompts via ` /loop ` or the programmatic API:
132+
133+ ``` python
134+ # Via slash command
135+ session.send(' /loop 5m check if tests are still passing' )
136+
137+ # Programmatic
138+ task_id = session.schedule_task(' summarize git log since last check' , 300 )
139+
140+ # List and cancel
141+ tasks = session.list_scheduled_tasks()
142+ session.cancel_scheduled_task(task_id)
143+ ```
144+
145+ Interval syntax: ` 30s ` , ` 5m ` , ` 2h ` , ` 1d ` . Max 50 tasks per session; auto-expire after 3 days.
146+
147+ ---
148+
103149## Safety and Control
104150
105151Agents run with ** explicit permissions** . Nothing executes by default without a policy allowing it:
@@ -117,10 +163,35 @@ session = agent.session(".", opts)
117163```
118164
119165Other safety features:
166+
120167- ** Human-in-the-loop confirmation** — prompt before any tool call
121168- ** Skill-based tool restrictions** — ` allowed-tools ` in skill frontmatter limits what the LLM can call
122169- ** AHP integration** — plug in an external harness to block or sanitize tool calls at runtime
123170- ** Auto-compact** — rolls up context before hitting token limits, keeping sessions running
171+ - ** Circuit breaker** — stops after 3 consecutive LLM failures, prevents infinite retry loops
172+ - ** Continuation injection** — prevents the LLM from stopping early mid-task (max 3 continuation turns)
173+
174+ ---
175+
176+ ## Hooks — Lifecycle Events
177+
178+ Intercept and modify agent behavior at 11 event points:
179+
180+ ``` python
181+ from a3s_code import SessionOptions, HookHandler
182+
183+ class MyHook (HookHandler ):
184+ def pre_tool_use (self , tool_name , tool_input , ctx ):
185+ if tool_name == " bash" and " rm -rf" in str (tool_input):
186+ return self .block(" Refusing destructive command" )
187+ return self .continue_()
188+
189+ opts = SessionOptions()
190+ opts.hook_handler = MyHook()
191+ session = agent.session(" ." , opts)
192+ ```
193+
194+ Hook events: ` PreToolUse ` (blockable), ` PostToolUse ` , ` GenerateStart ` (modifiable), ` GenerateEnd ` , ` SessionStart/End ` , ` SkillLoad/Unload ` , ` PrePrompt ` , ` PostResponse ` , ` OnError ` .
124195
125196---
126197
@@ -191,6 +262,25 @@ Built-in skills (enabled via `builtin_skills=True`): `agentic-search`, `code-sea
191262
192263---
193264
265+ ## Multi-Agent
266+
267+ Delegate tasks to subagents or coordinate teams:
268+
269+ ``` python
270+ # Single subagent
271+ result = session.send(' task: explore the codebase and summarize the architecture' )
272+
273+ # Parallel tasks
274+ result = session.send(' parallel_task: [audit security, check performance, review tests]' )
275+
276+ # Agent team (lead decomposes → workers execute → reviewer validates)
277+ result = session.send(' run_team: refactor the authentication module' )
278+ ```
279+
280+ Built-in agent types: ` explore ` (read-only), ` general ` (full capabilities), ` plan ` (analysis only).
281+
282+ ---
283+
194284## Architecture
195285
196286```
@@ -212,9 +302,11 @@ Agent (config + provider registry)
212302Full reference, examples, and guides: ** [ a3s.dev/docs/code] ( https://a3s.dev/docs/code ) **
213303
214304- [ Sessions & Options] ( https://a3s.dev/docs/code/sessions )
305+ - [ Commands & Scheduling] ( https://a3s.dev/docs/code/commands ) — ` /btw ` , ` /loop ` , slash commands
215306- [ Tools] ( https://a3s.dev/docs/code/tools )
216307- [ Skills] ( https://a3s.dev/docs/code/skills )
217308- [ Plugin System] ( https://a3s.dev/docs/code/plugins )
309+ - [ Hooks] ( https://a3s.dev/docs/code/hooks )
218310- [ Security] ( https://a3s.dev/docs/code/security )
219311- [ Examples] ( https://a3s.dev/docs/code/examples )
220312
0 commit comments