chatCompletionFunctionOptions
SUPPORT · function · Runtime value
Build the tool-selection request fields for a function-calling stage.
The adapter expects exactly one function call per response, so tool use is required and parallel calls are disabled.
Import
import { chatCompletionFunctionOptions } from '@jangts/agent-core/support';import { chatCompletionFunctionOptions } from '@jangts/agent-core/support';Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/support, @jangts/agent-core/support/model.
Definition
Call
chatCompletionFunctionOptions(options: ModelOptions): Record<string, unknown>Build the tool-selection request fields for a function-calling stage.
The adapter expects exactly one function call per response, so tool use is required and parallel calls are disabled.
| Parameter | Type | Passing | Description |
|---|---|---|---|
options | ModelOptions | Required | — |
Fields of options
| Field | Type | Required | Description |
|---|---|---|---|
json | boolean | undefined | Optional | Request a JSON-object response from providers that support it. |
temperature | number | undefined | Optional | Sampling temperature; provider range is not normalized by Core. |
maxOutputTokens | number | undefined | Optional | Output ceiling for the call; the effective value is the smaller of this and the budget. |
includeUsage | boolean | undefined | Optional | Ask the provider to report usage for streamed responses. |
onUsage | ((usage: ModelUsage) => void) | undefined | Optional | Receives usage the provider reports; may be called once per call. |
functions | readonly ModelFunction[] | undefined | Optional | Functions offered to the model for this call. |
toolChoice | "auto" | "required" | "none" | undefined | Optional | Tool-selection strategy; omitted keeps the provider's default. |
parallelToolCalls | boolean | "omit" | undefined | Optional | Request parallel tool calls; 'omit' leaves the wire field out entirely. |
Returns: Record<string, unknown>.
Examples
- Compatible Provider and custom Providers: Support owns the common Chat Completions HTTP/SSE lifecycle; an App can substitute its own ChatProvider.
Connect a common protocol with real server-side configuration
Beginner · Node.js
Running this example requires connection configuration for an available model service.
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);2
3
4
5
6
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);2
3
4
5
6
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.
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));2
3
4
5
6
7
8
9
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));2
3
4
5
6
7
8
9
Connect an offline object implementation to the same contract
Configuration · Node.js
import { ModelRunner } from '@jangts/agent-core/model';
const provider = { async *stream(messages: readonly { content: string }[]) {
yield '离线回答:' + messages.at(-1)!.content;
} };
console.log((await new ModelRunner({ provider }).invoke('你好')).value);2
3
4
5
import { ModelRunner } from '@jangts/agent-core/model';
const provider = { async *stream(messages) {
yield '离线回答:' + messages.at(-1).content;
} };
console.log((await new ModelRunner({ provider }).invoke('你好')).value);2
3
4
5