@jangts/agent-core 0.3.5 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/README.md +33 -31
- package/development/docs/README.en.md +2 -2
- package/development/docs/acceptance.en.md +2 -2
- package/development/docs/agent-development.en.md +1 -1
- package/development/docs/api/README.en.md +6 -2
- package/development/docs/api/README.md +4 -0
- package/development/docs/api/configuration-in-workflow.en.md +403 -0
- package/development/docs/api/configuration-in-workflow.md +403 -0
- package/development/docs/api/core.en.md +7 -7
- package/development/docs/api/core.md +6 -6
- package/development/docs/api/decorators.en.md +20 -0
- package/development/docs/api/decorators.md +20 -0
- package/development/docs/api/examples.en.md +1 -1
- package/development/docs/api/examples.md +1 -1
- package/development/docs/api/kits.en.md +22 -4
- package/development/docs/api/kits.md +22 -4
- package/development/docs/api/knowledge-answering.en.md +4 -1
- package/development/docs/api/knowledge-answering.md +4 -1
- package/development/docs/api/mock.en.md +2 -0
- package/development/docs/api/mock.md +2 -0
- package/development/docs/api/observability.en.md +37 -11
- package/development/docs/api/observability.md +64 -11
- package/development/docs/api/reference.en.md +876 -657
- package/development/docs/api/reference.md +662 -508
- package/development/docs/api/support.en.md +55 -9
- package/development/docs/api/support.md +53 -7
- package/development/docs/api/types.en.md +36 -1
- package/development/docs/api/types.md +44 -0
- package/development/docs/api/workflow-views.en.md +64 -0
- package/development/docs/api/workflow-views.md +78 -0
- package/development/docs/api/workflow.en.md +6 -2
- package/development/docs/api/workflow.md +6 -2
- package/development/docs/basic-usage.en.md +1 -1
- package/development/docs/basic-usage.md +1 -1
- package/development/docs/create-app.en.md +1 -1
- package/development/docs/examples/registration/associated.mjs +8 -0
- package/development/docs/examples/registration/independent.mjs +20 -0
- package/development/docs/examples/registration/protocol.mjs +48 -0
- package/development/docs/examples/registration/run.mjs +47 -0
- package/development/docs/examples/registration/tools.mjs +75 -0
- package/development/docs/examples/registration/workflow.mjs +109 -0
- package/development/docs/flows/knowledge-maintenance.en.md +1 -1
- package/development/docs/materials.en.md +1 -1
- package/development/docs/mechanisms.en.md +2 -2
- package/development/docs/mechanisms.md +1 -1
- package/development/docs/operations.en.md +1 -1
- package/development/docs/records.en.md +1 -1
- package/development/docs/registration.en.md +4 -4
- package/development/docs/registration.md +2 -2
- package/development/skills/agent-core-app/SKILL.md +16 -4
- package/development/skills/agent-core-app/templates/node-ts/README.md.tpl +1 -1
- package/development/skills/agent-core-app/templates/node-ts/src/catalog.ts.tpl +2 -2
- package/development/skills/agent-core-app/templates/node-ts/test/app.test.mjs.tpl +1 -1
- package/dist/cjs/capabilities/index.js +5 -12
- package/dist/cjs/capabilities/invocation.js +21 -1
- package/dist/cjs/capabilities/model.js +56 -12
- package/dist/cjs/capabilities/tool-conditions.js +65 -0
- package/dist/cjs/capabilities/tool-runtime.js +18 -4
- package/dist/cjs/capabilities/tools.js +12 -17
- package/dist/cjs/context/audit.js +5 -8
- package/dist/cjs/context/index.js +3 -4
- package/dist/cjs/diagnostics/index.js +51 -3
- package/dist/cjs/diagnostics/native-sub-flow.js +106 -0
- package/dist/cjs/diagnostics/sub-flow.js +278 -32
- package/dist/cjs/execution/engine.js +3 -2
- package/dist/cjs/execution/events.js +5 -5
- package/dist/cjs/execution/reporting.js +18 -28
- package/dist/cjs/execution/workflow-chain.js +211 -0
- package/dist/cjs/execution/workflow-graph.js +72 -0
- package/dist/cjs/execution/workflow.js +34 -6
- package/dist/cjs/index.js +21 -17
- package/dist/cjs/kits/aggregation.js +17 -14
- package/dist/cjs/kits/answering/checks.js +2 -1
- package/dist/cjs/kits/answering/flow.js +24 -21
- package/dist/cjs/kits/answering/tasks.js +30 -25
- package/dist/cjs/kits/delivery.js +36 -24
- package/dist/cjs/kits/domains/catalog.js +113 -0
- package/dist/cjs/kits/domains/index.js +20 -0
- package/dist/cjs/kits/{intents → domains}/registry.js +77 -31
- package/dist/cjs/kits/{intents → domains}/scopes.js +21 -21
- package/dist/cjs/kits/index.js +14 -13
- package/dist/cjs/kits/knowledge/catalog.js +33 -30
- package/dist/cjs/kits/policies.js +3 -2
- package/dist/cjs/kits/presentation/formats.js +110 -0
- package/dist/cjs/kits/presentation/index.js +10 -5
- package/dist/cjs/kits/presentation/outputs.js +2 -1
- package/dist/cjs/kits/reflection.js +2 -2
- package/dist/cjs/kits/retrieval.js +7 -1
- package/dist/cjs/kits/text-blocks.js +101 -0
- package/dist/cjs/kits/tools.js +247 -158
- package/dist/cjs/model/decision-retry.js +2 -1
- package/dist/cjs/model/index.js +2 -6
- package/dist/cjs/model/interactions/calls.js +61 -0
- package/dist/cjs/model/interactions/json-object.js +11 -11
- package/dist/cjs/model/interactions/native-functions.js +17 -23
- package/dist/cjs/model/message-diagnostics.js +13 -3
- package/dist/cjs/model/options.js +2 -0
- package/dist/cjs/model/preparation.js +39 -6
- package/dist/cjs/model/runner.js +34 -5
- package/dist/cjs/model/selection-transport.js +4 -4
- package/dist/cjs/model/token-budget.js +3 -0
- package/dist/cjs/model/transports.js +3 -2
- package/dist/cjs/structs/index.js +7 -6
- package/dist/cjs/structs/kits/domains/scopes.js +2 -0
- package/dist/cjs/structs/kits/presentation/formats.js +2 -0
- package/dist/cjs/structs/kits/text-blocks.js +11 -0
- package/dist/cjs/structs/model/session.js +11 -0
- package/dist/cjs/structs/support/associations.js +2 -0
- package/dist/cjs/support/associations.js +79 -0
- package/dist/cjs/support/context/nodes.js +48 -45
- package/dist/cjs/support/context/processing.js +6 -3
- package/dist/cjs/support/context/snapshot.js +11 -1
- package/dist/cjs/support/decorators/index.js +45 -3
- package/dist/cjs/support/index.js +1 -0
- package/dist/cjs/support/model/capabilities.js +35 -5
- package/dist/cjs/support/model/chat-completions.js +11 -2
- package/dist/cjs/support/model/completion/calls.js +10 -56
- package/dist/cjs/support/model/preview-rules.js +11 -11
- package/dist/cjs/support/model/reply-preview.js +3 -3
- package/dist/cjs/support/model/session.js +152 -0
- package/dist/cjs/support/model/stage-transport.js +8 -8
- package/dist/cjs/support/model/transports.js +5 -2
- package/dist/cjs/support/tools.js +42 -17
- package/dist/cjs/utils/invocation.js +1 -0
- package/dist/esm/capabilities/index.d.ts +5 -10
- package/dist/esm/capabilities/index.js +5 -9
- package/dist/esm/capabilities/invocation.js +21 -1
- package/dist/esm/capabilities/model.d.ts +17 -13
- package/dist/esm/capabilities/model.js +54 -10
- package/dist/esm/capabilities/tool-conditions.d.ts +9 -0
- package/dist/esm/capabilities/tool-conditions.js +59 -0
- package/dist/esm/capabilities/tool-runtime.js +18 -4
- package/dist/esm/capabilities/tools.d.ts +3 -3
- package/dist/esm/capabilities/tools.js +12 -17
- package/dist/esm/context/audit.js +5 -8
- package/dist/esm/context/index.d.ts +3 -4
- package/dist/esm/context/index.js +3 -4
- package/dist/esm/diagnostics/index.d.ts +1 -0
- package/dist/esm/diagnostics/index.js +48 -2
- package/dist/esm/diagnostics/native-sub-flow.d.ts +94 -0
- package/dist/esm/diagnostics/native-sub-flow.js +101 -0
- package/dist/esm/diagnostics/sub-flow.d.ts +56 -4
- package/dist/esm/diagnostics/sub-flow.js +271 -32
- package/dist/esm/execution/engine.d.ts +1 -0
- package/dist/esm/execution/engine.js +3 -2
- package/dist/esm/execution/events.js +5 -5
- package/dist/esm/execution/reporting.d.ts +6 -12
- package/dist/esm/execution/reporting.js +19 -29
- package/dist/esm/execution/workflow-chain.d.ts +3 -0
- package/dist/esm/execution/workflow-chain.js +208 -0
- package/dist/esm/execution/workflow-graph.d.ts +7 -0
- package/dist/esm/execution/workflow-graph.js +68 -0
- package/dist/esm/execution/workflow.d.ts +6 -0
- package/dist/esm/execution/workflow.js +34 -6
- package/dist/esm/index.d.ts +19 -13
- package/dist/esm/index.js +18 -15
- package/dist/esm/kits/aggregation.d.ts +1 -1
- package/dist/esm/kits/aggregation.js +17 -14
- package/dist/esm/kits/answering/checks.js +2 -1
- package/dist/esm/kits/answering/flow.js +24 -21
- package/dist/esm/kits/answering/tasks.d.ts +6 -6
- package/dist/esm/kits/answering/tasks.js +30 -25
- package/dist/esm/kits/delivery.d.ts +0 -9
- package/dist/esm/kits/delivery.js +36 -24
- package/dist/esm/kits/domains/catalog.d.ts +42 -0
- package/dist/esm/kits/domains/catalog.js +110 -0
- package/dist/esm/kits/domains/index.d.ts +4 -0
- package/dist/esm/kits/domains/index.js +4 -0
- package/dist/esm/kits/domains/registry.d.ts +100 -0
- package/dist/esm/kits/{intents → domains}/registry.js +77 -31
- package/dist/esm/kits/{intents → domains}/scopes.d.ts +18 -18
- package/dist/esm/kits/{intents → domains}/scopes.js +21 -21
- package/dist/esm/kits/index.d.ts +6 -5
- package/dist/esm/kits/index.js +6 -5
- package/dist/esm/kits/knowledge/catalog.js +33 -30
- package/dist/esm/kits/policies.d.ts +1 -1
- package/dist/esm/kits/policies.js +3 -2
- package/dist/esm/kits/presentation/formats.d.ts +42 -0
- package/dist/esm/kits/presentation/formats.js +105 -0
- package/dist/esm/kits/presentation/index.d.ts +14 -5
- package/dist/esm/kits/presentation/index.js +10 -5
- package/dist/esm/kits/presentation/outputs.js +2 -1
- package/dist/esm/kits/reflection.js +3 -3
- package/dist/esm/kits/retrieval.js +7 -1
- package/dist/esm/kits/text-blocks.d.ts +24 -0
- package/dist/esm/kits/text-blocks.js +97 -0
- package/dist/esm/kits/tools.d.ts +69 -52
- package/dist/esm/kits/tools.js +247 -158
- package/dist/esm/model/decision-retry.d.ts +2 -0
- package/dist/esm/model/decision-retry.js +2 -1
- package/dist/esm/model/index.d.ts +2 -6
- package/dist/esm/model/index.js +2 -6
- package/dist/esm/model/interactions/calls.d.ts +40 -0
- package/dist/esm/model/interactions/calls.js +58 -0
- package/dist/esm/model/interactions/json-object.js +11 -11
- package/dist/esm/model/interactions/native-functions.js +17 -23
- package/dist/esm/model/message-diagnostics.d.ts +6 -5
- package/dist/esm/model/message-diagnostics.js +13 -3
- package/dist/esm/model/options.js +2 -0
- package/dist/esm/model/preparation.js +39 -6
- package/dist/esm/model/runner.d.ts +2 -0
- package/dist/esm/model/runner.js +34 -5
- package/dist/esm/model/selection-transport.js +4 -4
- package/dist/esm/model/token-budget.js +3 -0
- package/dist/esm/model/transports.d.ts +2 -1
- package/dist/esm/model/transports.js +3 -2
- package/dist/esm/structs/capabilities/invocation.d.ts +3 -1
- package/dist/esm/structs/capabilities/model.d.ts +42 -11
- package/dist/esm/structs/capabilities/tools.d.ts +16 -7
- package/dist/esm/structs/common.d.ts +3 -1
- package/dist/esm/structs/debug.d.ts +36 -20
- package/dist/esm/structs/execution/workflow-views.d.ts +123 -0
- package/dist/esm/structs/execution/workflow.d.ts +4 -3
- package/dist/esm/structs/index.d.ts +8 -6
- package/dist/esm/structs/index.js +7 -6
- package/dist/esm/structs/kits/answering/tasks.d.ts +2 -2
- package/dist/esm/structs/kits/{intents → domains}/catalog.d.ts +20 -20
- package/dist/esm/structs/kits/{intents → domains}/registry.d.ts +24 -21
- package/dist/esm/structs/kits/{intents → domains}/scopes.d.ts +9 -9
- package/dist/esm/structs/kits/domains/scopes.js +1 -0
- package/dist/esm/structs/kits/presentation/formats.d.ts +42 -0
- package/dist/esm/structs/kits/presentation/formats.js +1 -0
- package/dist/esm/structs/kits/text-blocks.d.ts +25 -0
- package/dist/esm/structs/kits/text-blocks.js +10 -0
- package/dist/esm/structs/kits/tools.d.ts +82 -83
- package/dist/esm/structs/model/interactions.d.ts +18 -11
- package/dist/esm/structs/model/messages.d.ts +34 -2
- package/dist/esm/structs/model/runtime.d.ts +9 -0
- package/dist/esm/structs/model/session.d.ts +29 -0
- package/dist/esm/structs/model/session.js +10 -0
- package/dist/esm/structs/support/associations.d.ts +22 -0
- package/dist/esm/structs/support/associations.js +1 -0
- package/dist/esm/structs/support/model/interactions.d.ts +2 -2
- package/dist/esm/structs/support/model/messages.d.ts +6 -13
- package/dist/esm/structs/support/tools.d.ts +23 -23
- package/dist/esm/support/associations.d.ts +26 -0
- package/dist/esm/support/associations.js +76 -0
- package/dist/esm/support/context/nodes.js +48 -45
- package/dist/esm/support/context/processing.js +6 -3
- package/dist/esm/support/context/snapshot.js +11 -1
- package/dist/esm/support/decorators/index.d.ts +13 -2
- package/dist/esm/support/decorators/index.js +40 -3
- package/dist/esm/support/decorators/pool.d.ts +6 -5
- package/dist/esm/support/decorators/types.d.ts +3 -1
- package/dist/esm/support/index.d.ts +1 -0
- package/dist/esm/support/index.js +1 -0
- package/dist/esm/support/model/capabilities.d.ts +8 -3
- package/dist/esm/support/model/capabilities.js +35 -5
- package/dist/esm/support/model/chat-completions.js +11 -2
- package/dist/esm/support/model/completion/calls.d.ts +6 -34
- package/dist/esm/support/model/completion/calls.js +8 -55
- package/dist/esm/support/model/index.d.ts +1 -1
- package/dist/esm/support/model/preview-rules.d.ts +13 -8
- package/dist/esm/support/model/preview-rules.js +11 -11
- package/dist/esm/support/model/reply-preview.d.ts +2 -2
- package/dist/esm/support/model/reply-preview.js +3 -3
- package/dist/esm/support/model/session.d.ts +61 -0
- package/dist/esm/support/model/session.js +148 -0
- package/dist/esm/support/model/stage-transport.d.ts +1 -1
- package/dist/esm/support/model/stage-transport.js +9 -9
- package/dist/esm/support/model/transports.d.ts +2 -0
- package/dist/esm/support/model/transports.js +2 -1
- package/dist/esm/support/tools.d.ts +11 -3
- package/dist/esm/support/tools.js +43 -18
- package/dist/esm/utils/catalog.d.ts +1 -1
- package/dist/esm/utils/invocation.d.ts +1 -0
- package/dist/esm/utils/invocation.js +1 -0
- package/package.json +20 -6
- package/dist/cjs/execution/index.js +0 -30
- package/dist/cjs/kits/intents/catalog.js +0 -82
- package/dist/cjs/kits/intents/index.js +0 -35
- package/dist/cjs/utils/debug.js +0 -30
- package/dist/esm/execution/index.d.ts +0 -11
- package/dist/esm/execution/index.js +0 -11
- package/dist/esm/kits/intents/catalog.d.ts +0 -39
- package/dist/esm/kits/intents/catalog.js +0 -79
- package/dist/esm/kits/intents/index.d.ts +0 -22
- package/dist/esm/kits/intents/index.js +0 -18
- package/dist/esm/kits/intents/registry.d.ts +0 -88
- package/dist/esm/utils/debug.d.ts +0 -27
- package/dist/esm/utils/debug.js +0 -27
- /package/dist/cjs/structs/{kits/intents/catalog.js → execution/workflow-views.js} +0 -0
- /package/dist/cjs/structs/kits/{intents/registry.js → domains/catalog.js} +0 -0
- /package/dist/cjs/structs/kits/{intents/scopes.js → domains/registry.js} +0 -0
- /package/dist/esm/structs/{kits/intents/catalog.js → execution/workflow-views.js} +0 -0
- /package/dist/esm/structs/kits/{intents/registry.js → domains/catalog.js} +0 -0
- /package/dist/esm/structs/kits/{intents/scopes.js → domains/registry.js} +0 -0
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
# Independent and associated Tool configuration
|
|
2
|
+
|
|
3
|
+
A Tool is the model-facing interface. ExecutableTool adds authorization, execution and output validation. Tool adds one lifecycle block. Intent is Tool metadata, not an independently registered entity. The examples use public in-memory notes and an offline Provider.
|
|
4
|
+
|
|
5
|
+
```text
|
|
6
|
+
Tool declaration → node selects tools → model proposes name and arguments
|
|
7
|
+
→ schema / activation / authorization → execute → validated result
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
## 1. Executable Tool declarations
|
|
11
|
+
|
|
12
|
+
[tools.mjs](../examples/registration/tools.mjs)
|
|
13
|
+
|
|
14
|
+
```js
|
|
15
|
+
/** Tutorial tools: public in-memory notes only; no application database or network access. */
|
|
16
|
+
import { Support } from '@jangts/agent-core';
|
|
17
|
+
|
|
18
|
+
// The two business inputs differ; the model must use the selected tool's schema.
|
|
19
|
+
export function textInput(field) {
|
|
20
|
+
return Support.defineSchema({
|
|
21
|
+
jsonSchema: {
|
|
22
|
+
type: 'object',
|
|
23
|
+
properties: { [field]: { type: 'string', minLength: 1 } },
|
|
24
|
+
required: [field],
|
|
25
|
+
additionalProperties: false,
|
|
26
|
+
},
|
|
27
|
+
parse(value) {
|
|
28
|
+
if (
|
|
29
|
+
!value ||
|
|
30
|
+
typeof value !== 'object' ||
|
|
31
|
+
Array.isArray(value) ||
|
|
32
|
+
Object.keys(value).length !== 1 ||
|
|
33
|
+
typeof value[field] !== 'string' ||
|
|
34
|
+
!value[field].trim()
|
|
35
|
+
) {
|
|
36
|
+
throw new TypeError(`Expected one nonempty string: ${field}`);
|
|
37
|
+
}
|
|
38
|
+
return { [field]: value[field].trim() };
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const notes = [{ id: 'n1', title: '咖啡烘焙', body: '烘焙程度可结合豆色和风味判断。' }];
|
|
44
|
+
|
|
45
|
+
/** Build fresh declarations so manual and associated examples share no mutable request state. */
|
|
46
|
+
export function toolDefinitions() {
|
|
47
|
+
return [
|
|
48
|
+
{
|
|
49
|
+
id: 'search_notes',
|
|
50
|
+
asIntent: '用户希望查找笔记',
|
|
51
|
+
kind: 'read',
|
|
52
|
+
description: '按主题检索公开笔记',
|
|
53
|
+
inputSchema: textInput('query'),
|
|
54
|
+
authorize() {}, // This tutorial uses public constants, with no private account data.
|
|
55
|
+
execute({ query }) {
|
|
56
|
+
return notes
|
|
57
|
+
.filter((note) => note.title.includes(query))
|
|
58
|
+
.map(({ id, title }) => ({ id, title }));
|
|
59
|
+
},
|
|
60
|
+
parseOutput(value) {
|
|
61
|
+
if (
|
|
62
|
+
!Array.isArray(value) ||
|
|
63
|
+
value.some((note) => typeof note?.id !== 'string' || typeof note.title !== 'string')
|
|
64
|
+
) {
|
|
65
|
+
throw new TypeError('Invalid search result');
|
|
66
|
+
}
|
|
67
|
+
return value;
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: 'read_note',
|
|
72
|
+
kind: 'read',
|
|
73
|
+
description: '读取已定位笔记的正文',
|
|
74
|
+
inputSchema: textInput('noteId'),
|
|
75
|
+
authorize() {},
|
|
76
|
+
execute({ noteId }) {
|
|
77
|
+
const note = notes.find((note) => note.id === noteId);
|
|
78
|
+
if (!note) throw new Error('Note not found');
|
|
79
|
+
return { ...note };
|
|
80
|
+
},
|
|
81
|
+
parseOutput(value) {
|
|
82
|
+
if (!value || typeof value.body !== 'string') {
|
|
83
|
+
throw new TypeError('Invalid note body');
|
|
84
|
+
}
|
|
85
|
+
return value;
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
];
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## 2. Independent model and execution interfaces
|
|
93
|
+
|
|
94
|
+
[independent.mjs](../examples/registration/independent.mjs)
|
|
95
|
+
|
|
96
|
+
Model declarations propose `{ toolId, input }`; they do not execute business handlers.
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
/** Independent model and execution declarations, connected through checked Tool IDs. */
|
|
100
|
+
import { Support } from '@jangts/agent-core';
|
|
101
|
+
import { toolDefinitions, textInput } from './tools.mjs';
|
|
102
|
+
|
|
103
|
+
export function independentConfiguration() {
|
|
104
|
+
const execution = Support.defineToolCatalog(toolDefinitions());
|
|
105
|
+
const tools = Support.defineModelTools([
|
|
106
|
+
{
|
|
107
|
+
id: 'search_notes', description: '按主题检索公开笔记', asIntent: '用户希望查找笔记',
|
|
108
|
+
inputSchema: { jsonSchema: textInput('query').jsonSchema, parse: value => value },
|
|
109
|
+
resolve: input => ({ toolId: 'search_notes', input }),
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
id: 'read_note', description: '读取已定位笔记的正文',
|
|
113
|
+
inputSchema: { jsonSchema: textInput('noteId').jsonSchema, parse: value => value },
|
|
114
|
+
resolve: input => ({ toolId: 'read_note', input }),
|
|
115
|
+
},
|
|
116
|
+
]);
|
|
117
|
+
return { execution, tools };
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## 3. One declaration supplies both interfaces
|
|
122
|
+
|
|
123
|
+
[associated.mjs](../examples/registration/associated.mjs)
|
|
124
|
+
|
|
125
|
+
The catalog derives names, descriptions, schemas and invocation mapping. This avoids re-declaring them. It does not skip authorization or execution validation.
|
|
126
|
+
|
|
127
|
+
```js
|
|
128
|
+
/** One executable Tool declaration supplies both model and execution contracts. */
|
|
129
|
+
import { Support } from '@jangts/agent-core';
|
|
130
|
+
import { toolDefinitions } from './tools.mjs';
|
|
131
|
+
|
|
132
|
+
export function associatedConfiguration() {
|
|
133
|
+
const execution = Support.defineToolCatalog(toolDefinitions());
|
|
134
|
+
return { execution, tools: execution.tools };
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## 4. Node, context, transport and execution
|
|
139
|
+
|
|
140
|
+
[workflow.mjs](../examples/registration/workflow.mjs)
|
|
141
|
+
|
|
142
|
+
```js
|
|
143
|
+
/** One runtime for both configuration styles; its Provider is a fixed offline fixture. */
|
|
144
|
+
import { AgentCoreEngine, Support, defineWorkflow, route } from '@jangts/agent-core';
|
|
145
|
+
|
|
146
|
+
const context = Support.defineContextFragments(
|
|
147
|
+
[
|
|
148
|
+
{
|
|
149
|
+
id: 'task-policy',
|
|
150
|
+
sourceId: 'tutorial',
|
|
151
|
+
trust: 'instruction',
|
|
152
|
+
lifetime: 'configuration',
|
|
153
|
+
role: 'system',
|
|
154
|
+
maxChars: 500,
|
|
155
|
+
format: () => '按用户需求选择一个已提供的能力并提交参数。操作结果由程序返回。',
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
id: 'tool-catalog',
|
|
159
|
+
sourceId: 'tool-registry',
|
|
160
|
+
trust: 'server',
|
|
161
|
+
lifetime: 'step',
|
|
162
|
+
role: 'user',
|
|
163
|
+
maxChars: 6000,
|
|
164
|
+
format: ({ tools }) => ({ tools: [...tools.values()].map(({id, description}) => ({id, description})) }),
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
id: 'question',
|
|
168
|
+
sourceId: 'user-message',
|
|
169
|
+
trust: 'user',
|
|
170
|
+
lifetime: 'turn',
|
|
171
|
+
role: 'user',
|
|
172
|
+
maxChars: 1000,
|
|
173
|
+
format: ({ question }) => ({ question }),
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
{ maxInputChars: 8000 },
|
|
177
|
+
);
|
|
178
|
+
|
|
179
|
+
/** Stage policy selects candidates; association does not automatically submit every registration. */
|
|
180
|
+
export function taskTransport(tools, toolIds = ['search_notes', 'read_note']) {
|
|
181
|
+
return Support.createStageModelTransport({
|
|
182
|
+
id: 'task',
|
|
183
|
+
tools,
|
|
184
|
+
stages: [{ id: 'choose-operation', toolIds }],
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const workflow = defineWorkflow({
|
|
189
|
+
id: 'notes-request',
|
|
190
|
+
nodes: [
|
|
191
|
+
{
|
|
192
|
+
id: 'decide',
|
|
193
|
+
description: '组织上下文,让模型提出一次操作',
|
|
194
|
+
async run(state, { model, app }) {
|
|
195
|
+
const input = context.build({
|
|
196
|
+
input: {
|
|
197
|
+
question: state.question,
|
|
198
|
+
tools: app.tools,
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
const { value: proposal } = await model.invoke({
|
|
202
|
+
stageId: 'choose-operation',
|
|
203
|
+
transport: 'task',
|
|
204
|
+
input,
|
|
205
|
+
});
|
|
206
|
+
return { proposal };
|
|
207
|
+
},
|
|
208
|
+
routes: [route.to('execute')],
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
id: 'execute',
|
|
212
|
+
description: '经过工具合同执行提议,取得真实结果',
|
|
213
|
+
async run(state, { tools }) {
|
|
214
|
+
const { value: result } = await tools.invoke(state.proposal);
|
|
215
|
+
return { result };
|
|
216
|
+
},
|
|
217
|
+
routes: [route.deliver('result')],
|
|
218
|
+
},
|
|
219
|
+
],
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
/** The chosen reply is fixture input, not a language-understanding implementation. */
|
|
223
|
+
export async function runCase(configuration, question, proposedName, proposedInput) {
|
|
224
|
+
const submitted = [];
|
|
225
|
+
const provider = {
|
|
226
|
+
async *stream(messages, { options }) {
|
|
227
|
+
submitted.push({ messages, functions: options.functions });
|
|
228
|
+
if (!options.functions.some((fn) => fn.name === proposedName)) {
|
|
229
|
+
throw new Error('Fixture attempted an unavailable capability');
|
|
230
|
+
}
|
|
231
|
+
yield {
|
|
232
|
+
type: 'function-call-delta',
|
|
233
|
+
index: 0,
|
|
234
|
+
id: 'offline-call',
|
|
235
|
+
name: proposedName,
|
|
236
|
+
arguments: JSON.stringify(proposedInput),
|
|
237
|
+
};
|
|
238
|
+
},
|
|
239
|
+
};
|
|
240
|
+
const agent = new AgentCoreEngine({
|
|
241
|
+
workflow,
|
|
242
|
+
app: { tools: configuration.tools },
|
|
243
|
+
tools: configuration.execution.bind({ app: {} }),
|
|
244
|
+
model: {
|
|
245
|
+
provider,
|
|
246
|
+
transports: [taskTransport(configuration.tools, configuration.candidateIds)],
|
|
247
|
+
maxCalls: 1,
|
|
248
|
+
},
|
|
249
|
+
});
|
|
250
|
+
return { result: await agent.run({ question }), submitted };
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## 5. A name/input envelope reuses the same tools
|
|
255
|
+
|
|
256
|
+
[protocol.mjs](../examples/registration/protocol.mjs)
|
|
257
|
+
|
|
258
|
+
```js
|
|
259
|
+
/** A name/input envelope changes model output format while preserving the same tool proposal. */
|
|
260
|
+
import { Support } from '@jangts/agent-core';
|
|
261
|
+
|
|
262
|
+
export function wrappedConfiguration(configuration) {
|
|
263
|
+
const capability = {
|
|
264
|
+
id: 'tool_request',
|
|
265
|
+
description: '提交工具名称和参数,由程序执行',
|
|
266
|
+
inputSchema: Support.defineSchema({
|
|
267
|
+
jsonSchema: {
|
|
268
|
+
type: 'object',
|
|
269
|
+
required: ['name', 'input'],
|
|
270
|
+
additionalProperties: false,
|
|
271
|
+
properties: {
|
|
272
|
+
name: { type: 'string', enum: configuration.tools.ids() },
|
|
273
|
+
input: { type: 'object' },
|
|
274
|
+
},
|
|
275
|
+
anyOf: configuration.tools.definitions.map((tool) => ({
|
|
276
|
+
properties: {
|
|
277
|
+
name: { const: tool.id },
|
|
278
|
+
input: tool.inputSchema.jsonSchema,
|
|
279
|
+
},
|
|
280
|
+
})),
|
|
281
|
+
},
|
|
282
|
+
parse(value) {
|
|
283
|
+
if (
|
|
284
|
+
!value ||
|
|
285
|
+
typeof value !== 'object' ||
|
|
286
|
+
Array.isArray(value) ||
|
|
287
|
+
Object.keys(value).some((key) => key !== 'name' && key !== 'input') ||
|
|
288
|
+
typeof value.name !== 'string' ||
|
|
289
|
+
!value.input ||
|
|
290
|
+
typeof value.input !== 'object' ||
|
|
291
|
+
Array.isArray(value.input)
|
|
292
|
+
) {
|
|
293
|
+
throw new TypeError('Expected { name, input }');
|
|
294
|
+
}
|
|
295
|
+
configuration.tools.require(value.name);
|
|
296
|
+
return value;
|
|
297
|
+
},
|
|
298
|
+
}),
|
|
299
|
+
resolve: ({ name, input }) => ({ toolId: name, input }),
|
|
300
|
+
};
|
|
301
|
+
return {
|
|
302
|
+
...configuration,
|
|
303
|
+
tools: Support.defineModelTools([capability]),
|
|
304
|
+
candidateIds: ['tool_request'],
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
## 6. Offline equivalence checks
|
|
310
|
+
|
|
311
|
+
[run.mjs](../examples/registration/run.mjs)
|
|
312
|
+
|
|
313
|
+
```js
|
|
314
|
+
/** Run the tutorial offline and check that both configuration styles produce equivalent contracts. */
|
|
315
|
+
import assert from 'node:assert/strict';
|
|
316
|
+
import { independentConfiguration } from './independent.mjs';
|
|
317
|
+
import { associatedConfiguration } from './associated.mjs';
|
|
318
|
+
import { runCase, taskTransport } from './workflow.mjs';
|
|
319
|
+
import { wrappedConfiguration } from './protocol.mjs';
|
|
320
|
+
|
|
321
|
+
const separate = independentConfiguration();
|
|
322
|
+
const linked = associatedConfiguration();
|
|
323
|
+
assert.deepEqual(linked.tools.withIntent({}).ids(), separate.tools.withIntent({}).ids());
|
|
324
|
+
const rawFunctions = (configuration) =>
|
|
325
|
+
taskTransport(configuration.tools).prepare('choose-operation').options.functions;
|
|
326
|
+
assert.deepEqual(rawFunctions(linked), rawFunctions(separate));
|
|
327
|
+
assert.deepEqual(
|
|
328
|
+
linked.tools.resolve(
|
|
329
|
+
{ toolId: 'search_notes', input: { query: ' 咖啡 ' } },
|
|
330
|
+
{ stageId: 'choose-operation' },
|
|
331
|
+
),
|
|
332
|
+
separate.tools.resolve(
|
|
333
|
+
{ toolId: 'search_notes', input: { query: ' 咖啡 ' } },
|
|
334
|
+
{ stageId: 'choose-operation' },
|
|
335
|
+
),
|
|
336
|
+
);
|
|
337
|
+
for (const [question, name, input] of [
|
|
338
|
+
['帮我找咖啡相关的笔记', 'search_notes', { query: '咖啡' }],
|
|
339
|
+
['读一下n1这篇笔记', 'read_note', { noteId: 'n1' }],
|
|
340
|
+
]) {
|
|
341
|
+
const a = await runCase(separate, question, name, input);
|
|
342
|
+
const b = await runCase(linked, question, name, input);
|
|
343
|
+
assert.deepEqual(a.submitted, b.submitted);
|
|
344
|
+
assert.deepEqual(a.result, b.result);
|
|
345
|
+
console.log(JSON.stringify({ question, result: b.result }));
|
|
346
|
+
}
|
|
347
|
+
const a = await runCase(wrappedConfiguration(separate), '帮我找咖啡相关的笔记', 'tool_request', {
|
|
348
|
+
name: 'search_notes',
|
|
349
|
+
input: { query: '咖啡' },
|
|
350
|
+
});
|
|
351
|
+
const b = await runCase(wrappedConfiguration(linked), '帮我找咖啡相关的笔记', 'tool_request', {
|
|
352
|
+
name: 'search_notes',
|
|
353
|
+
input: { query: '咖啡' },
|
|
354
|
+
});
|
|
355
|
+
assert.deepEqual(a.submitted, b.submitted);
|
|
356
|
+
assert.deepEqual(a.result, b.result);
|
|
357
|
+
console.log(
|
|
358
|
+
'PASS: discovery, model functions, messages and execution results match.',
|
|
359
|
+
);
|
|
360
|
+
console.log('PASS: name/input envelope uses the same workflow and execution contract.');
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
## Demand discovery and activation
|
|
364
|
+
|
|
365
|
+
```ts
|
|
366
|
+
const tools = Support.defineModelTools([{
|
|
367
|
+
id: "manage_memo",
|
|
368
|
+
description: "Process a memo draft and check conflicts",
|
|
369
|
+
inputSchema: memoSchema,
|
|
370
|
+
asIntent: {
|
|
371
|
+
description: "The user wants to remember something or set a reminder",
|
|
372
|
+
when: context => context.features.memos,
|
|
373
|
+
},
|
|
374
|
+
active: context => context.services.memos != null,
|
|
375
|
+
resolve: input => input,
|
|
376
|
+
}]);
|
|
377
|
+
const candidates = tools.withIntent(context);
|
|
378
|
+
const known = tools.select(["manage_memo"], context);
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
`asIntent` accepts `true`, a description, a boolean predicate, or `{ description?, when?, delegates? }`. Omission excludes the tool from discovery; `active` defaults to true. Both selection methods filter activation. Discovery descriptions are view-local. Delegates are an optional allowed set, not a sequence; domain registries validate the vocabulary. No Intent IDs or cross-tool description aggregation are created.
|
|
382
|
+
|
|
383
|
+
## Decorator configuration
|
|
384
|
+
|
|
385
|
+
```ts
|
|
386
|
+
@Intent({ description: "Accept memo requests", delegates: ["read", "final"] })
|
|
387
|
+
@WorkflowTool("manage_memo", { ns: "assistant" })
|
|
388
|
+
class MemoTool {
|
|
389
|
+
description = "Process a memo request";
|
|
390
|
+
inputSchema = memoSchema;
|
|
391
|
+
resolve(input) { return input; }
|
|
392
|
+
}
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
Import decorators from `@jangts/agent-core/support/decorators`. `@WorkflowTool` supports classes and public instance methods, like `@WorkflowNode`. Use a separate `@Intent` on the same target; it alone registers nothing. Do not pass `asIntent` to the Tool decorator or its definition. Decorator order does not affect the association.
|
|
396
|
+
|
|
397
|
+
## Run the example
|
|
398
|
+
|
|
399
|
+
```sh
|
|
400
|
+
node packages/agent-core/development/docs/examples/registration/run.mjs
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
The fixture checks wiring and contract equivalence, not language understanding or real-provider quality. Cafe preserves its grouped goal/next decision protocol; goal identifies a GoalTool. Banker projects current Tool candidates into its name/input protocol. Both use the same Core Tool contracts without forcing identical business workflows.
|