Expand description
§neuromance
A Rust library for controlling and orchestrating LLM interactions.
Neuromance provides high-level abstractions for building LLM-powered applications, including conversation management, tool calling, and interaction orchestration.
§Quick Start
use neuromance::{Conversation, Message, Core, CoreEvent, ToolApproval};
// Create a conversation
let mut conversation = Conversation::new().with_title("My Chat");
// Add messages
let user_msg = Message::user(conversation.id, "Hello!");
let assistant_msg = Message::assistant(conversation.id, "Hi there!");
conversation.add_message(user_msg).expect("Failed to add message");
conversation.add_message(assistant_msg).expect("Failed to add message");
// Core uses event-driven architecture for streaming and monitoring
let core = Core::new(client)
.with_streaming()
.with_event_callback(|event| async move {
match event {
CoreEvent::Streaming(chunk) => print!("{}", chunk),
CoreEvent::ToolResult { name, .. } => println!("Tool executed: {}", name),
CoreEvent::Usage(usage) => println!("Tokens: {}", usage.total_tokens),
}
})
.with_tool_approval_callback(|tool_call| {
let tool_call = tool_call.clone();
async move {
println!("Approve {}?", tool_call.function.name);
ToolApproval::Approved // Or prompt user
}
});§Features
- Conversation Management: Track multi-turn conversations with metadata and status
- Message Handling: Support for system, user, assistant, and tool messages
- Tool Calling: Define and execute function calls from LLM responses
- Serialization: Full serde support for all types
Re-exports§
pub use core::Core;pub use events::CoreEvent;pub use events::EventCallback;pub use events::ToolApprovalCallback;
Modules§
- agents
- Agent state management and context types.
- chat
- Chat conversation and message types.
- client
- Client configuration and request/response types.
- core
- error
- events
- Event types for Core orchestration
- generic
- mcp
- openai
- OpenAI API types and client implementation.
- tools
- Tool calling and function execution types.
Structs§
- Agent
Context - Context describing the agent’s current task and environment.
- Agent
Memory - Memory storage for agents.
- Agent
Response - Response from agent execution.
- Agent
State - Complete state of an agent.
- Agent
Stats - Execution statistics for monitoring agent performance.
- Boolean
Tool - A tool that returns a boolean result based on the agent’s analysis Used for binary decisions like goal verification
- Chat
Request - A request for a chat completion from an LLM.
- Chat
Response - A response from a chat completion request.
- Config
- Configuration for an LLM client.
- Conversation
- Represents a conversation thread containing multiple messages.
- Function
- Describes a function that can be called by an LLM.
- Function
Call - Represents an invocation of a function with arguments.
- Message
- A single message in a conversation.
- NoRetry
Policy - A retry policy for SSE streams that never retries.
- OpenAI
Client - Client for OpenAI-compatible APIs.
- Parameters
- Defines the parameter schema for a function using JSON Schema conventions.
- Property
- Describes a single property in a function parameter schema.
- Retry
Config - Configuration for exponential backoff retry behavior.
- Think
Tool - A tool that allows the agent to record thoughts and reasoning Used for making the agent’s thinking process visible in the context
- Todo
Read Tool - Tool for reading the current todo list
- Todo
Write Tool - Tool for writing/updating the todo list
- Tool
- Represents a tool available to the LLM, typically wrapping a function.
- Tool
Call - Represents a complete tool call from an LLM, including ID and function details.
- Tool
Executor - Tool
Registry - Usage
- Token usage statistics for a completion request.
Enums§
- Agent
Message - Messages that can be sent to or from an agent.
- Client
Error - Errors that can occur when interacting with LLM APIs.
- Conversation
Status - The lifecycle status of a conversation.
- Finish
Reason - Indicates why the model stopped generating tokens.
- Message
Role - Represents the role of a message sender in a conversation.
- Tool
Approval - Represents the approval status of a tool call.
- Tool
Choice - Controls how the model selects which tool to call, if any.
Traits§
- LLMClient
- Trait for LLM client implementations.
- Tool
Implementation
Functions§
- create_
todo_ tools - Create a pair of TodoRead and TodoWrite tools that share the same storage