distri-0.2.8 has been yanked.
distri
Rust client for the Distri A2A agent platform. Use it to invoke agents, stream responses over SSE, and handle tool calls, connect MCPs and much more. Check out https://distri.dev/ for further information.
Install
[]
= "0.2.4"
Quick start
use Distri;
use Message;
async
Streaming responses
use Distri;
use Message;
async
Handle tool calls locally
use ;
use ;
use json;
let registry = new;
registry.register;
let stream = from_config.with_tool_registry;
let client = new.with_stream_client;
Configuration
Distri::from_env() and DistriConfig::from_env() read:
DISTRI_BASE_URL(defaults tohttps://api.distri.dev)DISTRI_API_KEY(optional)
You can also create a ~/.distri/config file:
= "https://api.distri.dev"
= "your-api-key"
Session Store API
The Distri client provides a comprehensive session store API for managing thread-scoped key-value storage. Session values can be used to store state, share data between agent iterations, and attach additional content to user messages.
Basic Session Operations
use Distri;
use json;
let client = from_env;
let session_id = "thread-123";
// Set a session value
client.set_session_value.await?;
// Get a single session value
let value = client.get_session_value.await?;
println!;
// Get all session values as a HashMap
let all_values = client.get_session_values.await?;
for in all_values
// Delete a specific key
client.delete_session_value.await?;
// Clear all values in a session
client.clear_session.await?;
Prefixed User Parts
For granular control, use the prefixed user parts API. Any session value with the __user_part_ prefix is automatically included in user messages:
use Distri;
use Part;
let client = from_env;
let session_id = "thread-123";
// Set a named user part (automatically prefixed with __user_part_)
client.set_user_part.await?;
// Set a text user part (convenience method)
client.set_user_part_text.await?;
// Set an image user part (with automatic gzip compression)
client.set_user_part_image.await?;
// Delete a specific user part
client.delete_user_part.await?;
// Clear all user parts
client.clear_user_parts.await?;
Session Value Expiry
Session values can optionally have an expiry time:
use Utc;
let expiry = now + hours;
client.set_session_value.await?;
Use Cases
- Browser Automation: Store screenshots, DOM observations, and user interactions
- State Management: Maintain conversation context and user preferences
- Tool Integration: Share data between external tools and agent iterations
- Multi-step Workflows: Persist intermediate results across agent calls
Related crates
distri-typesfor message, tool, and config typesdistri-a2afor the A2A protocol primitivesdistri-filesystemfor tool implementations
License
MIT