ProviderAssistantMessage
SUPPORT · interface · 类型合同
Assistant turn; content may be empty when the turn is only a tool declaration.
导入
ts
import type { ProviderAssistantMessage } from '@jangts/agent-core/support';1
js
/** @typedef {import('@jangts/agent-core/support').ProviderAssistantMessage} ProviderAssistantMessage */1
其他公开入口:@jangts/agent-core/support、@jangts/agent-core/support/model。
定义
ts
interface ProviderAssistantMessage1
字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
role | "assistant" | 必需 | 只读。见类型定义及调用场景。 |
content | string | 必需 | 只读。见类型定义及调用场景。 |
images | undefined | 可省略 | 只读。见类型定义及调用场景。 |
toolCallId | undefined | 可省略 | 只读。见类型定义及调用场景。 |
toolCalls | readonly ModelToolCall[] | undefined | 可省略 | 只读。见类型定义及调用场景。 |
使用示例
- 兼容 Provider 与自定义 Provider:Support 负责常见 Chat Completions HTTP/SSE 生命周期;App 可替换为自己的 ChatProvider。
- Support:推荐用法的聚合入口:Support 聚合推荐的构造、策略与同源配置生成;Core 运行不依赖这个命名空间。
真实服务端配置接入常见协议
入门 · Node.js
运行此例需要提供可用模型服务的连接配置。
ts
import { ModelRunner, Support } from '@jangts/agent-core';
const provider = new Support.CompatibleModelProvider({ config: {
baseUrl: process.env.MODEL_BASE_URL!, apiKey: process.env.MODEL_API_KEY!, model: process.env.MODEL_NAME!,
} });
const runner = new ModelRunner({ provider });
console.log((await runner.invoke('你好')).value);1
2
3
4
5
6
2
3
4
5
6
js
import { ModelRunner, Support } from '@jangts/agent-core';
const provider = new Support.CompatibleModelProvider({ config: {
baseUrl: process.env.MODEL_BASE_URL, apiKey: process.env.MODEL_API_KEY, model: process.env.MODEL_NAME,
} });
const runner = new ModelRunner({ provider });
console.log((await runner.invoke('你好')).value);1
2
3
4
5
6
2
3
4
5
6
直连工具线程的声明字段与 wire 映射
配置 · Node.js
只演示消息转换,无网络请求或工具执行。原始 tool_calls、tool_call_id 和宿主附加数据不透传。
ts
import { Support } from '@jangts/agent-core';
const messages: Support.ProviderMessage[] = [
{ role: 'user', content: '查询资料' },
{ role: 'assistant', content: '', toolCalls: [
{ id: 'call-1', name: 'lookup', arguments: '{"query":"资料"}' },
] },
{ role: 'tool', content: '{"found":true}', toolCallId: 'call-1' },
];
console.log(Support.chatCompletionMessages(messages));1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
js
import { Support } from '@jangts/agent-core';
const messages = [
{ role: 'user', content: '查询资料' },
{ role: 'assistant', content: '', toolCalls: [
{ id: 'call-1', name: 'lookup', arguments: '{"query":"资料"}' },
] },
{ role: 'tool', content: '{"found":true}', toolCallId: 'call-1' },
];
console.log(Support.chatCompletionMessages(messages));1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9