Skip to Content
MS-SWIFT × TWINKLE
数据格式
COMPONENTSMS-SWIFT × TWINKLE

消息

Message 是对话的一轮,Tool 是声明给模型的工具定义,ToolCall 是模型发出的一次工具调用。三者都是 TypedDict,运行时是普通 dict。

class FunctionCall(TypedDict, total=False):
    name: str
    arguments: Union[str, Dict[str, Any]]

class ToolCall(TypedDict, total=False):
    id: str
    type: Literal['function']
    function: FunctionCall

class FunctionSpec(TypedDict, total=False):
    name: str
    description: str
    parameters: Union[str, Dict[str, Any]]

class Tool(TypedDict, total=False):
    type: Literal['function']
    function: FunctionSpec

class Message(TypedDict, total=False):
    role: Literal['system', 'user', 'assistant', 'tool']
    type: str
    content: Union[str, List[Dict[str, str]]]
    tool_calls: List[ToolCall]
    tool_call_id: str
    reasoning_content: str

Message

字段含义
rolesystem / user / assistant / tool。tool 是工具调用结果,像 user 消息一样回给模型
content正文。含多模态内容时用占位符 <image>、<video>、<audio>,原媒体放在 Trajectory 的 images / videos / audios 中,模板按占位符顺序对齐
tool_callsassistant 消息发出的工具调用列表
tool_call_idtool 消息对应的 ToolCall.id
reasoning_content推理模型的思考段,与 content 分开存放
{'role': 'system', 'content': 'You are a helpful assistant.'}
{'role': 'user', 'content': 'What is the weather of Beijing today?'}
{'role': 'assistant', 'content': 'I need to call the weather api.',
 'tool_calls': [{'type': 'function', 'function': {'name': 'weather', 'arguments': {'city': 'Beijing'}}}]}
{'role': 'tool', 'content': 'Sunny', 'tool_call_id': 'call_1'}

ToolCall

与 OpenAI chat-completion 协议对齐:外层 {type: 'function', function: {...}},function.name 是工具名,function.arguments 经 chat template 渲染时是 dict,分发到工具时也接受 JSON 字符串。

Tool

声明给模型的工具,OpenAI 形状:{'type': 'function', 'function': {'name', 'description', 'parameters'}},parameters 是 JSON Schema。