Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Using the SDK

Common patterns for interacting with the Akshi runtime from agent code. Examples are in Rust; the same functions are available in Python and TypeScript SDKs with language-appropriate naming.

Inference

Request LLM inference through the router:

#![allow(unused)]
fn main() {
let answer = ctx.infer("Explain quantum computing in one paragraph.")?;

// With model hint
let answer = ctx.infer_with_model("claude-sonnet", "Explain quantum computing.")?;
}

The router selects local or cloud models based on your route profile.

Journal operations

Store and retrieve agent memory:

#![allow(unused)]
fn main() {
// Insert an entry
ctx.journal_insert("daily-summary", &summary_text)?;

// Vector similarity search
let results = ctx.journal_search("network anomaly detection", 5)?;
for entry in results {
    println!("{}: {} (score: {})", entry.key, entry.text, entry.score);
}

// Hybrid search (vector + keyword)
let results = ctx.journal_hybrid_search("anomaly", "network", 5)?;
}

Each journal entry is automatically embedded for vector search and tagged with provenance metadata (agent name, timestamp, DID signature).

Database operations

Use the built-in SQLite database for structured data:

#![allow(unused)]
fn main() {
ctx.db_exec("CREATE TABLE IF NOT EXISTS events (id INTEGER PRIMARY KEY, msg TEXT)")?;
ctx.db_exec("INSERT INTO events (msg) VALUES (?)", &[&event_message])?;

let rows = ctx.db_query("SELECT msg FROM events ORDER BY id DESC LIMIT 10")?;
}

HTTP fetch

Make outbound HTTP requests (requires http_fetch capability):

#![allow(unused)]
fn main() {
let response = ctx.http_fetch("https://api.example.com/data")?;
let body = response.text()?;
}

Only domains listed in the agent’s endpoint allowlist are permitted.

A2A messaging

Delegate tasks to other agents:

#![allow(unused)]
fn main() {
// Send a task to another agent
let task_id = ctx.a2a_send("researcher", json!({"query": "Rust WASM runtimes"}))?;

// Check task result (non-blocking)
if let Some(result) = ctx.a2a_poll(task_id)? {
    println!("Result: {}", result);
}
}

MCP tool calls

Call tools exposed by configured MCP servers:

#![allow(unused)]
fn main() {
let result = ctx.mcp_call("search", json!({"query": "akshi documentation"}))?;
}

See MCP Integration for server configuration.

Logging

#![allow(unused)]
fn main() {
ctx.log_info("Processing started");
ctx.log_warn("Rate limit approaching");
ctx.log_error("Failed to fetch data");
}

Logs are visible via akshi logs, the dashboard, and the /api/v1/logs endpoint.