illuma-agents 1.0.5 → 1.0.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/dist/cjs/events.cjs +34 -10
- package/dist/cjs/events.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +6 -4
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/utils/message_outputs.cjs.map +1 -1
- package/dist/cjs/main.cjs +3 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/messages/cache.cjs +87 -14
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +188 -7
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/esm/events.mjs +34 -10
- package/dist/esm/events.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +6 -4
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/llm/anthropic/utils/message_outputs.mjs.map +1 -1
- package/dist/esm/main.mjs +2 -2
- package/dist/esm/messages/cache.mjs +86 -15
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +188 -8
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/types/events.d.ts +3 -1
- package/dist/types/messages/cache.d.ts +16 -0
- package/dist/types/messages/format.d.ts +21 -1
- package/dist/types/types/stream.d.ts +1 -1
- package/package.json +6 -3
- package/src/events.ts +37 -15
- package/src/graphs/Graph.ts +8 -4
- package/src/llm/anthropic/utils/message_outputs.ts +289 -289
- package/src/messages/cache.test.ts +499 -3
- package/src/messages/cache.ts +115 -25
- package/src/messages/ensureThinkingBlock.test.ts +75 -0
- package/src/messages/format.ts +240 -7
- package/src/messages/labelContentByAgent.test.ts +887 -0
- package/src/scripts/test-multi-agent-list-handoff.ts +116 -10
- package/src/scripts/test-parallel-agent-labeling.ts +325 -0
- package/src/types/stream.ts +1 -1
package/src/events.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
BaseMessageFields,
|
|
7
7
|
} from '@langchain/core/messages';
|
|
8
8
|
import type { MultiAgentGraph, StandardGraph } from '@/graphs';
|
|
9
|
+
import type { Logger } from 'winston';
|
|
9
10
|
import type * as t from '@/types';
|
|
10
11
|
import { handleToolCalls } from '@/tools/handlers';
|
|
11
12
|
import { Providers } from '@/common';
|
|
@@ -74,12 +75,15 @@ export class ModelEndHandler implements t.EventHandler {
|
|
|
74
75
|
|
|
75
76
|
export class ToolEndHandler implements t.EventHandler {
|
|
76
77
|
private callback?: t.ToolEndCallback;
|
|
78
|
+
private logger?: Logger;
|
|
77
79
|
private omitOutput?: (name?: string) => boolean;
|
|
78
80
|
constructor(
|
|
79
81
|
callback?: t.ToolEndCallback,
|
|
82
|
+
logger?: Logger,
|
|
80
83
|
omitOutput?: (name?: string) => boolean
|
|
81
84
|
) {
|
|
82
85
|
this.callback = callback;
|
|
86
|
+
this.logger = logger;
|
|
83
87
|
this.omitOutput = omitOutput;
|
|
84
88
|
}
|
|
85
89
|
async handle(
|
|
@@ -88,23 +92,41 @@ export class ToolEndHandler implements t.EventHandler {
|
|
|
88
92
|
metadata?: Record<string, unknown>,
|
|
89
93
|
graph?: StandardGraph | MultiAgentGraph
|
|
90
94
|
): Promise<void> {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
+
try {
|
|
96
|
+
if (!graph || !metadata) {
|
|
97
|
+
if (this.logger) {
|
|
98
|
+
this.logger.warn(`Graph or metadata not found in ${event} event`);
|
|
99
|
+
} else {
|
|
100
|
+
console.warn(`Graph or metadata not found in ${event} event`);
|
|
101
|
+
}
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
95
104
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
105
|
+
const toolEndData = data as t.ToolEndData | undefined;
|
|
106
|
+
if (!toolEndData?.output) {
|
|
107
|
+
if (this.logger) {
|
|
108
|
+
this.logger.warn('No output found in tool_end event');
|
|
109
|
+
} else {
|
|
110
|
+
console.warn('No output found in tool_end event');
|
|
111
|
+
}
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
101
114
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
115
|
+
if (this.callback) {
|
|
116
|
+
await this.callback(toolEndData, metadata);
|
|
117
|
+
}
|
|
118
|
+
await graph.handleToolCallCompleted(
|
|
119
|
+
{ input: toolEndData.input, output: toolEndData.output },
|
|
120
|
+
metadata,
|
|
121
|
+
this.omitOutput?.((toolEndData.output as ToolMessage | undefined)?.name)
|
|
122
|
+
);
|
|
123
|
+
} catch (error) {
|
|
124
|
+
if (this.logger) {
|
|
125
|
+
this.logger.error('Error handling tool_end event:', error);
|
|
126
|
+
} else {
|
|
127
|
+
console.error('Error handling tool_end event:', error);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
108
130
|
}
|
|
109
131
|
}
|
|
110
132
|
|
package/src/graphs/Graph.ts
CHANGED
|
@@ -333,7 +333,7 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
333
333
|
* Get all run steps, optionally filtered by agent ID
|
|
334
334
|
*/
|
|
335
335
|
getRunSteps(agentId?: string): t.RunStep[] {
|
|
336
|
-
if (
|
|
336
|
+
if (agentId == null || agentId === '') {
|
|
337
337
|
return [...this.contentData];
|
|
338
338
|
}
|
|
339
339
|
return this.contentData.filter((step) => step.agentId === agentId);
|
|
@@ -346,7 +346,7 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
346
346
|
const stepsByAgent = new Map<string, t.RunStep[]>();
|
|
347
347
|
|
|
348
348
|
for (const step of this.contentData) {
|
|
349
|
-
if (
|
|
349
|
+
if (step.agentId == null || step.agentId === '') continue;
|
|
350
350
|
|
|
351
351
|
const steps = stepsByAgent.get(step.agentId) ?? [];
|
|
352
352
|
steps.push(step);
|
|
@@ -362,7 +362,7 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
362
362
|
getActiveAgentIds(): string[] {
|
|
363
363
|
const agentIds = new Set<string>();
|
|
364
364
|
for (const step of this.contentData) {
|
|
365
|
-
if (step.agentId) {
|
|
365
|
+
if (step.agentId != null && step.agentId !== '') {
|
|
366
366
|
agentIds.add(step.agentId);
|
|
367
367
|
}
|
|
368
368
|
}
|
|
@@ -377,7 +377,11 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
377
377
|
const contentPartAgentMap = new Map<number, string>();
|
|
378
378
|
|
|
379
379
|
for (const step of this.contentData) {
|
|
380
|
-
if (
|
|
380
|
+
if (
|
|
381
|
+
step.agentId != null &&
|
|
382
|
+
step.agentId !== '' &&
|
|
383
|
+
Number.isFinite(step.index)
|
|
384
|
+
) {
|
|
381
385
|
contentPartAgentMap.set(step.index, step.agentId);
|
|
382
386
|
}
|
|
383
387
|
}
|