illuma-agents 1.0.64 → 1.0.66
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/graphs/Graph.cjs +3 -132
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/main.cjs +28 -4
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +0 -50
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/cjs/tools/Calculator.cjs +23 -2
- package/dist/cjs/tools/Calculator.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +19 -1
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ToolNode.cjs +2 -1
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/search/schema.cjs +45 -0
- package/dist/cjs/tools/search/schema.cjs.map +1 -1
- package/dist/cjs/tools/search/tool.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +3 -132
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/main.mjs +4 -3
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/messages/format.mjs +2 -51
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/esm/tools/Calculator.mjs +20 -3
- package/dist/esm/tools/Calculator.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +16 -2
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/ToolNode.mjs +2 -1
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/search/schema.mjs +42 -1
- package/dist/esm/tools/search/schema.mjs.map +1 -1
- package/dist/esm/tools/search/tool.mjs.map +1 -1
- package/dist/types/messages/format.d.ts +0 -9
- package/dist/types/tools/Calculator.d.ts +26 -0
- package/dist/types/tools/CodeExecutor.d.ts +51 -0
- package/dist/types/tools/search/index.d.ts +1 -0
- package/dist/types/tools/search/schema.d.ts +69 -0
- package/package.json +1 -1
- package/src/graphs/Graph.ts +5 -160
- package/src/messages/format.ts +0 -60
- package/src/tools/Calculator.ts +24 -3
- package/src/tools/CodeExecutor.ts +19 -2
- package/src/tools/ToolNode.ts +2 -1
- package/src/tools/search/index.ts +1 -0
- package/src/tools/search/schema.ts +45 -0
- package/src/tools/search/tool.ts +3 -3
|
@@ -454,7 +454,7 @@ class StandardGraph extends Graph {
|
|
|
454
454
|
`Please use a model that supports JSON schema output (e.g., OpenAI GPT-4, Anthropic Claude, Google Gemini) ` +
|
|
455
455
|
`or disable structured output for this agent.`);
|
|
456
456
|
}
|
|
457
|
-
const { name = 'StructuredResponse', mode = 'auto', includeRaw = false, handleErrors = true, maxRetries = 2, } = structuredOutputConfig;
|
|
457
|
+
const { name = 'StructuredResponse', mode = 'auto', includeRaw: _includeRaw = false, handleErrors = true, maxRetries = 2, } = structuredOutputConfig;
|
|
458
458
|
// Determine the method based on mode and provider
|
|
459
459
|
// - 'tool' / 'functionCalling': Use tool calling (works with OpenAI, Bedrock)
|
|
460
460
|
// - 'provider' / 'jsonMode': Use native JSON mode (OpenAI, Anthropic direct - NOT Bedrock)
|
|
@@ -509,7 +509,6 @@ class StandardGraph extends Graph {
|
|
|
509
509
|
const result = await structuredModel.invoke(finalMessages, config);
|
|
510
510
|
// Debug: log what we got back
|
|
511
511
|
console.log('[Graph] Structured output raw result type:', typeof result);
|
|
512
|
-
console.log('[Graph] Structured output result keys:', result ? Object.keys(result) : 'null');
|
|
513
512
|
if (result?.raw) {
|
|
514
513
|
const rawMsg = result.raw;
|
|
515
514
|
console.log('[Graph] Raw message content type:', typeof rawMsg?.content);
|
|
@@ -517,28 +516,15 @@ class StandardGraph extends Graph {
|
|
|
517
516
|
if (rawMsg?.content && typeof rawMsg.content === 'string' && rawMsg.content.length > 0) {
|
|
518
517
|
console.log('[Graph] Raw message text content (first 200):', rawMsg.content.substring(0, 200));
|
|
519
518
|
}
|
|
520
|
-
// Log the parsed result if available
|
|
521
|
-
if (result?.parsed) {
|
|
522
|
-
console.log('[Graph] Parsed result keys:', Object.keys(result.parsed));
|
|
523
|
-
}
|
|
524
519
|
}
|
|
525
520
|
// Handle response - we always use includeRaw internally
|
|
526
521
|
if (result?.raw && result?.parsed !== undefined) {
|
|
527
|
-
console.log('[Graph] Using parsed result from structured output');
|
|
528
522
|
return {
|
|
529
523
|
structuredResponse: result.parsed,
|
|
530
524
|
rawMessage: result.raw,
|
|
531
525
|
};
|
|
532
526
|
}
|
|
533
|
-
// Fallback: If result itself is the parsed object (no raw wrapper)
|
|
534
|
-
if (result && typeof result === 'object' && !result.raw && !result.parsed) {
|
|
535
|
-
console.log('[Graph] Result is the structured object directly');
|
|
536
|
-
return {
|
|
537
|
-
structuredResponse: result,
|
|
538
|
-
};
|
|
539
|
-
}
|
|
540
527
|
// Fallback for models that don't support includeRaw
|
|
541
|
-
console.log('[Graph] Using fallback - treating result as structured response');
|
|
542
528
|
return {
|
|
543
529
|
structuredResponse: result,
|
|
544
530
|
};
|
|
@@ -780,15 +766,8 @@ class StandardGraph extends Graph {
|
|
|
780
766
|
analytics: contextAnalytics$1,
|
|
781
767
|
}, config);
|
|
782
768
|
// Check if structured output mode is enabled
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
// 1. No tools are configured, OR
|
|
786
|
-
// 2. The model has already used tools and is ready to give final response
|
|
787
|
-
const hasTools = agentContext.tools && agentContext.tools.length > 0;
|
|
788
|
-
const shouldUseStructuredOutputNow = agentContext.isStructuredOutputMode &&
|
|
789
|
-
agentContext.structuredOutput &&
|
|
790
|
-
!hasTools; // Only use structured output immediately if no tools
|
|
791
|
-
if (shouldUseStructuredOutputNow) {
|
|
769
|
+
if (agentContext.isStructuredOutputMode &&
|
|
770
|
+
agentContext.structuredOutput) {
|
|
792
771
|
const schema = agentContext.getStructuredOutputSchema();
|
|
793
772
|
if (!schema) {
|
|
794
773
|
throw new Error('Structured output schema is not configured');
|
|
@@ -827,8 +806,6 @@ class StandardGraph extends Graph {
|
|
|
827
806
|
provider: agentContext.provider,
|
|
828
807
|
clientOptions: structuredClientOptions,
|
|
829
808
|
});
|
|
830
|
-
// For no-tools case, we pass the original messages directly
|
|
831
|
-
// There shouldn't be thinking blocks since this is the first invocation
|
|
832
809
|
const { structuredResponse, rawMessage } = await this.attemptStructuredInvoke({
|
|
833
810
|
currentModel: structuredModel,
|
|
834
811
|
finalMessages,
|
|
@@ -1040,112 +1017,6 @@ If I seem to be missing something we discussed earlier, just give me a quick rem
|
|
|
1040
1017
|
if (!result) {
|
|
1041
1018
|
throw new Error('No result after model invocation');
|
|
1042
1019
|
}
|
|
1043
|
-
// Check if we need to apply structured output for the final response
|
|
1044
|
-
// This handles the case where tools were used, and now the model is giving its final answer
|
|
1045
|
-
const resultMessage = result.messages?.[0];
|
|
1046
|
-
const hasToolCalls = (resultMessage?.tool_calls?.length ?? 0) > 0;
|
|
1047
|
-
if (agentContext.isStructuredOutputMode &&
|
|
1048
|
-
agentContext.structuredOutput &&
|
|
1049
|
-
!hasToolCalls && // Model is giving final response (no tool calls)
|
|
1050
|
-
hasTools // We skipped structured output earlier because tools were available
|
|
1051
|
-
) {
|
|
1052
|
-
const schema = agentContext.getStructuredOutputSchema();
|
|
1053
|
-
if (schema) {
|
|
1054
|
-
try {
|
|
1055
|
-
console.log('[Graph] Applying structured output for final response after tool execution');
|
|
1056
|
-
// Get a fresh model for structured output
|
|
1057
|
-
const structuredClientOptions = { ...agentContext.clientOptions };
|
|
1058
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1059
|
-
structuredClientOptions.streaming = false;
|
|
1060
|
-
// Remove thinking configuration
|
|
1061
|
-
if (agentContext.provider === _enum.Providers.BEDROCK) {
|
|
1062
|
-
const bedrockOpts = structuredClientOptions;
|
|
1063
|
-
if (bedrockOpts.additionalModelRequestFields) {
|
|
1064
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1065
|
-
const additionalFields = Object.assign({}, bedrockOpts.additionalModelRequestFields);
|
|
1066
|
-
delete additionalFields.thinking;
|
|
1067
|
-
delete additionalFields.budgetTokens;
|
|
1068
|
-
bedrockOpts.additionalModelRequestFields = additionalFields;
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
if (agentContext.provider === _enum.Providers.ANTHROPIC) {
|
|
1072
|
-
const anthropicOpts = structuredClientOptions;
|
|
1073
|
-
if (anthropicOpts.thinking) {
|
|
1074
|
-
delete anthropicOpts.thinking;
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
const structuredModel = this.getNewModel({
|
|
1078
|
-
provider: agentContext.provider,
|
|
1079
|
-
clientOptions: structuredClientOptions,
|
|
1080
|
-
});
|
|
1081
|
-
// Following LangGraph's Option 2 pattern:
|
|
1082
|
-
// Instead of passing the full conversation (which has thinking blocks),
|
|
1083
|
-
// just pass the model's final response text as a HumanMessage asking for structured output.
|
|
1084
|
-
// This avoids issues with thinking blocks and is more token-efficient.
|
|
1085
|
-
let responseContent = '';
|
|
1086
|
-
if (resultMessage) {
|
|
1087
|
-
if (typeof resultMessage.content === 'string') {
|
|
1088
|
-
responseContent = resultMessage.content;
|
|
1089
|
-
}
|
|
1090
|
-
else if (Array.isArray(resultMessage.content)) {
|
|
1091
|
-
// Extract text parts only (skip thinking blocks, tool_use, etc.)
|
|
1092
|
-
responseContent = resultMessage.content
|
|
1093
|
-
.filter((c) => typeof c === 'object' && c !== null &&
|
|
1094
|
-
c.type === 'text' &&
|
|
1095
|
-
typeof c.text === 'string')
|
|
1096
|
-
.map(c => c.text)
|
|
1097
|
-
.join('\n');
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
if (!responseContent) {
|
|
1101
|
-
console.log('[Graph] No response content to structure, skipping');
|
|
1102
|
-
throw new Error('No response content available for structured output');
|
|
1103
|
-
}
|
|
1104
|
-
console.log('[Graph] Structuring response content (first 200 chars):', responseContent.substring(0, 200));
|
|
1105
|
-
// Create a simple message asking to structure the response
|
|
1106
|
-
const structuredMessages = [
|
|
1107
|
-
new messages.HumanMessage({
|
|
1108
|
-
content: `Based on the following response, extract and return the data in the required structured format:\n\n${responseContent}`,
|
|
1109
|
-
}),
|
|
1110
|
-
];
|
|
1111
|
-
const { structuredResponse, rawMessage } = await this.attemptStructuredInvoke({
|
|
1112
|
-
currentModel: structuredModel,
|
|
1113
|
-
finalMessages: structuredMessages,
|
|
1114
|
-
schema,
|
|
1115
|
-
structuredOutputConfig: agentContext.structuredOutput,
|
|
1116
|
-
provider: agentContext.provider,
|
|
1117
|
-
}, config);
|
|
1118
|
-
// Emit structured output event
|
|
1119
|
-
await events.safeDispatchCustomEvent(_enum.GraphEvents.ON_STRUCTURED_OUTPUT, {
|
|
1120
|
-
structuredResponse,
|
|
1121
|
-
schema,
|
|
1122
|
-
raw: rawMessage,
|
|
1123
|
-
}, config);
|
|
1124
|
-
agentContext.currentUsage = rawMessage
|
|
1125
|
-
? this.getUsageMetadata(rawMessage)
|
|
1126
|
-
: undefined;
|
|
1127
|
-
this.cleanupSignalListener();
|
|
1128
|
-
// Return clean message without tool_calls
|
|
1129
|
-
let cleanMessage;
|
|
1130
|
-
if (rawMessage) {
|
|
1131
|
-
cleanMessage = new messages.AIMessageChunk({
|
|
1132
|
-
content: JSON.stringify(structuredResponse, null, 2),
|
|
1133
|
-
id: rawMessage.id,
|
|
1134
|
-
response_metadata: rawMessage.response_metadata,
|
|
1135
|
-
usage_metadata: rawMessage.usage_metadata,
|
|
1136
|
-
});
|
|
1137
|
-
}
|
|
1138
|
-
return {
|
|
1139
|
-
messages: cleanMessage ? [cleanMessage] : [],
|
|
1140
|
-
structuredResponse,
|
|
1141
|
-
};
|
|
1142
|
-
}
|
|
1143
|
-
catch (structuredError) {
|
|
1144
|
-
console.error('[Graph] Structured output failed after tool execution:', structuredError);
|
|
1145
|
-
// Fall through to return normal result
|
|
1146
|
-
}
|
|
1147
|
-
}
|
|
1148
|
-
}
|
|
1149
1020
|
agentContext.currentUsage = this.getUsageMetadata(result.messages?.[0]);
|
|
1150
1021
|
this.cleanupSignalListener();
|
|
1151
1022
|
return result;
|