defaultCompletionPolicy
SUPPORT · constant · Runtime value
Import
import { defaultCompletionPolicy } from '@jangts/agent-core/support';import { defaultCompletionPolicy } from '@jangts/agent-core/support';Other public entry points:@jangts/agent-core/support, @jangts/agent-core/support/model.
Definition
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | Read-only. Registered identifier; the catalog key must match it. |
Member index
| Member | Purpose |
|---|---|
begin | Start one request. Throwing here rejects the request before it is sent, which is how a policy refuses a request shape it cannot judge after the fact. |
Member details
begin
Start one request.
Throwing here rejects the request before it is sent, which is how a policy refuses a request shape it cannot judge after the fact.
defaultCompletionPolicy.begin(facts: CompletionRequestFacts, fail: CompletionFailure): CompletionSessionStart one request.
Throwing here rejects the request before it is sent, which is how a policy refuses a request shape it cannot judge after the fact.
| Parameter | Type | Passing | Description |
|---|---|---|---|
facts | CompletionRequestFacts | Required | — |
fail | CompletionFailure | Required | — |
Fields of facts
| Field | Type | Required | Description |
|---|---|---|---|
functions | boolean | Required | Read-only. Whether the call declared native functions through Core options. |
toolChoice | unknown | Optional | Read-only. Effective tool_choice of the request body; an absent field reads as undefined. |
allowEmptyText | boolean | Required | Read-only. Whether an empty response is allowed because JSON mode permits it. |
Returns: CompletionSession.
Return value structure
| Field | Type | Required | Description |
|---|---|---|---|
part | (part: ModelPart) => void | Required | Observe one part immediately before the provider yields it. |
finish | (reason: string) => void | Required | Observe the stream's single finish_reason. |
end | () => void | Required | Complete the response when the end-of-stream marker arrives. |
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);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.
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));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));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);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);