Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Rust SDK

The official Rust client for LocusGraph — store events, retrieve knowledge, and generate insights from your wisdom graph.

Installation

Add the dependency to your Cargo.toml:

[dependencies]
locusgraph-client = "0.1"

Configuration

use locusgraph_client::{LocusGraphClient, LocusGraphConfig};
 
let config = LocusGraphConfig {
    server_url: Some("https://api.locusgraph.com".to_string()),
    agent_secret: Some("your-agent-secret".to_string()),
    graph_id: Some("default".to_string()),
};
let client = LocusGraphClient::new(Some(config));

Set LOCUSGRAPH_SERVER_URL and LOCUSGRAPH_AGENT_SECRET as environment variables to avoid hardcoding credentials. The client reads these automatically when config values are None.

The Rust SDK uses a blocking HTTP API powered by ureq. All methods block the current thread until the response arrives.

Store Event

Add knowledge to your wisdom graph with store_event.

use locusgraph_client::CreateEventRequest;
 
let request = CreateEventRequest {
    graph_id: "default".to_string(),
    event_kind: "fact".to_string(),
    source: Some("onboarding-flow".to_string()),
    context_id: Some("user-preferences".to_string()),
    payload: "User prefers dark mode and weekly email digests.".to_string(),
    reinforces: Some(vec!["ctx-abc123".to_string()]),
    extends: None,
    contradicts: None,
    related_to: Some(vec!["ctx-def456".to_string()]),
    timestamp: Some("2025-01-15T10:30:00Z".to_string()),
};
 
let response = client.store_event(request)?;
// response.event_id   -> "evt-789"
// response.context_id -> "user-preferences"
// response.status     -> "stored"

Retrieve Knowledge

Run semantic search across your wisdom graph with retrieve_memories.

let result = client.retrieve_memories(
    "default",                              // graph_id
    "What are the user notification preferences?", // query
    Some(5),                                // limit
    Some(vec!["user-preferences".to_string()]), // context_ids
    Some(vec!["fact".to_string()]),         // context_types
)?;
 
// result.memories -> Vec<Memory>
// result.memories[0].content   -> "User prefers weekly email digests."
// result.memories[0].score     -> 0.92
// result.memories[0].context_type -> "fact"

Get Context

Fetch a single context by ID. Returns an error if the context does not exist.

let context = client.get_context(
    "user-preferences", // context_id
    "default",          // graph_id
)?;
 
// context.context_id   -> "user-preferences"
// context.context_type -> "fact"
// context.content      -> "User prefers dark mode..."

List Context Types

Browse available context types in your wisdom graph.

let types = client.list_context_types(
    "default", // graph_id
    0,         // page
    100,       // page_size
)?;
 
// types.context_types -> vec!["fact", "action", "decision", ...]

Generate Insights

Reason over your wisdom graph and produce synthesized answers.

let insight = client.generate_insights(
    "default",          // graph_id
    "Summarize user preferences and suggest personalization strategies.", // task
    Some("user preferences and settings".to_string()), // locus_query
    Some(10),           // limit
    Some(vec!["user-preferences".to_string()]), // context_ids
    Some(vec!["fact".to_string(), "decision".to_string()]), // context_types
)?;
 
// insight.insight    -> "Based on stored knowledge, the user prefers..."
// insight.sources    -> vec!["ctx-abc123", "ctx-def456"]
// insight.confidence -> 0.89

Environment Variables

VariableDescription
LOCUSGRAPH_SERVER_URLAPI server URL (default: https://api.locusgraph.com)
LOCUSGRAPH_AGENT_SECRETYour agent secret key

Next

TypeScript SDK
Use LocusGraph with TypeScript.
Python SDK
Use LocusGraph with Python.