illuma-agents 1.0.50 → 1.0.51
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/agents/AgentContext.cjs +19 -1
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +29 -2
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +19 -1
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +29 -2
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/types/types/graph.d.ts +26 -1
- package/package.json +1 -1
- package/src/agents/AgentContext.test.ts +99 -0
- package/src/agents/AgentContext.ts +19 -1
- package/src/graphs/Graph.ts +29 -0
- package/src/types/graph.ts +27 -1
|
@@ -43,9 +43,27 @@ export class AgentContext {
|
|
|
43
43
|
reasoningKey,
|
|
44
44
|
useLegacyContent,
|
|
45
45
|
dynamicContext,
|
|
46
|
-
structuredOutput,
|
|
46
|
+
structuredOutput: structuredOutputCamel,
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
48
|
+
structured_output: structuredOutputSnake,
|
|
47
49
|
} = agentConfig;
|
|
48
50
|
|
|
51
|
+
// Normalize structured output: support both camelCase and snake_case inputs
|
|
52
|
+
// Priority: structuredOutput (camelCase) > structured_output (snake_case with enabled check)
|
|
53
|
+
let structuredOutput: t.StructuredOutputConfig | undefined;
|
|
54
|
+
if (structuredOutputCamel) {
|
|
55
|
+
structuredOutput = structuredOutputCamel;
|
|
56
|
+
} else if (structuredOutputSnake?.enabled && structuredOutputSnake.schema) {
|
|
57
|
+
// Convert snake_case input to StructuredOutputConfig
|
|
58
|
+
structuredOutput = {
|
|
59
|
+
schema: structuredOutputSnake.schema,
|
|
60
|
+
name: structuredOutputSnake.name,
|
|
61
|
+
description: structuredOutputSnake.description,
|
|
62
|
+
mode: structuredOutputSnake.mode,
|
|
63
|
+
strict: structuredOutputSnake.strict,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
49
67
|
const agentContext = new AgentContext({
|
|
50
68
|
agentId,
|
|
51
69
|
name: name ?? agentId,
|
package/src/graphs/Graph.ts
CHANGED
|
@@ -700,11 +700,13 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
700
700
|
finalMessages,
|
|
701
701
|
schema,
|
|
702
702
|
structuredOutputConfig,
|
|
703
|
+
provider,
|
|
703
704
|
}: {
|
|
704
705
|
currentModel: t.ChatModelInstance;
|
|
705
706
|
finalMessages: BaseMessage[];
|
|
706
707
|
schema: Record<string, unknown>;
|
|
707
708
|
structuredOutputConfig: t.StructuredOutputConfig;
|
|
709
|
+
provider?: Providers;
|
|
708
710
|
},
|
|
709
711
|
config?: RunnableConfig
|
|
710
712
|
): Promise<{
|
|
@@ -728,15 +730,41 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
728
730
|
|
|
729
731
|
const {
|
|
730
732
|
name = 'StructuredResponse',
|
|
733
|
+
mode = 'auto',
|
|
731
734
|
includeRaw = false,
|
|
732
735
|
handleErrors = true,
|
|
733
736
|
maxRetries = 2,
|
|
734
737
|
} = structuredOutputConfig;
|
|
735
738
|
|
|
739
|
+
// Determine the method based on mode and provider
|
|
740
|
+
// - 'tool': Use tool calling (works well with OpenAI)
|
|
741
|
+
// - 'json_mode': Use JSON mode (works well with Bedrock/Anthropic)
|
|
742
|
+
// - 'auto': Auto-detect based on provider
|
|
743
|
+
let method: 'functionCalling' | 'jsonMode' | 'jsonSchema' | undefined;
|
|
744
|
+
|
|
745
|
+
if (mode === 'tool') {
|
|
746
|
+
method = 'functionCalling';
|
|
747
|
+
} else if (mode === 'provider') {
|
|
748
|
+
// Use native JSON mode - best for Anthropic/Bedrock
|
|
749
|
+
method = 'jsonMode';
|
|
750
|
+
} else {
|
|
751
|
+
// Auto mode: choose based on provider
|
|
752
|
+
// Bedrock and Anthropic work better with JSON mode
|
|
753
|
+
// OpenAI, Azure work better with function calling
|
|
754
|
+
if (provider === Providers.BEDROCK || provider === Providers.ANTHROPIC) {
|
|
755
|
+
method = 'jsonMode';
|
|
756
|
+
} else if (provider === Providers.GOOGLE || provider === Providers.VERTEXAI) {
|
|
757
|
+
// Gemini supports native JSON mode
|
|
758
|
+
method = 'jsonMode';
|
|
759
|
+
}
|
|
760
|
+
// For OpenAI/Azure, leave undefined to use default (function calling)
|
|
761
|
+
}
|
|
762
|
+
|
|
736
763
|
// Use withStructuredOutput to bind the schema
|
|
737
764
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
738
765
|
const structuredModel = (model as any).withStructuredOutput(schema, {
|
|
739
766
|
name,
|
|
767
|
+
method,
|
|
740
768
|
includeRaw,
|
|
741
769
|
strict: structuredOutputConfig.strict !== false,
|
|
742
770
|
});
|
|
@@ -1128,6 +1156,7 @@ export class StandardGraph extends Graph<t.BaseGraphState, t.GraphNode> {
|
|
|
1128
1156
|
finalMessages,
|
|
1129
1157
|
schema,
|
|
1130
1158
|
structuredOutputConfig: agentContext.structuredOutput,
|
|
1159
|
+
provider: agentContext.provider,
|
|
1131
1160
|
},
|
|
1132
1161
|
config
|
|
1133
1162
|
);
|
package/src/types/graph.ts
CHANGED
|
@@ -420,6 +420,25 @@ export interface StructuredOutputConfig {
|
|
|
420
420
|
includeRaw?: boolean;
|
|
421
421
|
}
|
|
422
422
|
|
|
423
|
+
/**
|
|
424
|
+
* Database/API structured output format (snake_case with enabled flag).
|
|
425
|
+
* This matches the format stored in MongoDB and sent from frontends.
|
|
426
|
+
*/
|
|
427
|
+
export interface StructuredOutputInput {
|
|
428
|
+
/** Whether structured output is enabled */
|
|
429
|
+
enabled?: boolean;
|
|
430
|
+
/** JSON Schema defining the expected response structure */
|
|
431
|
+
schema?: Record<string, unknown>;
|
|
432
|
+
/** Name identifier for the structured output */
|
|
433
|
+
name?: string;
|
|
434
|
+
/** Description of what the structured output represents */
|
|
435
|
+
description?: string;
|
|
436
|
+
/** Mode for structured output: 'tool' | 'provider' | 'auto' */
|
|
437
|
+
mode?: StructuredOutputMode;
|
|
438
|
+
/** Whether to enforce strict schema validation */
|
|
439
|
+
strict?: boolean;
|
|
440
|
+
}
|
|
441
|
+
|
|
423
442
|
export interface AgentInputs {
|
|
424
443
|
agentId: string;
|
|
425
444
|
/** Human-readable name for the agent (used in handoff context). Defaults to agentId if not provided. */
|
|
@@ -450,11 +469,18 @@ export interface AgentInputs {
|
|
|
450
469
|
*/
|
|
451
470
|
dynamicContext?: string;
|
|
452
471
|
/**
|
|
453
|
-
* Structured output configuration.
|
|
472
|
+
* Structured output configuration (camelCase).
|
|
454
473
|
* When set, disables streaming and returns a validated JSON response
|
|
455
474
|
* conforming to the specified schema.
|
|
456
475
|
*/
|
|
457
476
|
structuredOutput?: StructuredOutputConfig;
|
|
477
|
+
/**
|
|
478
|
+
* Structured output configuration (snake_case - database/API format).
|
|
479
|
+
* Alternative to structuredOutput for compatibility with MongoDB/frontend.
|
|
480
|
+
* Uses an `enabled` flag to control activation.
|
|
481
|
+
* @deprecated Use structuredOutput instead when possible
|
|
482
|
+
*/
|
|
483
|
+
structured_output?: StructuredOutputInput;
|
|
458
484
|
/**
|
|
459
485
|
* Serializable tool definitions for event-driven execution.
|
|
460
486
|
* When provided, ToolNode operates in event-driven mode, dispatching
|