Skip to content
中文

ToolCallCollector ​

CORE · interface · Type contract

Aggregation entry point for streamed function-call deltas.

Import ​

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

Other public entry points:@jangts/agent-core/support, @jangts/agent-core/support/model.

Definition ​

ts
interface ToolCallCollector

Field structure ​

FieldTypeRequiredDescription
push(part: ModelPart) => voidRequiredFeed one part; text parts are ignored and cannot satisfy or break a call.
callsreadonly AggregatedToolCall[]RequiredRead-only. Calls started so far, including incomplete ones, in index order.
complete() => readonly AggregatedToolCall[]RequiredFinalize the calls.

Member index ​

MemberPurpose
pushFeed one part; text parts are ignored and cannot satisfy or break a call.
completeFinalize the calls.

Member details ​

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.

ParameterTypePassingDescription
partModelPartRequired—

Optional shapes of Parameter part: choose one shape; required fields for each branch are listed separately.

Branch 1

string

Branch 2
FieldTypeRequiredDescription
type"function-call-delta"RequiredSee the type definition and usage context.
indexnumberRequiredIndex of the call within the response; deltas with the same index belong together.
idstring | undefinedOptionalProvider call id, usually delivered once with the first delta.
namestring | undefinedOptionalFunction name, usually delivered once with the first delta.
argumentsstring | undefinedOptionalRaw JSON argument fragment; concatenating all fragments yields the full arguments.

Returns: void.

complete ​

Finalize the calls.

ts
ToolCallCollector.complete(): readonly AggregatedToolCall[]

Finalize the calls.

No call parameters.

Returns: readonly AggregatedToolCall[].

Examples ​

Connect a common protocol with real server-side configuration ​

Beginner · Node.js

Running this example requires connection configuration for an available model service.

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);

Declared fields and wire mapping for a direct tool thread ​

Configuration · Node.js

This only demonstrates message conversion, with no network request or tool execution. Raw tool_calls, tool_call_id, and host-attached data are not forwarded.

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));

API reference, usage examples and developer guides.