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_core::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 {
    tool_type: "function".to_string(),
    function: ai_lib_core::types::tool::FunctionDefinition {
        name: "get_weather".to_string(),
        description: Some("Get current weather for a location".to_string()),
        parameters: Some(serde_json::json!({
            "type": "object",
            "properties": {
                "location": {"type": "string"}
            }
        })),
    },
};

Modules§

events
Streaming events based on AI-Protocol standard_schema
execution_result
E/P 边界:执行层返回结果类型(对应 Paper1 第 3 章 3.1–3.2)。
message
Unified message format based on AI-Protocol standard_schema
tool
Tool calling definitions based on AI-Protocol standard_schema

Structs§

ExecutionMetadata
Metadata returned with every E-layer call for P-layer policy decisions.
ExecutionResult
Successful execution envelope from E: payload plus metadata for P.
ExecutionUsage
Token usage attached to an execution (aligned with driver UsageInfo).
Message
Unified message structure
ToolCall
Tool call (invocation from model)
ToolDefinition
Tool definition (for function calling)

Enums§

MessageRole
Message role
StreamingEvent
Unified streaming event enum