A3S CodeExamples
Direct Tools
Call tools directly without involving the LLM — useful for scripting, testing, and custom pipelines
Direct Tools
Call any built-in tool directly without an LLM round-trip. This is useful for scripting, testing, or building custom pipelines on top of A3S Code's tool layer.
Low-Level: session.tool()
use a3s_code_core::{Agent, SessionOptions};
let agent = Agent::new("~/.a3s/config.hcl").await?;
let session = agent.session("/my-project", Some(
SessionOptions::new().with_permissive_policy()
))?;
// Write a file
let r = session.tool("write", serde_json::json!({
"path": "hello.txt",
"content": "Hello from direct tool execution!"
})).await?;
println!("write: exit={}", r.exit_code);
// Read it back
let r = session.tool("read", serde_json::json!({"path": "hello.txt"})).await?;
println!("content: {}", r.output);
// Edit the file
let r = session.tool("edit", serde_json::json!({
"path": "hello.txt",
"old_string": "Hello",
"new_string": "Hi"
})).await?;
println!("edit: exit={}", r.exit_code);
// Glob for files
let r = session.tool("glob", serde_json::json!({"pattern": "*.txt"})).await?;
println!("matches: {}", r.output);
// Run bash
let r = session.tool("bash", serde_json::json!({"command": "cat hello.txt"})).await?;
println!("bash: {}", r.output);
// Grep
let r = session.tool("grep", serde_json::json!({"pattern": "Hi", "path": "."})).await?;
println!("grep: {}", r.output);Run: cargo run --example 07_direct_tools
Source: core/examples/07_direct_tools.rs
session = agent.session("/my-project", permissive=True)
# Write a file
r = await session.tool("write", {"path": "hello.txt", "content": "Hello!"})
print(f"write: exit={r.exit_code}")
# Read it back
r = await session.tool("read", {"path": "hello.txt"})
print(f"content: {r.output}")
# Run bash
r = await session.tool("bash", {"command": "cat hello.txt"})
print(f"bash: {r.output}")const session = agent.session('/my-project', { permissive: true });
// Write a file
const r1 = await session.tool('write', { path: 'hello.txt', content: 'Hello!' });
console.log(`write: exit=${r1.exitCode}`);
// Read it back
const r2 = await session.tool('read', { path: 'hello.txt' });
console.log(`content: ${r2.output}`);
// Run bash
const r3 = await session.tool('bash', { command: 'cat hello.txt' });
console.log(`bash: ${r3.output}`);Convenience Methods
Higher-level wrappers for common operations:
// Read a file
let content = session.read_file("src/main.rs").await?;
// Run a shell command
let output = session.bash("cargo test").await?;
// Find files by pattern
let files = session.glob("**/*.rs").await?;
// Search content
let matches = session.grep("TODO").await?;content = await session.read_file("src/main.rs")
output = await session.bash("cargo test")
files = await session.glob("**/*.rs")
matches = await session.grep("TODO")const content = await session.readFile('src/main.rs');
const output = await session.bash('cargo test');
const files = await session.glob('**/*.rs');
const matches = await session.grep('TODO');Direct tool calls bypass the LLM entirely — no tokens consumed, no streaming events. They still respect the session's permission policy and workspace scope.
API Reference
session.tool()
Prop
Type
Convenience Methods
Prop
Type