Skip to main content

Crate umf

Crate umf 

Source
Expand description

Universal Message Format (UMF)

This crate provides a provider-agnostic message representation for LLM interactions. It follows the OpenAI-compatible JSON structure as the foundation while supporting conversion to any LLM provider format (Anthropic, Google Gemini, Cohere, etc.).

§Core Principles

  1. OpenAI-Compatible Base: The format follows OpenAI’s JSON structure
  2. Provider-Agnostic: Can be converted to any LLM provider format
  3. Metadata Support: Includes optional metadata for internal tracking
  4. Tool Calling Support: Full support for function/tool calling
  5. Hub Model: Internal format acts as conversion hub for all protocols

§Features

  • internal (default) - Core hub types for protocol conversion
  • chatml - ChatML message formatting
  • events - Conversation event tracking
  • streaming - Streaming response support
  • mcp - Model Context Protocol types and conversion
  • full - All features enabled

§Usage

use umf::{InternalMessage, MessageRole, ContentBlock};

// Create a simple text message
let msg = InternalMessage::user("Hello, world!");

// Create a message with tool calls
let msg = InternalMessage::assistant_with_tools(
    "Let me search for that",
    vec![ContentBlock::tool_use("call_123", "search", serde_json::json!({"q": "rust"}))],
);

Re-exports§

pub use internal::ConversionError;
pub use internal::FromInternal;
pub use internal::InternalTool;
pub use internal::InternalToolCall;
pub use internal::InternalToolResult;
pub use internal::ToInternal;
pub use internal::TryFromInternal;
pub use internal::TryToInternal;
pub use chatml::ChatMLFormatter;
pub use chatml::ChatMLMessage;
pub use chatml::MessageRole as ChatMLMessageRole;
pub use events::Event;
pub use events::EventEnvelope;
pub use events::EventType;
pub use events::McpContext;
pub use events::MessageEvent;
pub use events::ModelInfo;
pub use events::ToolCall as EventToolCall;
pub use events::ToolCallEvent;
pub use events::ToolCallStatus;
pub use events::ToolResult;
pub use events::ToolResultEvent;

Modules§

chatml
ChatML message formatter for simpaticoder.
events
Event types for conversation tracking and storage
internal
Internal format module - the hub for protocol conversion.

Structs§

Function
Function definition for tools
FunctionCall
Function call structure for tool invocations
InternalMessage
A message in the internal format
Tool
Tool definition for OpenAI-compatible tools
ToolCall
Tool call structure for function calling

Enums§

ContentBlock
A content block within a message
GenerateResult
Result of generation with tools
ImageSource
Image source for image blocks
MessageContent
Message content (text or structured blocks)
MessageRole
Message role in a conversation