Skip to main content

Module types

Module types 

Source
Expand description

类型系统模块:定义基于 AI-Protocol 规范的核心数据类型。

§Types Module

This module defines the core type system based on the AI-Protocol standard schema, providing strongly-typed representations for all AI interaction primitives.

§Overview

The type system ensures:

  • Type-safe message construction and handling
  • Consistent event representation across providers
  • Standardized tool/function calling interfaces
  • Serialization compatibility with AI-Protocol specification

§Key Types

TypeDescription
MessageChat message with role and content
MessageRoleMessage role (user, assistant, system, tool)
StreamingEventUnified streaming event representation
ToolCallFunction/tool call from model response
ToolDefinitionTool definition for model context

§Submodules

ModuleDescription
eventsStreaming event types and variants
messageMessage types with multi-modal content support
toolTool/function calling types

§Example

use ai_lib_rust::types::{Message, MessageRole, ToolDefinition};

// Create messages
let system = Message::system("You are a helpful assistant");
let user = Message::user("What's the weather?");

// Define a tool
let tool = ToolDefinition {
    name: "get_weather".to_string(),
    description: Some("Get current weather for a location".to_string()),
    parameters: serde_json::json!({
        "type": "object",
        "properties": {
            "location": {"type": "string"}
        }
    }),
    strict: None,
};

Re-exports§

pub use events::StreamingEvent;
pub use message::Message;
pub use message::MessageRole;
pub use tool::ToolCall;
pub use tool::ToolDefinition;

Modules§

events
Streaming events based on AI-Protocol standard_schema
message
Unified message format based on AI-Protocol standard_schema
tool
Tool calling definitions based on AI-Protocol standard_schema