illuma-agents 1.0.63 → 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.
@@ -7,7 +7,7 @@ import { SystemMessage, HumanMessage, AIMessageChunk } from '@langchain/core/mes
7
7
  import { GraphNodeKeys, ContentTypes, Providers, GraphEvents, MessageTypes, StepTypes, Constants } from '../common/enum.mjs';
8
8
  import { convertMessagesToContent, modifyDeltaProperties, formatAnthropicArtifactContent, formatArtifactPayload } from '../messages/core.mjs';
9
9
  import { createPruneMessages } from '../messages/prune.mjs';
10
- import { ensureThinkingBlockInMessages, stripThinkingBlocksFromMessages } from '../messages/format.mjs';
10
+ import { ensureThinkingBlockInMessages } from '../messages/format.mjs';
11
11
  import { addCacheControl, addBedrockCacheControl } from '../messages/cache.mjs';
12
12
  import { formatContentStrings } from '../messages/content.mjs';
13
13
  import { extractToolDiscoveries } from '../messages/tools.mjs';
@@ -825,11 +825,11 @@ class StandardGraph extends Graph {
825
825
  provider: agentContext.provider,
826
826
  clientOptions: structuredClientOptions,
827
827
  });
828
- // Strip thinking blocks from messages since structured output has thinking disabled
829
- const cleanMessages = stripThinkingBlocksFromMessages(finalMessages);
828
+ // For no-tools case, we pass the original messages directly
829
+ // There shouldn't be thinking blocks since this is the first invocation
830
830
  const { structuredResponse, rawMessage } = await this.attemptStructuredInvoke({
831
831
  currentModel: structuredModel,
832
- finalMessages: cleanMessages,
832
+ finalMessages,
833
833
  schema,
834
834
  structuredOutputConfig: agentContext.structuredOutput,
835
835
  provider: agentContext.provider,
@@ -1076,17 +1076,39 @@ If I seem to be missing something we discussed earlier, just give me a quick rem
1076
1076
  provider: agentContext.provider,
1077
1077
  clientOptions: structuredClientOptions,
1078
1078
  });
1079
- // Include the current result in the messages so the model knows what it just said
1080
- // IMPORTANT: Strip thinking blocks from messages since structured output has thinking disabled
1081
- // Bedrock will error if assistant messages contain thinking blocks when thinking is disabled
1082
- let messagesWithResult = [...finalMessages];
1079
+ // Following LangGraph's Option 2 pattern:
1080
+ // Instead of passing the full conversation (which has thinking blocks),
1081
+ // just pass the model's final response text as a HumanMessage asking for structured output.
1082
+ // This avoids issues with thinking blocks and is more token-efficient.
1083
+ let responseContent = '';
1083
1084
  if (resultMessage) {
1084
- messagesWithResult.push(resultMessage);
1085
+ if (typeof resultMessage.content === 'string') {
1086
+ responseContent = resultMessage.content;
1087
+ }
1088
+ else if (Array.isArray(resultMessage.content)) {
1089
+ // Extract text parts only (skip thinking blocks, tool_use, etc.)
1090
+ responseContent = resultMessage.content
1091
+ .filter((c) => typeof c === 'object' && c !== null &&
1092
+ c.type === 'text' &&
1093
+ typeof c.text === 'string')
1094
+ .map(c => c.text)
1095
+ .join('\n');
1096
+ }
1085
1097
  }
1086
- messagesWithResult = stripThinkingBlocksFromMessages(messagesWithResult);
1098
+ if (!responseContent) {
1099
+ console.log('[Graph] No response content to structure, skipping');
1100
+ throw new Error('No response content available for structured output');
1101
+ }
1102
+ console.log('[Graph] Structuring response content (first 200 chars):', responseContent.substring(0, 200));
1103
+ // Create a simple message asking to structure the response
1104
+ const structuredMessages = [
1105
+ new HumanMessage({
1106
+ content: `Based on the following response, extract and return the data in the required structured format:\n\n${responseContent}`,
1107
+ }),
1108
+ ];
1087
1109
  const { structuredResponse, rawMessage } = await this.attemptStructuredInvoke({
1088
1110
  currentModel: structuredModel,
1089
- finalMessages: messagesWithResult,
1111
+ finalMessages: structuredMessages,
1090
1112
  schema,
1091
1113
  structuredOutputConfig: agentContext.structuredOutput,
1092
1114
  provider: agentContext.provider,