UMF - Universal Message Format
A provider-agnostic message representation for LLM (Large Language Model) interactions.
Overview
UMF provides a standardized message format that can be converted to any LLM provider format (OpenAI, Anthropic, Google Gemini, Cohere, etc.). It follows OpenAI's JSON structure as the foundation while supporting flexible conversion to provider-specific formats.
Features
- OpenAI-Compatible Base: Follows OpenAI's message structure
- Provider-Agnostic: Easily convert to any LLM provider format
- Tool Calling Support: Full support for function/tool calling
- Type-Safe: Strongly typed Rust API with comprehensive validation
- Spec-Compliant: Matches the Universal Message Format specification exactly
Usage
Add to your Cargo.toml:
[]
= "0.1.0"
Basic Example
use ;
// Create a simple text message
let msg = user;
// Create a message with tool calls
let msg = assistant_with_tools;
// Create a tool result message
let msg = tool_result;
Message Structure
Content Types
Simple Text:
let msg = user;
Structured Content Blocks:
use ContentBlock;
let blocks = vec!;
let msg = InternalMessage ;
Tool Calling
Tool Use:
let tool_call = tool_use;
Tool Result:
let msg = tool_result;
JSON Serialization
UMF types serialize to JSON exactly as specified:
Text Block:
Tool Use Block:
Tool Result Block:
Provider Conversion
UMF can be converted to any provider format:
OpenAI
- Keep
role,content,tool_callsas-is - Remove internal metadata fields
Anthropic
- Extract system messages to separate parameter
- Convert
tool_callsto content blocks - Convert
role: "tool"torole: "user"withtool_resultblocks
Google Gemini / Cohere
- Follow similar conversion patterns based on provider API
Spec Compliance
UMF follows the Universal Message Format specification:
- Lowercase
typefield ("text","tool_use","tool_result") - Flattened block fields (no nested
dataobjects) - OpenAI-compatible structure as baseline
- Full round-trip serialization support
Testing
Run tests:
All tests include:
- Message creation and serialization
- Content block validation
- Spec compliance verification
- Round-trip serialization tests
License
MIT OR Apache-2.0
Related
- Simpaticoder - Terminal-first software engineering agent
- Universal Message Format Specification - See
specs/universal-message-format/