@memberjunction/ai-agents 6.2.0-edge.5 → 6.2.0-edge.7
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/README.md +89 -2
- package/dist/AgentDataPreloader.d.ts +4 -2
- package/dist/AgentDataPreloader.d.ts.map +1 -1
- package/dist/AgentDataPreloader.js +21 -12
- package/dist/AgentDataPreloader.js.map +1 -1
- package/dist/AgentRunner.d.ts +150 -5
- package/dist/AgentRunner.d.ts.map +1 -1
- package/dist/AgentRunner.js +588 -64
- package/dist/AgentRunner.js.map +1 -1
- package/dist/AgentWakeTriggerService.d.ts +183 -0
- package/dist/AgentWakeTriggerService.d.ts.map +1 -0
- package/dist/AgentWakeTriggerService.js +485 -0
- package/dist/AgentWakeTriggerService.js.map +1 -0
- package/dist/ArtifactToolManager.d.ts +1 -0
- package/dist/ArtifactToolManager.d.ts.map +1 -1
- package/dist/ArtifactToolManager.js +5 -0
- package/dist/ArtifactToolManager.js.map +1 -1
- package/dist/ConversationToolManager.d.ts +1 -1
- package/dist/ConversationToolManager.d.ts.map +1 -1
- package/dist/ConversationToolManager.js +10 -4
- package/dist/ConversationToolManager.js.map +1 -1
- package/dist/MJAIAgentRequestEntityServer.d.ts +15 -1
- package/dist/MJAIAgentRequestEntityServer.d.ts.map +1 -1
- package/dist/MJAIAgentRequestEntityServer.js +63 -3
- package/dist/MJAIAgentRequestEntityServer.js.map +1 -1
- package/dist/agent-context-injector.d.ts +21 -4
- package/dist/agent-context-injector.d.ts.map +1 -1
- package/dist/agent-context-injector.js +49 -13
- package/dist/agent-context-injector.js.map +1 -1
- package/dist/agent-memory-context-builder.js +2 -2
- package/dist/agent-memory-context-builder.js.map +1 -1
- package/dist/agent-pre-execution-rag.d.ts.map +1 -1
- package/dist/agent-pre-execution-rag.js +6 -8
- package/dist/agent-pre-execution-rag.js.map +1 -1
- package/dist/agent-run-watchdog.d.ts +71 -18
- package/dist/agent-run-watchdog.d.ts.map +1 -1
- package/dist/agent-run-watchdog.js +223 -90
- package/dist/agent-run-watchdog.js.map +1 -1
- package/dist/agent-types/flow-agent-type.d.ts +13 -0
- package/dist/agent-types/flow-agent-type.d.ts.map +1 -1
- package/dist/agent-types/flow-agent-type.js +165 -27
- package/dist/agent-types/flow-agent-type.js.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.d.ts +32 -5
- package/dist/agent-types/loop-agent-prompt-params.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-prompt-params.js +5 -3
- package/dist/agent-types/loop-agent-prompt-params.js.map +1 -1
- package/dist/agent-types/loop-agent-response-type.d.ts +35 -4
- package/dist/agent-types/loop-agent-response-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-response-type.js +1 -1
- package/dist/agent-types/loop-agent-response-type.js.map +1 -1
- package/dist/agent-types/loop-agent-type.d.ts +103 -9
- package/dist/agent-types/loop-agent-type.d.ts.map +1 -1
- package/dist/agent-types/loop-agent-type.js +351 -68
- package/dist/agent-types/loop-agent-type.js.map +1 -1
- package/dist/base-agent.d.ts +551 -44
- package/dist/base-agent.d.ts.map +1 -1
- package/dist/base-agent.js +2742 -549
- package/dist/base-agent.js.map +1 -1
- package/dist/bound-action-params.d.ts +57 -0
- package/dist/bound-action-params.d.ts.map +1 -0
- package/dist/bound-action-params.js +91 -0
- package/dist/bound-action-params.js.map +1 -0
- package/dist/catalog-narrowing.d.ts.map +1 -1
- package/dist/catalog-narrowing.js +6 -3
- package/dist/catalog-narrowing.js.map +1 -1
- package/dist/handoff-target.d.ts +80 -0
- package/dist/handoff-target.d.ts.map +1 -0
- package/dist/handoff-target.js +158 -0
- package/dist/handoff-target.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/memory-cleanup-agent.d.ts.map +1 -1
- package/dist/memory-cleanup-agent.js +3 -0
- package/dist/memory-cleanup-agent.js.map +1 -1
- package/dist/memory-manager-agent.d.ts.map +1 -1
- package/dist/memory-manager-agent.js +8 -1
- package/dist/memory-manager-agent.js.map +1 -1
- package/dist/native-tools/action-tool-builder.d.ts +6 -0
- package/dist/native-tools/action-tool-builder.d.ts.map +1 -1
- package/dist/native-tools/action-tool-builder.js +21 -5
- package/dist/native-tools/action-tool-builder.js.map +1 -1
- package/dist/native-tools/agent-tools.d.ts +64 -0
- package/dist/native-tools/agent-tools.d.ts.map +1 -0
- package/dist/native-tools/agent-tools.js +23 -0
- package/dist/native-tools/agent-tools.js.map +1 -0
- package/dist/native-tools/control-tools.d.ts +40 -7
- package/dist/native-tools/control-tools.d.ts.map +1 -1
- package/dist/native-tools/control-tools.js +139 -50
- package/dist/native-tools/control-tools.js.map +1 -1
- package/dist/native-tools/framework-tools.d.ts +47 -0
- package/dist/native-tools/framework-tools.d.ts.map +1 -0
- package/dist/native-tools/framework-tools.js +187 -0
- package/dist/native-tools/framework-tools.js.map +1 -0
- package/dist/native-tools/native-control-config.d.ts +93 -0
- package/dist/native-tools/native-control-config.d.ts.map +1 -0
- package/dist/native-tools/native-control-config.js +104 -0
- package/dist/native-tools/native-control-config.js.map +1 -0
- package/dist/native-tools/tool-result-turns.d.ts +41 -8
- package/dist/native-tools/tool-result-turns.d.ts.map +1 -1
- package/dist/native-tools/tool-result-turns.js +76 -2
- package/dist/native-tools/tool-result-turns.js.map +1 -1
- package/dist/native-tools/turn-mode.d.ts +8 -0
- package/dist/native-tools/turn-mode.d.ts.map +1 -0
- package/dist/native-tools/turn-mode.js +14 -0
- package/dist/native-tools/turn-mode.js.map +1 -0
- package/dist/pipeline/pipeline-registry.d.ts +5 -12
- package/dist/pipeline/pipeline-registry.d.ts.map +1 -1
- package/dist/pipeline/pipeline-registry.js +28 -2
- package/dist/pipeline/pipeline-registry.js.map +1 -1
- package/dist/pipeline/providers/serialize.d.ts +7 -3
- package/dist/pipeline/providers/serialize.d.ts.map +1 -1
- package/dist/pipeline/providers/serialize.js +9 -5
- package/dist/pipeline/providers/serialize.js.map +1 -1
- package/dist/query-builder-agent.d.ts +20 -1
- package/dist/query-builder-agent.d.ts.map +1 -1
- package/dist/query-builder-agent.js +35 -3
- package/dist/query-builder-agent.js.map +1 -1
- package/dist/realtime/bridge-room-transcript-sink.js +3 -0
- package/dist/realtime/bridge-room-transcript-sink.js.map +1 -1
- package/dist/realtime/bridge-session-transcript-sink.js +1 -0
- package/dist/realtime/bridge-session-transcript-sink.js.map +1 -1
- package/dist/realtime/realtime-client-session-service.d.ts +22 -2
- package/dist/realtime/realtime-client-session-service.d.ts.map +1 -1
- package/dist/realtime/realtime-client-session-service.js +70 -10
- package/dist/realtime/realtime-client-session-service.js.map +1 -1
- package/dist/realtime/realtime-coagent-config.d.ts.map +1 -1
- package/dist/realtime/realtime-coagent-config.js +2 -28
- package/dist/realtime/realtime-coagent-config.js.map +1 -1
- package/dist/realtime/realtime-recording-capture.d.ts +1 -0
- package/dist/realtime/realtime-recording-capture.d.ts.map +1 -1
- package/dist/realtime/realtime-recording-capture.js +17 -3
- package/dist/realtime/realtime-recording-capture.js.map +1 -1
- package/dist/realtime/realtime-recording-ledger.d.ts +20 -0
- package/dist/realtime/realtime-recording-ledger.d.ts.map +1 -1
- package/dist/realtime/realtime-recording-ledger.js +16 -0
- package/dist/realtime/realtime-recording-ledger.js.map +1 -1
- package/dist/realtime/realtime-recording-opus-assembly.d.ts.map +1 -1
- package/dist/realtime/realtime-recording-opus-assembly.js +9 -4
- package/dist/realtime/realtime-recording-opus-assembly.js.map +1 -1
- package/dist/realtime/realtime-recording-store.d.ts +6 -5
- package/dist/realtime/realtime-recording-store.d.ts.map +1 -1
- package/dist/realtime/realtime-recording-store.js +47 -21
- package/dist/realtime/realtime-recording-store.js.map +1 -1
- package/dist/realtime/realtime-session-runner.d.ts.map +1 -1
- package/dist/realtime/realtime-session-runner.js +5 -7
- package/dist/realtime/realtime-session-runner.js.map +1 -1
- package/dist/realtime/realtime-turn-moderator.d.ts.map +1 -1
- package/dist/realtime/realtime-turn-moderator.js +1 -0
- package/dist/realtime/realtime-turn-moderator.js.map +1 -1
- package/dist/rubric-evaluation-agent-runner.js +1 -0
- package/dist/rubric-evaluation-agent-runner.js.map +1 -1
- package/dist/runtime-state-fragment.d.ts.map +1 -1
- package/dist/runtime-state-fragment.js +3 -0
- package/dist/runtime-state-fragment.js.map +1 -1
- package/dist/sub-agent-consult.d.ts +75 -0
- package/dist/sub-agent-consult.d.ts.map +1 -0
- package/dist/sub-agent-consult.js +193 -0
- package/dist/sub-agent-consult.js.map +1 -0
- package/dist/volatile-child-prompt.d.ts +7 -0
- package/dist/volatile-child-prompt.d.ts.map +1 -1
- package/dist/volatile-child-prompt.js +8 -0
- package/dist/volatile-child-prompt.js.map +1 -1
- package/package.json +20 -20
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
export const SCRATCHPAD_TOOL = 'scratchpad_write';
|
|
2
|
+
export const MEMORY_WRITE_TOOL = 'memory_write';
|
|
3
|
+
export const ARTIFACT_TOOL = 'artifact_tool';
|
|
4
|
+
export const CONVERSATION_TOOL = 'conversation_tool';
|
|
5
|
+
export const DECISION_TOOL = 'ask_decisions';
|
|
6
|
+
/** Every framework tool name — reserved, like the control tools. */
|
|
7
|
+
export const FRAMEWORK_TOOL_NAMES = [SCRATCHPAD_TOOL, MEMORY_WRITE_TOOL, ARTIFACT_TOOL, CONVERSATION_TOOL, DECISION_TOOL];
|
|
8
|
+
const isRecord = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
9
|
+
const fail = (Content) => ({ Content, IsError: true });
|
|
10
|
+
function scratchpadTool(host) {
|
|
11
|
+
return {
|
|
12
|
+
Name: SCRATCHPAD_TOOL,
|
|
13
|
+
Description: 'Write to your private scratchpad: working notes and a task list that persist across your turns and are never shared. '
|
|
14
|
+
+ 'Call this to record reasoning you will need later or to track work items. Keep it lean: it is shown to you on every turn.',
|
|
15
|
+
InputSchema: {
|
|
16
|
+
type: 'object',
|
|
17
|
+
properties: {
|
|
18
|
+
notes: { type: 'string', description: 'Replaces your notes. Omit to leave them as they are.' },
|
|
19
|
+
taskList: {
|
|
20
|
+
type: 'object',
|
|
21
|
+
description: 'Task changes: `upsert` adds or updates tasks by id; `remove` deletes tasks by id.',
|
|
22
|
+
properties: {
|
|
23
|
+
upsert: {
|
|
24
|
+
type: 'array',
|
|
25
|
+
items: {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
id: { type: 'string' },
|
|
29
|
+
title: { type: 'string' },
|
|
30
|
+
status: { type: 'string', enum: ['pending', 'in_progress', 'completed', 'blocked'] },
|
|
31
|
+
notes: { type: 'string' }
|
|
32
|
+
},
|
|
33
|
+
required: ['id', 'title', 'status']
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
remove: { type: 'array', items: { type: 'string' } }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
Execute: async (args) => {
|
|
42
|
+
const changes = readScratchpadChanges(args);
|
|
43
|
+
return typeof changes === 'string' ? fail(changes) : { Content: host.ApplyScratchpad(changes), IsError: false };
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
const TASK_STATUSES = ['pending', 'in_progress', 'completed', 'blocked'];
|
|
48
|
+
/** One task from `taskList.upsert`, or undefined when it lacks an id, a title or a known status. */
|
|
49
|
+
function readTask(raw) {
|
|
50
|
+
if (!isRecord(raw) || typeof raw.id !== 'string' || typeof raw.title !== 'string' || typeof raw.status !== 'string') {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
const status = TASK_STATUSES.find((s) => s === raw.status);
|
|
54
|
+
if (!status) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
return { id: raw.id, title: raw.title, status, ...(typeof raw.notes === 'string' ? { notes: raw.notes } : {}) };
|
|
58
|
+
}
|
|
59
|
+
/** The scratchpad changes in a call's arguments, or a message saying what is wrong with them. */
|
|
60
|
+
function readScratchpadChanges(args) {
|
|
61
|
+
if (args.notes !== undefined && typeof args.notes !== 'string') {
|
|
62
|
+
return 'scratchpad_write.notes must be a string.';
|
|
63
|
+
}
|
|
64
|
+
const list = isRecord(args.taskList) ? args.taskList : {};
|
|
65
|
+
const upsertRaw = Array.isArray(list.upsert) ? list.upsert : [];
|
|
66
|
+
const upsert = upsertRaw.map(readTask);
|
|
67
|
+
if (upsert.some((t) => t === undefined)) {
|
|
68
|
+
return "Every task in taskList.upsert needs an id, a title and a status of 'pending', 'in_progress', 'completed' or 'blocked'.";
|
|
69
|
+
}
|
|
70
|
+
const remove = Array.isArray(list.remove) ? list.remove.filter((id) => typeof id === 'string') : [];
|
|
71
|
+
return {
|
|
72
|
+
...(typeof args.notes === 'string' ? { notes: args.notes } : {}),
|
|
73
|
+
...(upsert.length || remove.length ? { taskList: { upsert: upsert, remove } } : {})
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
function memoryTool(host) {
|
|
77
|
+
return {
|
|
78
|
+
Name: MEMORY_WRITE_TOOL,
|
|
79
|
+
Description: 'Record one durable memory that persists across runs: an atomic, third-person fact such as "User prefers bar charts over pie charts." '
|
|
80
|
+
+ 'Call this the moment the user states a lasting preference or fact. Not for task state (use the scratchpad) and not for instructions.',
|
|
81
|
+
InputSchema: {
|
|
82
|
+
type: 'object',
|
|
83
|
+
properties: {
|
|
84
|
+
note: { type: 'string', description: 'The fact, as one declarative sentence.' },
|
|
85
|
+
type: { type: 'string', enum: ['Preference', 'Context'], description: 'Preference: likes, dislikes, choices. Context: situational facts.' },
|
|
86
|
+
scopeHint: { type: 'string', enum: ['user', 'agent'], description: "Optional. 'agent' stores it without tying it to the current user." }
|
|
87
|
+
},
|
|
88
|
+
required: ['note', 'type']
|
|
89
|
+
},
|
|
90
|
+
Execute: async (args) => {
|
|
91
|
+
const type = args.type === 'Preference' || args.type === 'Context' ? args.type : undefined;
|
|
92
|
+
if (typeof args.note !== 'string' || !args.note.trim() || !type) {
|
|
93
|
+
return fail("memory_write needs a non-empty note and a type of 'Preference' or 'Context'.");
|
|
94
|
+
}
|
|
95
|
+
const scope = args.scopeHint === 'user' || args.scopeHint === 'agent' ? args.scopeHint : undefined;
|
|
96
|
+
return host.WriteMemory(args.note, type, scope);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function artifactTool(host) {
|
|
101
|
+
return {
|
|
102
|
+
Name: ARTIFACT_TOOL,
|
|
103
|
+
Description: 'Run one artifact tool on an artifact listed in Available Artifacts, to explore or inspect it. '
|
|
104
|
+
+ 'Call this with the artifact id (A, B, …), the tool name and its input; the result is returned to you on this turn.',
|
|
105
|
+
InputSchema: {
|
|
106
|
+
type: 'object',
|
|
107
|
+
properties: {
|
|
108
|
+
artifactId: { type: 'string', description: 'The artifact id from Available Artifacts, such as "A".' },
|
|
109
|
+
tool: { type: 'string', description: 'The artifact tool to run, as listed under Artifact Tools.' },
|
|
110
|
+
input: { type: 'object', description: "The tool's input parameters." }
|
|
111
|
+
},
|
|
112
|
+
required: ['artifactId', 'tool']
|
|
113
|
+
},
|
|
114
|
+
Execute: async (args) => {
|
|
115
|
+
if (typeof args.artifactId !== 'string' || typeof args.tool !== 'string') {
|
|
116
|
+
return fail('artifact_tool needs an artifactId and a tool name.');
|
|
117
|
+
}
|
|
118
|
+
return host.RunArtifactTool(args.artifactId, args.tool, isRecord(args.input) ? args.input : {});
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
function conversationTool(host) {
|
|
123
|
+
return {
|
|
124
|
+
Name: CONVERSATION_TOOL,
|
|
125
|
+
Description: 'Read stored conversation history: page exact messages back in by sequence number, search the history, or summarize a range. '
|
|
126
|
+
+ 'Call this when you need exact wording, identifiers or numbers that a summary may have lost.',
|
|
127
|
+
InputSchema: {
|
|
128
|
+
type: 'object',
|
|
129
|
+
properties: {
|
|
130
|
+
tool: { type: 'string', enum: ['getMessageBySequence', 'getMessagesByRange', 'searchConversation', 'summarizeRange'] },
|
|
131
|
+
input: { type: 'object', description: 'The input for that tool, as listed under Conversation History Tools.' }
|
|
132
|
+
},
|
|
133
|
+
required: ['tool', 'input']
|
|
134
|
+
},
|
|
135
|
+
Execute: async (args) => {
|
|
136
|
+
if (typeof args.tool !== 'string') {
|
|
137
|
+
return fail('conversation_tool needs a tool name.');
|
|
138
|
+
}
|
|
139
|
+
return host.RunConversationTool(args.tool, isRecord(args.input) ? args.input : {});
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function decisionTool(host) {
|
|
144
|
+
return {
|
|
145
|
+
Name: DECISION_TOOL,
|
|
146
|
+
Description: 'Ask typed decision questions (Likelihood, Choice, Score) answered by a fast decision model; the answers are returned to you on this turn. '
|
|
147
|
+
+ 'Call this for classification, triage, relevance or threshold judgments over a small answer space — not for writing or open-ended reasoning.',
|
|
148
|
+
InputSchema: {
|
|
149
|
+
type: 'object',
|
|
150
|
+
properties: {
|
|
151
|
+
decisions: {
|
|
152
|
+
type: 'array',
|
|
153
|
+
description: 'Decision requests, the same shape as described under Decisions.',
|
|
154
|
+
items: { type: 'object' }
|
|
155
|
+
}
|
|
156
|
+
},
|
|
157
|
+
required: ['decisions']
|
|
158
|
+
},
|
|
159
|
+
Execute: async (args, context) => {
|
|
160
|
+
if (!Array.isArray(args.decisions) || args.decisions.length === 0) {
|
|
161
|
+
return fail('ask_decisions needs a non-empty decisions array.');
|
|
162
|
+
}
|
|
163
|
+
return host.RunDecisions(args.decisions, context.CurrentPayload);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The framework tools this turn offers, in a fixed order.
|
|
169
|
+
*
|
|
170
|
+
* @param host The capabilities behind the tools
|
|
171
|
+
* @param availability Which capabilities are enabled for this agent and turn
|
|
172
|
+
*/
|
|
173
|
+
export function BuildFrameworkTools(host, availability) {
|
|
174
|
+
const tools = [];
|
|
175
|
+
if (availability.Scratchpad)
|
|
176
|
+
tools.push(scratchpadTool(host));
|
|
177
|
+
if (availability.MemoryWrites)
|
|
178
|
+
tools.push(memoryTool(host));
|
|
179
|
+
if (availability.ArtifactTools)
|
|
180
|
+
tools.push(artifactTool(host));
|
|
181
|
+
if (availability.ConversationTools)
|
|
182
|
+
tools.push(conversationTool(host));
|
|
183
|
+
if (availability.Decisions)
|
|
184
|
+
tools.push(decisionTool(host));
|
|
185
|
+
return tools;
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=framework-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"framework-tools.js","sourceRoot":"","sources":["../../src/native-tools/framework-tools.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAC,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAClD,MAAM,CAAC,MAAM,iBAAiB,GAAG,cAAc,CAAC;AAChD,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC;AAC7C,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,CAAC;AACrD,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC;AAC7C,oEAAoE;AACpE,MAAM,CAAC,MAAM,oBAAoB,GAAsB,CAAC,eAAe,EAAE,iBAAiB,EAAE,aAAa,EAAE,iBAAiB,EAAE,aAAa,CAAC,CAAC;AAoB7I,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CAAC,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC5I,MAAM,IAAI,GAAG,CAAC,OAAe,EAAmB,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAEhF,SAAS,cAAc,CAAC,IAAuB;IAC3C,OAAO;QACH,IAAI,EAAE,eAAe;QACrB,WAAW,EAAE,uHAAuH;cAC9H,2HAA2H;QACjI,WAAW,EAAE;YACT,IAAI,EAAE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C,CAAC;IAC3D,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Per-agent configuration of the native control tools, read from the agent's
|
|
3
|
+
* `TypeConfiguration` JSON under a `NativeControl` key:
|
|
4
|
+
*
|
|
5
|
+
* ```json
|
|
6
|
+
* { "NativeControl": { "PayloadChangeTool": false, "Terminal": "text", "AskUser": true, "CompleteTaskPayload": "object", "NativeOnly": true } }
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* Every field is optional, and an agent with no `NativeControl` block keeps the default control
|
|
10
|
+
* set: `payload_change_request`, `ask_user` and `complete_task`, with the final permitted turn
|
|
11
|
+
* forced to `complete_task`.
|
|
12
|
+
* @module @memberjunction/ai-agents
|
|
13
|
+
*/
|
|
14
|
+
/** How a native-mode run ends. */
|
|
15
|
+
export type NativeTerminalMode =
|
|
16
|
+
/** `complete_task` is declared, and the final permitted turn is forced to call it. */
|
|
17
|
+
'tool'
|
|
18
|
+
/**
|
|
19
|
+
* A plain-text reply ends the run. `complete_task` is not declared, and the final permitted turn
|
|
20
|
+
* uses `toolChoice: 'none'`, so the model answers instead of calling a tool it could not see
|
|
21
|
+
* the result of.
|
|
22
|
+
*/
|
|
23
|
+
| 'text';
|
|
24
|
+
/** How `complete_task` declares its `payloadChangeRequest` parameter. */
|
|
25
|
+
export type CompleteTaskPayloadForm =
|
|
26
|
+
/**
|
|
27
|
+
* A JSON object string the loop decodes. The default: a forced, schema-constrained call can
|
|
28
|
+
* only decode an object whose sections declare no properties as `{}`, which loses the change.
|
|
29
|
+
*/
|
|
30
|
+
'string'
|
|
31
|
+
/** An object parameter — no JSON inside a JSON string. For agents whose final turn is not forced. */
|
|
32
|
+
| 'object';
|
|
33
|
+
/** The resolved native control configuration for one agent. */
|
|
34
|
+
export interface NativeControlConfig {
|
|
35
|
+
/**
|
|
36
|
+
* Whether `payload_change_request` is declared, and `complete_task` carries a payload change.
|
|
37
|
+
* Off for an agent whose state changes go through its own tools.
|
|
38
|
+
*/
|
|
39
|
+
PayloadChangeTool: boolean;
|
|
40
|
+
/** Whether `ask_user` is declared. */
|
|
41
|
+
AskUser: boolean;
|
|
42
|
+
Terminal: NativeTerminalMode;
|
|
43
|
+
CompleteTaskPayload: CompleteTaskPayloadForm;
|
|
44
|
+
/**
|
|
45
|
+
* One control plane. When the selected model runs implicit control flow, the system prompt
|
|
46
|
+
* teaches tools only — no JSON envelope — and the scratchpad, durable memory, artifact tools,
|
|
47
|
+
* conversation-history tools and decisions are declared as tools. Capabilities that exist only
|
|
48
|
+
* as envelope steps (ForEach, While, Pipeline, Skill, Plan, Tasks, ClientTools, message
|
|
49
|
+
* expansion, UI commands) are unavailable in this mode; an agent that needs them keeps this off.
|
|
50
|
+
* Ignored for a model on the hybrid or envelope path, which keeps the hybrid prompt.
|
|
51
|
+
*/
|
|
52
|
+
NativeOnly: boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Shorten large string arguments of older tool calls in the history sent back to the model —
|
|
55
|
+
* a write tool's whole document otherwise travels on every later turn. The two most recent
|
|
56
|
+
* call turns are always kept whole. See `CompactAnsweredToolCallArguments`.
|
|
57
|
+
*/
|
|
58
|
+
CompactToolArguments: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Let one tool-call turn mix calls the default routing asks to be made on turns of their own:
|
|
61
|
+
* writes (agent tools, several `payload_change_request` calls) before `ask_user` or
|
|
62
|
+
* `complete_task`, and Actions beside a delegation or `ask_user`. Writes run first, in call
|
|
63
|
+
* order; a delegation, question or completion that came with Actions is answered as not run,
|
|
64
|
+
* for the model to make again once it has read their results. Off by default: each such turn
|
|
65
|
+
* is a Retry that runs nothing.
|
|
66
|
+
*/
|
|
67
|
+
RelaxedTurnShapes: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The prompt-data key a native-only agent sets. The Loop system prompt renders its tools-only form
|
|
71
|
+
* when this is set and the runner resolved implicit control flow for the turn.
|
|
72
|
+
*/
|
|
73
|
+
export declare const NATIVE_ONLY_TEMPLATE_FLAG = "_NATIVE_ONLY_REQUESTED";
|
|
74
|
+
/** The prompt-data key carrying a native-only agent's control choices, so its prompt names only the tools it declares. */
|
|
75
|
+
export declare const NATIVE_CONTROL_TEMPLATE_DATA = "_NATIVE_CONTROL";
|
|
76
|
+
/** The control set every agent had before this configuration existed. */
|
|
77
|
+
export declare const DEFAULT_NATIVE_CONTROL_CONFIG: Readonly<NativeControlConfig>;
|
|
78
|
+
/** The resolved configuration, and any field that was present but unusable. */
|
|
79
|
+
export interface NativeControlConfigResult {
|
|
80
|
+
Config: NativeControlConfig;
|
|
81
|
+
/** One entry per ignored value, for the caller to log. Empty when the configuration was clean. */
|
|
82
|
+
Problems: string[];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* The native control configuration in an agent's `TypeConfiguration`.
|
|
86
|
+
*
|
|
87
|
+
* Tolerant by design: a run never fails over this. Anything unusable falls back to its default
|
|
88
|
+
* and is reported in `Problems`, so a typo in one field leaves the others in force.
|
|
89
|
+
*
|
|
90
|
+
* @param typeConfiguration The agent's `TypeConfiguration` column
|
|
91
|
+
*/
|
|
92
|
+
export declare function ResolveNativeControlConfig(typeConfiguration: string | null | undefined): NativeControlConfigResult;
|
|
93
|
+
//# sourceMappingURL=native-control-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-control-config.d.ts","sourceRoot":"","sources":["../../src/native-tools/native-control-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,kCAAkC;AAClC,MAAM,MAAM,kBAAkB;AAC1B,sFAAsF;AACpF,MAAM;AACR;;;;GAIG;GACD,MAAM,CAAC;AAEb,yEAAyE;AACzE,MAAM,MAAM,uBAAuB;AAC/B;;;GAGG;AACD,QAAQ;AACV,qGAAqG;GACnG,QAAQ,CAAC;AAEf,+DAA+D;AAC/D,MAAM,WAAW,mBAAmB;IAChC;;;OAGG;IACH,iBAAiB,EAAE,OAAO,CAAC;IAC3B,sCAAsC;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,QAAQ,EAAE,kBAAkB,CAAC;IAC7B,mBAAmB,EAAE,uBAAuB,CAAC;IAC7C;;;;;;;OAOG;IACH,UAAU,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,oBAAoB,EAAE,OAAO,CAAC;IAC9B;;;;;;;OAOG;IACH,iBAAiB,EAAE,OAAO,CAAC;CAC9B;AAED;;;GAGG;AACH,eAAO,MAAM,yBAAyB,2BAA2B,CAAC;AAElE,0HAA0H;AAC1H,eAAO,MAAM,4BAA4B,oBAAoB,CAAC;AAE9D,yEAAyE;AACzE,eAAO,MAAM,6BAA6B,EAAE,QAAQ,CAAC,mBAAmB,CAQtE,CAAC;AAEH,+EAA+E;AAC/E,MAAM,WAAW,yBAAyB;IACtC,MAAM,EAAE,mBAAmB,CAAC;IAC5B,kGAAkG;IAClG,QAAQ,EAAE,MAAM,EAAE,CAAC;CACtB;AAmDD;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,yBAAyB,CAsBlH"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Per-agent configuration of the native control tools, read from the agent's
|
|
3
|
+
* `TypeConfiguration` JSON under a `NativeControl` key:
|
|
4
|
+
*
|
|
5
|
+
* ```json
|
|
6
|
+
* { "NativeControl": { "PayloadChangeTool": false, "Terminal": "text", "AskUser": true, "CompleteTaskPayload": "object", "NativeOnly": true } }
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
* Every field is optional, and an agent with no `NativeControl` block keeps the default control
|
|
10
|
+
* set: `payload_change_request`, `ask_user` and `complete_task`, with the final permitted turn
|
|
11
|
+
* forced to `complete_task`.
|
|
12
|
+
* @module @memberjunction/ai-agents
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* The prompt-data key a native-only agent sets. The Loop system prompt renders its tools-only form
|
|
16
|
+
* when this is set and the runner resolved implicit control flow for the turn.
|
|
17
|
+
*/
|
|
18
|
+
export const NATIVE_ONLY_TEMPLATE_FLAG = '_NATIVE_ONLY_REQUESTED';
|
|
19
|
+
/** The prompt-data key carrying a native-only agent's control choices, so its prompt names only the tools it declares. */
|
|
20
|
+
export const NATIVE_CONTROL_TEMPLATE_DATA = '_NATIVE_CONTROL';
|
|
21
|
+
/** The control set every agent had before this configuration existed. */
|
|
22
|
+
export const DEFAULT_NATIVE_CONTROL_CONFIG = Object.freeze({
|
|
23
|
+
PayloadChangeTool: true,
|
|
24
|
+
AskUser: true,
|
|
25
|
+
Terminal: 'tool',
|
|
26
|
+
CompleteTaskPayload: 'string',
|
|
27
|
+
NativeOnly: false,
|
|
28
|
+
CompactToolArguments: false,
|
|
29
|
+
RelaxedTurnShapes: false
|
|
30
|
+
});
|
|
31
|
+
function isPlainObject(value) {
|
|
32
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
33
|
+
}
|
|
34
|
+
/** Reads `TypeConfiguration` as JSON; null when absent, an error message when unparseable. */
|
|
35
|
+
function parseTypeConfiguration(json) {
|
|
36
|
+
if (!json || !json.trim()) {
|
|
37
|
+
return { Value: null };
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const parsed = JSON.parse(json);
|
|
41
|
+
return isPlainObject(parsed) ? { Value: parsed } : { Error: 'TypeConfiguration is not a JSON object' };
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
return { Error: `TypeConfiguration is not valid JSON: ${error instanceof Error ? error.message : String(error)}` };
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/** Copies a boolean field when it is one. */
|
|
48
|
+
function readBoolean(raw, key, into, problems) {
|
|
49
|
+
if (raw[key] === undefined) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (typeof raw[key] === 'boolean') {
|
|
53
|
+
into[key] = raw[key];
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
problems.push(`NativeControl.${key} must be true or false; ignored`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/** Copies an enumerated field when its value is one of `allowed`. */
|
|
60
|
+
function readChoice(raw, key, allowed, into, problems) {
|
|
61
|
+
const value = raw[key];
|
|
62
|
+
if (value === undefined) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const match = allowed.find((option) => option === value);
|
|
66
|
+
if (match !== undefined) {
|
|
67
|
+
into[key] = match;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
problems.push(`NativeControl.${key} must be one of ${allowed.map((a) => `'${a}'`).join(', ')}; ignored`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* The native control configuration in an agent's `TypeConfiguration`.
|
|
75
|
+
*
|
|
76
|
+
* Tolerant by design: a run never fails over this. Anything unusable falls back to its default
|
|
77
|
+
* and is reported in `Problems`, so a typo in one field leaves the others in force.
|
|
78
|
+
*
|
|
79
|
+
* @param typeConfiguration The agent's `TypeConfiguration` column
|
|
80
|
+
*/
|
|
81
|
+
export function ResolveNativeControlConfig(typeConfiguration) {
|
|
82
|
+
const config = { ...DEFAULT_NATIVE_CONTROL_CONFIG };
|
|
83
|
+
const problems = [];
|
|
84
|
+
const parsed = parseTypeConfiguration(typeConfiguration);
|
|
85
|
+
if ('Error' in parsed) {
|
|
86
|
+
return { Config: config, Problems: [parsed.Error] };
|
|
87
|
+
}
|
|
88
|
+
const raw = parsed.Value?.NativeControl;
|
|
89
|
+
if (raw === undefined || raw === null) {
|
|
90
|
+
return { Config: config, Problems: problems };
|
|
91
|
+
}
|
|
92
|
+
if (!isPlainObject(raw)) {
|
|
93
|
+
return { Config: config, Problems: ['NativeControl must be an object; ignored'] };
|
|
94
|
+
}
|
|
95
|
+
readBoolean(raw, 'PayloadChangeTool', config, problems);
|
|
96
|
+
readBoolean(raw, 'AskUser', config, problems);
|
|
97
|
+
readBoolean(raw, 'NativeOnly', config, problems);
|
|
98
|
+
readBoolean(raw, 'CompactToolArguments', config, problems);
|
|
99
|
+
readBoolean(raw, 'RelaxedTurnShapes', config, problems);
|
|
100
|
+
readChoice(raw, 'Terminal', ['tool', 'text'], config, problems);
|
|
101
|
+
readChoice(raw, 'CompleteTaskPayload', ['string', 'object'], config, problems);
|
|
102
|
+
return { Config: config, Problems: problems };
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=native-control-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-control-config.js","sourceRoot":"","sources":["../../src/native-tools/native-control-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA4DH;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,wBAAwB,CAAC;AAElE,0HAA0H;AAC1H,MAAM,CAAC,MAAM,4BAA4B,GAAG,iBAAiB,CAAC;AAE9D,yEAAyE;AACzE,MAAM,CAAC,MAAM,6BAA6B,GAAkC,MAAM,CAAC,MAAM,CAAC;IACtF,iBAAiB,EAAE,IAAI;IACvB,OAAO,EAAE,IAAI;IACb,QAAQ,EAAE,MAAM;IAChB,mBAAmB,EAAE,QAAQ;IAC7B,UAAU,EAAE,KAAK;IACjB,oBAAoB,EAAE,KAAK;IAC3B,iBAAiB,EAAE,KAAK;CAC3B,CAAC,CAAC;AASH,SAAS,aAAa,CAAC,KAAc;IACjC,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAChF,CAAC;AAED,8FAA8F;AAC9F,SAAS,sBAAsB,CAAC,IAA+B;IAC3D,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;QACxB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC;IACD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G,EAAE,sBAAsB,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC3D,WAAW,CAAC,GAAG,EAAE,mBAAmB,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IACxD,UAAU,CAAC,GAAG,EAAE,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IAChE,UAAU,CAAC,GAAG,EAAE,qBAAqB,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;IAC/E,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;AAClD,CAAC"}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* answers each call here.
|
|
8
8
|
* @module @memberjunction/ai-agents
|
|
9
9
|
*/
|
|
10
|
-
import type { ChatToolCall } from '@memberjunction/ai';
|
|
10
|
+
import type { ChatToolCall, ChatReasoningBlock } from '@memberjunction/ai';
|
|
11
11
|
import type { AgentChatMessage, AgentChatMessageMetadata } from '@memberjunction/ai-core-plus';
|
|
12
12
|
/** One tool call's outcome, ready to be shown to the model. */
|
|
13
13
|
export interface NativeToolResult {
|
|
@@ -17,16 +17,21 @@ export interface NativeToolResult {
|
|
|
17
17
|
content: string;
|
|
18
18
|
isError: boolean;
|
|
19
19
|
}
|
|
20
|
-
/** The model's
|
|
21
|
-
export
|
|
20
|
+
/** The model's tool-call turn as the loop records it. */
|
|
21
|
+
export interface NativeAssistantTurn {
|
|
22
22
|
text: string;
|
|
23
23
|
toolCalls: ChatToolCall[];
|
|
24
|
-
|
|
24
|
+
/** The provider's reasoning blocks from the turn, when the driver kept any. */
|
|
25
|
+
reasoning?: ChatReasoningBlock[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The model's own turn, replayed into history so the results that follow have something to answer.
|
|
29
|
+
* Its reasoning blocks travel with it: Anthropic asks for a tool-use turn's thinking to come back
|
|
30
|
+
* unchanged, and the driver replays them ahead of the calls.
|
|
31
|
+
*/
|
|
32
|
+
export declare function BuildAssistantToolCallTurn(turn: NativeAssistantTurn): AgentChatMessage;
|
|
25
33
|
/** @deprecated Use {@link BuildAssistantToolCallTurn}. */
|
|
26
|
-
export declare function buildAssistantToolCallTurn(turn:
|
|
27
|
-
text: string;
|
|
28
|
-
toolCalls: ChatToolCall[];
|
|
29
|
-
}): AgentChatMessage;
|
|
34
|
+
export declare function buildAssistantToolCallTurn(turn: NativeAssistantTurn): AgentChatMessage;
|
|
30
35
|
/** One `tool` turn with a `tool_result` block per result, paired to its call by id. */
|
|
31
36
|
export declare function BuildToolResultTurn(results: readonly NativeToolResult[], metadata: AgentChatMessageMetadata | undefined): AgentChatMessage;
|
|
32
37
|
/** @deprecated Use {@link BuildToolResultTurn}. */
|
|
@@ -36,6 +41,34 @@ export declare function buildToolResultTurn(results: readonly NativeToolResult[]
|
|
|
36
41
|
* whose content became a plain string would be rejected by every provider.
|
|
37
42
|
*/
|
|
38
43
|
export declare function CompactToolResultContent(message: AgentChatMessage, compact: (text: string) => string): AgentChatMessage;
|
|
44
|
+
/**
|
|
45
|
+
* {@link CompactToolResultContent} with an asynchronous compactor — for one that calls a model,
|
|
46
|
+
* such as an AI summary. Blocks are compacted one at a time, in order.
|
|
47
|
+
*/
|
|
48
|
+
export declare function CompactToolResultContentAsync(message: AgentChatMessage, compact: (text: string) => Promise<string>): Promise<AgentChatMessage>;
|
|
49
|
+
/** How {@link CompactAnsweredToolCallArguments} decides what to shorten. */
|
|
50
|
+
export interface ToolCallArgumentCompaction {
|
|
51
|
+
/** The most recent call turns left untouched — the model may still be working from them. */
|
|
52
|
+
KeepRecentCallTurns: number;
|
|
53
|
+
/** A string argument shorter than this is kept. */
|
|
54
|
+
MinChars: number;
|
|
55
|
+
}
|
|
56
|
+
/** The defaults for {@link CompactAnsweredToolCallArguments}. */
|
|
57
|
+
export declare const DEFAULT_TOOL_CALL_ARGUMENT_COMPACTION: Readonly<ToolCallArgumentCompaction>;
|
|
58
|
+
/**
|
|
59
|
+
* Shortens the large string arguments of older tool calls in place — a 25k-character `write_file`
|
|
60
|
+
* argument otherwise travels on every later turn.
|
|
61
|
+
*
|
|
62
|
+
* Only call turns older than the most recent `KeepRecentCallTurns` are touched, so every call
|
|
63
|
+
* still being answered or worked from keeps its arguments; the call id, name and small arguments
|
|
64
|
+
* always stay. A compacted turn also loses its provider reasoning and signatures, which were
|
|
65
|
+
* minted for the arguments as sent.
|
|
66
|
+
*
|
|
67
|
+
* @param messages The conversation, changed in place
|
|
68
|
+
* @param options What to shorten
|
|
69
|
+
* @returns How many calls were compacted
|
|
70
|
+
*/
|
|
71
|
+
export declare function CompactAnsweredToolCallArguments(messages: AgentChatMessage[], options?: ToolCallArgumentCompaction): number;
|
|
39
72
|
/** @deprecated Use {@link CompactToolResultContent}. */
|
|
40
73
|
export declare function compactToolResultContent(message: AgentChatMessage, compact: (text: string) => string): AgentChatMessage;
|
|
41
74
|
//# sourceMappingURL=tool-result-turns.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-result-turns.d.ts","sourceRoot":"","sources":["../../src/native-tools/tool-result-turns.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,YAAY,EAA2B,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"tool-result-turns.d.ts","sourceRoot":"","sources":["../../src/native-tools/tool-result-turns.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,YAAY,EAA2B,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACpG,OAAO,KAAK,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAE/F,+DAA+D;AAC/D,MAAM,WAAW,gBAAgB;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,8FAA8F;IAC9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GAYG;AACH,wBAAgB,gCAAgC,CAAC,QAAQ,EAAE,gBAAgB,EAAE,EAAE,OAAO,GAAE,0BAAkE,GAAG,MAAM,CAclK;AAED,wDAAwD;AACxD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,gBAAgB,CAEvH"}
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* The model's own turn, replayed into history so the results that follow have something to answer.
|
|
3
|
+
* Its reasoning blocks travel with it: Anthropic asks for a tool-use turn's thinking to come back
|
|
4
|
+
* unchanged, and the driver replays them ahead of the calls.
|
|
5
|
+
*/
|
|
2
6
|
export function BuildAssistantToolCallTurn(turn) {
|
|
3
|
-
return {
|
|
7
|
+
return {
|
|
8
|
+
role: 'assistant',
|
|
9
|
+
content: turn.text ?? '',
|
|
10
|
+
toolCalls: turn.toolCalls,
|
|
11
|
+
...(turn.reasoning?.length ? { reasoning: turn.reasoning } : {})
|
|
12
|
+
};
|
|
4
13
|
}
|
|
5
14
|
/** @deprecated Use {@link BuildAssistantToolCallTurn}. */
|
|
6
15
|
export function buildAssistantToolCallTurn(turn) {
|
|
@@ -34,6 +43,71 @@ export function CompactToolResultContent(message, compact) {
|
|
|
34
43
|
content: message.content.map((b) => (b.type === 'tool_result' ? { ...b, content: compact(b.content) } : b))
|
|
35
44
|
};
|
|
36
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* {@link CompactToolResultContent} with an asynchronous compactor — for one that calls a model,
|
|
48
|
+
* such as an AI summary. Blocks are compacted one at a time, in order.
|
|
49
|
+
*/
|
|
50
|
+
export async function CompactToolResultContentAsync(message, compact) {
|
|
51
|
+
if (!Array.isArray(message.content)) {
|
|
52
|
+
return { ...message, content: await compact(String(message.content)) };
|
|
53
|
+
}
|
|
54
|
+
const content = [];
|
|
55
|
+
for (const block of message.content) {
|
|
56
|
+
content.push(block.type === 'tool_result' ? { ...block, content: await compact(block.content) } : block);
|
|
57
|
+
}
|
|
58
|
+
return { ...message, content };
|
|
59
|
+
}
|
|
60
|
+
/** The defaults for {@link CompactAnsweredToolCallArguments}. */
|
|
61
|
+
export const DEFAULT_TOOL_CALL_ARGUMENT_COMPACTION = Object.freeze({ KeepRecentCallTurns: 2, MinChars: 2000 });
|
|
62
|
+
/** One call with its large string arguments replaced by a stub; the same call when nothing was large. */
|
|
63
|
+
function compactCallArguments(call, minChars) {
|
|
64
|
+
let changed = false;
|
|
65
|
+
const args = {};
|
|
66
|
+
for (const [key, value] of Object.entries(call.arguments ?? {})) {
|
|
67
|
+
if (typeof value === 'string' && value.length >= minChars) {
|
|
68
|
+
args[key] = `[content omitted: ${value.length.toLocaleString('en-US')} characters sent to ${call.name}]`;
|
|
69
|
+
changed = true;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
args[key] = value;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (!changed) {
|
|
76
|
+
return call;
|
|
77
|
+
}
|
|
78
|
+
// The provider signature was minted for the original arguments. Without it, Gemini replays the
|
|
79
|
+
// call under its documented placeholder signature, which always validates.
|
|
80
|
+
const { providerMetadata: _signed, ...unsigned } = call;
|
|
81
|
+
return { ...unsigned, arguments: args };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Shortens the large string arguments of older tool calls in place — a 25k-character `write_file`
|
|
85
|
+
* argument otherwise travels on every later turn.
|
|
86
|
+
*
|
|
87
|
+
* Only call turns older than the most recent `KeepRecentCallTurns` are touched, so every call
|
|
88
|
+
* still being answered or worked from keeps its arguments; the call id, name and small arguments
|
|
89
|
+
* always stay. A compacted turn also loses its provider reasoning and signatures, which were
|
|
90
|
+
* minted for the arguments as sent.
|
|
91
|
+
*
|
|
92
|
+
* @param messages The conversation, changed in place
|
|
93
|
+
* @param options What to shorten
|
|
94
|
+
* @returns How many calls were compacted
|
|
95
|
+
*/
|
|
96
|
+
export function CompactAnsweredToolCallArguments(messages, options = DEFAULT_TOOL_CALL_ARGUMENT_COMPACTION) {
|
|
97
|
+
const callTurns = messages.map((m, i) => (m.role === 'assistant' && m.toolCalls?.length ? i : -1)).filter((i) => i >= 0);
|
|
98
|
+
let compacted = 0;
|
|
99
|
+
for (const index of callTurns.slice(0, Math.max(0, callTurns.length - options.KeepRecentCallTurns))) {
|
|
100
|
+
const turn = messages[index];
|
|
101
|
+
const calls = (turn.toolCalls ?? []).map((call) => compactCallArguments(call, options.MinChars));
|
|
102
|
+
const changed = calls.filter((call, i) => call !== turn.toolCalls?.[i]).length;
|
|
103
|
+
if (changed > 0) {
|
|
104
|
+
const { reasoning: _reasoning, ...rest } = turn;
|
|
105
|
+
messages[index] = { ...rest, toolCalls: calls };
|
|
106
|
+
compacted += changed;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return compacted;
|
|
110
|
+
}
|
|
37
111
|
/** @deprecated Use {@link CompactToolResultContent}. */
|
|
38
112
|
export function compactToolResultContent(message, compact) {
|
|
39
113
|
return CompactToolResultContent(message, compact);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-result-turns.js","sourceRoot":"","sources":["../../src/native-tools/tool-result-turns.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tool-result-turns.js","sourceRoot":"","sources":["../../src/native-tools/tool-result-turns.ts"],"names":[],"mappings":"AA6BA;;;;GAIG;AACH,MAAM,UAAU,0BAA0B,CAAC,IAAyB;IAChE,OAAO;QACH,IAAI,EAAE,WAAW;QACjB,OAAO,EAAE,IAAI,CAAC,IAAI,IAAI,EAAE;QACxB,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACnE,CAAC;AACN,CAAC;AAED,0DAA0D;AAC1D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CAAC,IAAI,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;QACjG,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QAC/E,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;YACd,MAAM,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;YAChD,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;YAChD,SAAS,IAAI,OAAO,CAAC;QACzB,CAAC;IACL,CAAC;IACD,OAAO,SAAS,CAAC;AACrB,CAAC;AAED,wDAAwD;AACxD,MAAM,UAAU,wBAAwB,CAAC,OAAyB,EAAE,OAAiC;IACjG,OAAO,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AIPromptRunResult } from '@memberjunction/ai-core-plus';
|
|
2
|
+
/**
|
|
3
|
+
* The turn's tool-calling mode, read from the chat result the runner tagged. The prompt-run
|
|
4
|
+
* record's copy is the fallback only: that entity is reloaded when its INSERT completes, which can
|
|
5
|
+
* reset the field after the call returned.
|
|
6
|
+
*/
|
|
7
|
+
export declare function TurnToolCallingMode(promptResult: AIPromptRunResult | null | undefined): AIPromptRunResult['promptRun']['ToolCallingMode'] | undefined;
|
|
8
|
+
//# sourceMappingURL=turn-mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn-mode.d.ts","sourceRoot":"","sources":["../../src/native-tools/turn-mode.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEtE;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,iBAAiB,GAAG,IAAI,GAAG,SAAS,GAAG,iBAAiB,CAAC,WAAW,CAAC,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAErJ"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview The tool-calling path a prompt turn actually took.
|
|
3
|
+
* @module @memberjunction/ai-agents
|
|
4
|
+
*/
|
|
5
|
+
import { GetToolCallingMode } from '@memberjunction/ai-prompts';
|
|
6
|
+
/**
|
|
7
|
+
* The turn's tool-calling mode, read from the chat result the runner tagged. The prompt-run
|
|
8
|
+
* record's copy is the fallback only: that entity is reloaded when its INSERT completes, which can
|
|
9
|
+
* reset the field after the call returned.
|
|
10
|
+
*/
|
|
11
|
+
export function TurnToolCallingMode(promptResult) {
|
|
12
|
+
return GetToolCallingMode(promptResult?.chatResult) ?? promptResult?.promptRun?.ToolCallingMode ?? undefined;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=turn-mode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn-mode.js","sourceRoot":"","sources":["../../src/native-tools/turn-mode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAGhE;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,YAAkD;IAClF,OAAO,kBAAkB,CAAC,YAAY,EAAE,UAAU,CAAC,IAAI,YAAY,EAAE,SAAS,EAAE,eAAe,IAAI,SAAS,CAAC;AACjH,CAAC"}
|