Skip to content
English

ToolCallCollector ​

CORE · interface · 类型合同

Aggregation entry point for streamed function-call deltas.

导入 ​

ts
import type { ToolCallCollector } from '@jangts/agent-core/support';
js
/** @typedef {import('@jangts/agent-core/support').ToolCallCollector} ToolCallCollector */

其他公开入口:@jangts/agent-core/support、@jangts/agent-core/support/model。

定义 ​

ts
interface ToolCallCollector

字段结构 ​

字段类型必需说明
push(part: ModelPart) => void必需Feed one part; text parts are ignored and cannot satisfy or break a call.
callsreadonly AggregatedToolCall[]必需只读。Calls started so far, including incomplete ones, in index order.
complete() => readonly AggregatedToolCall[]必需Finalize the calls.

成员目录 ​

成员用途
pushFeed one part; text parts are ignored and cannot satisfy or break a call.
completeFinalize the calls.

成员详情 ​

push ​

Feed one part; text parts are ignored and cannot satisfy or break a call.

ts
ToolCallCollector.push(part: ModelPart): void

Feed one part; text parts are ignored and cannot satisfy or break a call.

参数类型传递说明
partModelPart必需—

参数 part的可选结构: 选择其中一种结构,各分支的字段要求分别列出。

分支 1

string

分支 2
字段类型必需说明
type"function-call-delta"必需见类型定义及调用场景。
indexnumber必需Index of the call within the response; deltas with the same index belong together.
idstring | undefined可省略Provider call id, usually delivered once with the first delta.
namestring | undefined可省略Function name, usually delivered once with the first delta.
argumentsstring | undefined可省略Raw JSON argument fragment; concatenating all fragments yields the full arguments.

返回: void。

complete ​

Finalize the calls.

ts
ToolCallCollector.complete(): readonly AggregatedToolCall[]

Finalize the calls.

无调用参数。

返回: readonly AggregatedToolCall[]。

使用示例 ​

真实服务端配置接入常见协议 ​

入门 · 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);
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);

直连工具线程的声明字段与 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));
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));

相关策略源码 ​

相关定义 ​

接口参考、使用示例与开发指南。