illuma-agents 1.0.62 → 1.0.64
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 +45 -4
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/main.cjs +1 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/messages/format.cjs +50 -0
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +45 -4
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/main.mjs +1 -1
- package/dist/esm/messages/format.mjs +51 -2
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/types/messages/format.d.ts +9 -0
- package/package.json +1 -1
- package/src/graphs/Graph.ts +51 -4
- package/src/messages/format.ts +60 -0
|
@@ -509,6 +509,7 @@ 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');
|
|
512
513
|
if (result?.raw) {
|
|
513
514
|
const rawMsg = result.raw;
|
|
514
515
|
console.log('[Graph] Raw message content type:', typeof rawMsg?.content);
|
|
@@ -516,15 +517,28 @@ class StandardGraph extends Graph {
|
|
|
516
517
|
if (rawMsg?.content && typeof rawMsg.content === 'string' && rawMsg.content.length > 0) {
|
|
517
518
|
console.log('[Graph] Raw message text content (first 200):', rawMsg.content.substring(0, 200));
|
|
518
519
|
}
|
|
520
|
+
// Log the parsed result if available
|
|
521
|
+
if (result?.parsed) {
|
|
522
|
+
console.log('[Graph] Parsed result keys:', Object.keys(result.parsed));
|
|
523
|
+
}
|
|
519
524
|
}
|
|
520
525
|
// Handle response - we always use includeRaw internally
|
|
521
526
|
if (result?.raw && result?.parsed !== undefined) {
|
|
527
|
+
console.log('[Graph] Using parsed result from structured output');
|
|
522
528
|
return {
|
|
523
529
|
structuredResponse: result.parsed,
|
|
524
530
|
rawMessage: result.raw,
|
|
525
531
|
};
|
|
526
532
|
}
|
|
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
|
+
}
|
|
527
540
|
// Fallback for models that don't support includeRaw
|
|
541
|
+
console.log('[Graph] Using fallback - treating result as structured response');
|
|
528
542
|
return {
|
|
529
543
|
structuredResponse: result,
|
|
530
544
|
};
|
|
@@ -813,6 +827,8 @@ class StandardGraph extends Graph {
|
|
|
813
827
|
provider: agentContext.provider,
|
|
814
828
|
clientOptions: structuredClientOptions,
|
|
815
829
|
});
|
|
830
|
+
// For no-tools case, we pass the original messages directly
|
|
831
|
+
// There shouldn't be thinking blocks since this is the first invocation
|
|
816
832
|
const { structuredResponse, rawMessage } = await this.attemptStructuredInvoke({
|
|
817
833
|
currentModel: structuredModel,
|
|
818
834
|
finalMessages,
|
|
@@ -1062,14 +1078,39 @@ If I seem to be missing something we discussed earlier, just give me a quick rem
|
|
|
1062
1078
|
provider: agentContext.provider,
|
|
1063
1079
|
clientOptions: structuredClientOptions,
|
|
1064
1080
|
});
|
|
1065
|
-
//
|
|
1066
|
-
|
|
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 = '';
|
|
1067
1086
|
if (resultMessage) {
|
|
1068
|
-
|
|
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
|
+
}
|
|
1069
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
|
+
];
|
|
1070
1111
|
const { structuredResponse, rawMessage } = await this.attemptStructuredInvoke({
|
|
1071
1112
|
currentModel: structuredModel,
|
|
1072
|
-
finalMessages:
|
|
1113
|
+
finalMessages: structuredMessages,
|
|
1073
1114
|
schema,
|
|
1074
1115
|
structuredOutputConfig: agentContext.structuredOutput,
|
|
1075
1116
|
provider: agentContext.provider,
|