ModelOptions
SUPPORT · type · Type contract
Model id is only a pool key; Core still owns the configured model/transport identities.
Import
ts
import type { ModelOptions } from '@jangts/agent-core/support/decorators';1
js
/** @typedef {import('@jangts/agent-core/support/decorators').ModelOptions} ModelOptions */1
Other public entry points:@jangts/agent-core/support/decorators.
Definition
Type: ModelOptions
Type expression
ts
type ModelOptions = ModelRunnerOptions & IdentifiedDefinition;1
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
provider | ChatProvider | Required | See the type definition and usage context. |
execution | ExecutionOptions | undefined | Optional | See the type definition and usage context. |
transports | readonly ModelTransportDefinition<unknown>[] | undefined | Optional | See the type definition and usage context. |
sink | { output?: ModelRunnerPorts["onOutput"]; } | undefined | Optional | See the type definition and usage context. |
errors | { inputBudget?: ModelRunnerPorts["inputBudgetError"]; outputBudget?: ModelRunnerPorts["outputBudgetError"]; } | undefined | Optional | See the type definition and usage context. |
children | ModelChildPolicy | undefined | Optional | Read-only. See the type definition and usage context. |
maxInputChars | number | undefined | Optional | Character budget for the assembled input. |
maxSchemaChars | number | undefined | Optional | Character allowance for registered capability schemas. |
tokenBudget | ModelTokenBudget | undefined | Optional | See the type definition and usage context. |
maxOutputTokens | number | undefined | Optional | Default output reservation; invoke can override it for one call. |
maxCalls | number | undefined | Optional | Calls allowed for the whole request, including descendant runners' reservations. |
callTimeoutMs | number | undefined | Optional | Deadline for one provider call, in milliseconds. |
maxOutputChars | number | undefined | Optional | Cap on streamed output characters; exceeding it fails the call. |
usage | boolean | undefined | Optional | Request and record provider usage for each call. |
id | string | Required | Read-only. See the type definition and usage context. |
Examples
- Decorators: complete handlers and existing host methods: Classes construct definitions automatically; methods bind the real host. Outputs still use original define, constructor and bind contracts.
A class owns configuration and private helpers without manual construction
Beginner · TypeScript 标准装饰器
ts
import { AgentCoreEngine, defineWorkflow } from '@jangts/agent-core';
import type { WorkflowNode } from '@jangts/agent-core';
import { node, nodePool } from '@jangts/agent-core/support/decorators';
import type { Node } from '@jangts/agent-core/support/decorators';
type State = { text: string; answer?: string };
@node<State, string>('greet', { ns: 'greeting' })
class Greeting implements Node<State, string> {
readonly description = '生成问候';
readonly routes = [{ complete: (state: Readonly<State>) => state.answer! }];
#prefix = '你好,';
run(state: Readonly<State>) { return { answer: this._format(state.text) }; }
private _format(text: string) { return this.#prefix + text.trim(); }
}
const flow = defineWorkflow<State, string>({ id: 'greeting', nodes: nodePool.getAll('greeting') });
console.log(await new AgentCoreEngine({ workflow: flow }).run({ text: '访客' }));1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
js
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { AgentCoreEngine, defineWorkflow } from '@jangts/agent-core';
import { node, nodePool } from '@jangts/agent-core/support/decorators';
let Greeting = class Greeting {
description = '生成问候';
routes = [{ complete: (state) => state.answer }];
#prefix = '你好,';
run(state) { return { answer: this._format(state.text) }; }
_format(text) { return this.#prefix + text.trim(); }
};
Greeting = __decorate([
node('greet', { ns: 'greeting' })
], Greeting);
const flow = defineWorkflow({ id: 'greeting', nodes: nodePool.getAll('greeting') });
console.log(await new AgentCoreEngine({ workflow: flow }).run({ text: '访客' }));1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Keep a service method name and bind its original host automatically
Configuration · TypeScript 标准装饰器
ts
import type { WorkflowNode } from '@jangts/agent-core';
import { node, nodePool } from '@jangts/agent-core/support/decorators';
type State = { text: string; answer?: string };
class GreetingService {
constructor(private readonly prefix: string) {}
@node<State, string>('reply', { ns: 'service',
description: '调用现有服务',
routes: [{ complete: (state: Readonly<State>) => state.answer! }],
})
answer(state: Readonly<State>) { return { answer: this.prefix + state.text }; }
}
const service = new GreetingService('你好,');
const definition = nodePool.get<WorkflowNode<State, string>>('reply', 'service')!;
console.log(definition === nodePool.get('reply', 'service'));1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
js
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { node, nodePool } from '@jangts/agent-core/support/decorators';
class GreetingService {
prefix;
constructor(prefix) {
this.prefix = prefix;
}
answer(state) { return { answer: this.prefix + state.text }; }
}
__decorate([
node('reply', { ns: 'service',
description: '调用现有服务',
routes: [{ complete: (state) => state.answer }],
})
], GreetingService.prototype, "answer", null);
const service = new GreetingService('你好,');
const definition = nodePool.get('reply', 'service');
console.log(definition === nodePool.get('reply', 'service'));1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23