@illuma-ai/agents 1.1.21 → 1.1.23
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 +12 -1
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +105 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/run.cjs +20 -9
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/utils/llm.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +12 -1
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +105 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/run.mjs +20 -9
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/utils/llm.mjs.map +1 -1
- package/dist/types/graphs/MultiAgentGraph.d.ts +17 -0
- package/package.json +1 -1
- package/src/graphs/Graph.ts +13 -1
- package/src/graphs/MultiAgentGraph.ts +128 -1
- package/src/graphs/__tests__/multi-agent-delegate.test.ts +205 -0
- package/src/run.ts +20 -11
- package/src/scripts/test-bedrock-handoff-autonomous.ts +231 -0
- package/src/utils/llm.ts +1 -0
- package/src/agents/AgentContext.js +0 -782
- package/src/agents/AgentContext.test.js +0 -421
- package/src/agents/__tests__/AgentContext.test.js +0 -678
- package/src/agents/__tests__/resolveStructuredOutputMode.test.js +0 -117
- package/src/common/enum.js +0 -192
- package/src/common/index.js +0 -3
- package/src/events.js +0 -166
- package/src/graphs/Graph.js +0 -1857
- package/src/graphs/MultiAgentGraph.js +0 -1092
- package/src/graphs/__tests__/structured-output.integration.test.js +0 -624
- package/src/graphs/__tests__/structured-output.test.js +0 -144
- package/src/graphs/contextManagement.e2e.test.js +0 -718
- package/src/graphs/contextManagement.test.js +0 -485
- package/src/graphs/handoffValidation.test.js +0 -276
- package/src/graphs/index.js +0 -3
- package/src/index.js +0 -28
- package/src/instrumentation.js +0 -21
- package/src/llm/anthropic/index.js +0 -319
- package/src/llm/anthropic/types.js +0 -46
- package/src/llm/anthropic/utils/message_inputs.js +0 -627
- package/src/llm/anthropic/utils/message_outputs.js +0 -290
- package/src/llm/anthropic/utils/output_parsers.js +0 -89
- package/src/llm/anthropic/utils/tools.js +0 -25
- package/src/llm/bedrock/__tests__/bedrock-caching.test.js +0 -392
- package/src/llm/bedrock/index.js +0 -303
- package/src/llm/bedrock/types.js +0 -2
- package/src/llm/bedrock/utils/index.js +0 -6
- package/src/llm/bedrock/utils/message_inputs.js +0 -463
- package/src/llm/bedrock/utils/message_outputs.js +0 -269
- package/src/llm/fake.js +0 -92
- package/src/llm/google/index.js +0 -215
- package/src/llm/google/types.js +0 -12
- package/src/llm/google/utils/common.js +0 -670
- package/src/llm/google/utils/tools.js +0 -111
- package/src/llm/google/utils/zod_to_genai_parameters.js +0 -47
- package/src/llm/openai/index.js +0 -1033
- package/src/llm/openai/types.js +0 -2
- package/src/llm/openai/utils/index.js +0 -756
- package/src/llm/openai/utils/isReasoningModel.test.js +0 -79
- package/src/llm/openrouter/index.js +0 -261
- package/src/llm/openrouter/reasoning.test.js +0 -181
- package/src/llm/providers.js +0 -36
- package/src/llm/text.js +0 -65
- package/src/llm/vertexai/index.js +0 -402
- package/src/messages/__tests__/tools.test.js +0 -392
- package/src/messages/cache.js +0 -404
- package/src/messages/cache.test.js +0 -1167
- package/src/messages/content.js +0 -48
- package/src/messages/content.test.js +0 -314
- package/src/messages/core.js +0 -359
- package/src/messages/ensureThinkingBlock.test.js +0 -997
- package/src/messages/format.js +0 -973
- package/src/messages/formatAgentMessages.test.js +0 -2278
- package/src/messages/formatAgentMessages.tools.test.js +0 -362
- package/src/messages/formatMessage.test.js +0 -608
- package/src/messages/ids.js +0 -18
- package/src/messages/index.js +0 -9
- package/src/messages/labelContentByAgent.test.js +0 -725
- package/src/messages/prune.js +0 -438
- package/src/messages/reducer.js +0 -60
- package/src/messages/shiftIndexTokenCountMap.test.js +0 -63
- package/src/messages/summarize.js +0 -146
- package/src/messages/summarize.test.js +0 -332
- package/src/messages/tools.js +0 -90
- package/src/mockStream.js +0 -81
- package/src/prompts/collab.js +0 -7
- package/src/prompts/index.js +0 -3
- package/src/prompts/taskmanager.js +0 -58
- package/src/run.js +0 -427
- package/src/schemas/index.js +0 -3
- package/src/schemas/schema-preparation.test.js +0 -370
- package/src/schemas/validate.js +0 -314
- package/src/schemas/validate.test.js +0 -264
- package/src/scripts/abort.js +0 -127
- package/src/scripts/ant_web_search.js +0 -130
- package/src/scripts/ant_web_search_edge_case.js +0 -133
- package/src/scripts/ant_web_search_error_edge_case.js +0 -119
- package/src/scripts/args.js +0 -41
- package/src/scripts/bedrock-cache-debug.js +0 -186
- package/src/scripts/bedrock-content-aggregation-test.js +0 -195
- package/src/scripts/bedrock-merge-test.js +0 -80
- package/src/scripts/bedrock-parallel-tools-test.js +0 -150
- package/src/scripts/caching.js +0 -106
- package/src/scripts/cli.js +0 -152
- package/src/scripts/cli2.js +0 -119
- package/src/scripts/cli3.js +0 -163
- package/src/scripts/cli4.js +0 -165
- package/src/scripts/cli5.js +0 -165
- package/src/scripts/code_exec.js +0 -171
- package/src/scripts/code_exec_files.js +0 -180
- package/src/scripts/code_exec_multi_session.js +0 -185
- package/src/scripts/code_exec_ptc.js +0 -265
- package/src/scripts/code_exec_session.js +0 -217
- package/src/scripts/code_exec_simple.js +0 -120
- package/src/scripts/content.js +0 -111
- package/src/scripts/empty_input.js +0 -125
- package/src/scripts/handoff-test.js +0 -96
- package/src/scripts/image.js +0 -138
- package/src/scripts/memory.js +0 -83
- package/src/scripts/multi-agent-chain.js +0 -271
- package/src/scripts/multi-agent-conditional.js +0 -185
- package/src/scripts/multi-agent-document-review-chain.js +0 -171
- package/src/scripts/multi-agent-hybrid-flow.js +0 -264
- package/src/scripts/multi-agent-parallel-start.js +0 -214
- package/src/scripts/multi-agent-parallel.js +0 -346
- package/src/scripts/multi-agent-sequence.js +0 -184
- package/src/scripts/multi-agent-supervisor.js +0 -324
- package/src/scripts/multi-agent-test.js +0 -147
- package/src/scripts/parallel-asymmetric-tools-test.js +0 -202
- package/src/scripts/parallel-full-metadata-test.js +0 -176
- package/src/scripts/parallel-tools-test.js +0 -256
- package/src/scripts/programmatic_exec.js +0 -277
- package/src/scripts/programmatic_exec_agent.js +0 -168
- package/src/scripts/search.js +0 -118
- package/src/scripts/sequential-full-metadata-test.js +0 -143
- package/src/scripts/simple.js +0 -174
- package/src/scripts/single-agent-metadata-test.js +0 -152
- package/src/scripts/stream.js +0 -113
- package/src/scripts/test-custom-prompt-key.js +0 -132
- package/src/scripts/test-handoff-input.js +0 -143
- package/src/scripts/test-handoff-preamble.js +0 -227
- package/src/scripts/test-handoff-steering.js +0 -353
- package/src/scripts/test-multi-agent-list-handoff.js +0 -318
- package/src/scripts/test-parallel-agent-labeling.js +0 -253
- package/src/scripts/test-parallel-handoffs.js +0 -229
- package/src/scripts/test-thinking-handoff-bedrock.js +0 -132
- package/src/scripts/test-thinking-handoff.js +0 -132
- package/src/scripts/test-thinking-to-thinking-handoff-bedrock.js +0 -140
- package/src/scripts/test-tool-before-handoff-role-order.js +0 -223
- package/src/scripts/test-tools-before-handoff.js +0 -187
- package/src/scripts/test_code_api.js +0 -263
- package/src/scripts/thinking-bedrock.js +0 -128
- package/src/scripts/thinking-vertexai.js +0 -130
- package/src/scripts/thinking.js +0 -134
- package/src/scripts/tool_search.js +0 -114
- package/src/scripts/tools.js +0 -125
- package/src/specs/agent-handoffs-bedrock.integration.test.js +0 -280
- package/src/specs/agent-handoffs.test.js +0 -924
- package/src/specs/anthropic.simple.test.js +0 -287
- package/src/specs/azure.simple.test.js +0 -381
- package/src/specs/cache.simple.test.js +0 -282
- package/src/specs/custom-event-await.test.js +0 -148
- package/src/specs/deepseek.simple.test.js +0 -189
- package/src/specs/emergency-prune.test.js +0 -308
- package/src/specs/moonshot.simple.test.js +0 -237
- package/src/specs/observability.integration.test.js +0 -1337
- package/src/specs/openai.simple.test.js +0 -233
- package/src/specs/openrouter.simple.test.js +0 -202
- package/src/specs/prune.test.js +0 -733
- package/src/specs/reasoning.test.js +0 -144
- package/src/specs/spec.utils.js +0 -4
- package/src/specs/thinking-handoff.test.js +0 -486
- package/src/specs/thinking-prune.test.js +0 -600
- package/src/specs/token-distribution-edge-case.test.js +0 -246
- package/src/specs/token-memoization.test.js +0 -32
- package/src/specs/tokens.test.js +0 -49
- package/src/specs/tool-error.test.js +0 -139
- package/src/splitStream.js +0 -204
- package/src/splitStream.test.js +0 -504
- package/src/stream.js +0 -650
- package/src/stream.test.js +0 -225
- package/src/test/mockTools.js +0 -340
- package/src/tools/BrowserTools.js +0 -245
- package/src/tools/Calculator.js +0 -38
- package/src/tools/Calculator.test.js +0 -225
- package/src/tools/CodeExecutor.js +0 -233
- package/src/tools/ProgrammaticToolCalling.js +0 -602
- package/src/tools/StreamingToolCallBuffer.js +0 -179
- package/src/tools/ToolNode.js +0 -930
- package/src/tools/ToolSearch.js +0 -904
- package/src/tools/__tests__/BrowserTools.test.js +0 -306
- package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.js +0 -276
- package/src/tools/__tests__/ProgrammaticToolCalling.test.js +0 -807
- package/src/tools/__tests__/StreamingToolCallBuffer.test.js +0 -175
- package/src/tools/__tests__/ToolApproval.test.js +0 -675
- package/src/tools/__tests__/ToolNode.recovery.test.js +0 -200
- package/src/tools/__tests__/ToolNode.session.test.js +0 -319
- package/src/tools/__tests__/ToolSearch.integration.test.js +0 -125
- package/src/tools/__tests__/ToolSearch.test.js +0 -812
- package/src/tools/__tests__/handlers.test.js +0 -799
- package/src/tools/__tests__/truncation-recovery.integration.test.js +0 -362
- package/src/tools/handlers.js +0 -306
- package/src/tools/schema.js +0 -25
- package/src/tools/search/anthropic.js +0 -34
- package/src/tools/search/content.js +0 -116
- package/src/tools/search/content.test.js +0 -133
- package/src/tools/search/firecrawl.js +0 -173
- package/src/tools/search/format.js +0 -198
- package/src/tools/search/highlights.js +0 -241
- package/src/tools/search/index.js +0 -3
- package/src/tools/search/jina-reranker.test.js +0 -106
- package/src/tools/search/rerankers.js +0 -165
- package/src/tools/search/schema.js +0 -102
- package/src/tools/search/search.js +0 -561
- package/src/tools/search/serper-scraper.js +0 -126
- package/src/tools/search/test.js +0 -129
- package/src/tools/search/tool.js +0 -453
- package/src/tools/search/types.js +0 -2
- package/src/tools/search/utils.js +0 -59
- package/src/types/graph.js +0 -24
- package/src/types/graph.test.js +0 -192
- package/src/types/index.js +0 -7
- package/src/types/llm.js +0 -2
- package/src/types/messages.js +0 -2
- package/src/types/run.js +0 -2
- package/src/types/stream.js +0 -2
- package/src/types/tools.js +0 -2
- package/src/utils/contextAnalytics.js +0 -79
- package/src/utils/contextAnalytics.test.js +0 -166
- package/src/utils/events.js +0 -26
- package/src/utils/graph.js +0 -11
- package/src/utils/handlers.js +0 -65
- package/src/utils/index.js +0 -10
- package/src/utils/llm.js +0 -21
- package/src/utils/llmConfig.js +0 -205
- package/src/utils/logging.js +0 -37
- package/src/utils/misc.js +0 -51
- package/src/utils/run.js +0 -69
- package/src/utils/schema.js +0 -21
- package/src/utils/title.js +0 -119
- package/src/utils/tokens.js +0 -92
- package/src/utils/toonFormat.js +0 -379
|
@@ -1,421 +0,0 @@
|
|
|
1
|
-
// src/agents/AgentContext.test.ts
|
|
2
|
-
import { AgentContext } from './AgentContext';
|
|
3
|
-
import { Providers } from '@/common';
|
|
4
|
-
describe('AgentContext', () => {
|
|
5
|
-
describe('structured output', () => {
|
|
6
|
-
const baseConfig = {
|
|
7
|
-
agentId: 'test-agent',
|
|
8
|
-
provider: Providers.OPENAI,
|
|
9
|
-
clientOptions: {
|
|
10
|
-
model: 'gpt-4',
|
|
11
|
-
streaming: true,
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
describe('isStructuredOutputMode', () => {
|
|
15
|
-
it('should return false when structuredOutput is not configured', () => {
|
|
16
|
-
const context = AgentContext.fromConfig(baseConfig);
|
|
17
|
-
expect(context.isStructuredOutputMode).toBe(false);
|
|
18
|
-
});
|
|
19
|
-
it('should return false when structuredOutput has no schema', () => {
|
|
20
|
-
const config = {
|
|
21
|
-
...baseConfig,
|
|
22
|
-
structuredOutput: {
|
|
23
|
-
schema: undefined,
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
const context = AgentContext.fromConfig(config);
|
|
27
|
-
expect(context.isStructuredOutputMode).toBe(false);
|
|
28
|
-
});
|
|
29
|
-
it('should return false when structuredOutput schema is null', () => {
|
|
30
|
-
const config = {
|
|
31
|
-
...baseConfig,
|
|
32
|
-
structuredOutput: {
|
|
33
|
-
schema: null,
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
const context = AgentContext.fromConfig(config);
|
|
37
|
-
expect(context.isStructuredOutputMode).toBe(false);
|
|
38
|
-
});
|
|
39
|
-
it('should return true when structuredOutput has a valid schema', () => {
|
|
40
|
-
const config = {
|
|
41
|
-
...baseConfig,
|
|
42
|
-
structuredOutput: {
|
|
43
|
-
schema: {
|
|
44
|
-
type: 'object',
|
|
45
|
-
properties: {
|
|
46
|
-
answer: { type: 'string' },
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
const context = AgentContext.fromConfig(config);
|
|
52
|
-
expect(context.isStructuredOutputMode).toBe(true);
|
|
53
|
-
});
|
|
54
|
-
it('should return true with minimal schema', () => {
|
|
55
|
-
const config = {
|
|
56
|
-
...baseConfig,
|
|
57
|
-
structuredOutput: {
|
|
58
|
-
schema: { type: 'string' },
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
const context = AgentContext.fromConfig(config);
|
|
62
|
-
expect(context.isStructuredOutputMode).toBe(true);
|
|
63
|
-
});
|
|
64
|
-
// Snake_case structured_output tests (database/API format)
|
|
65
|
-
it('should return true when structured_output (snake_case) is enabled with schema', () => {
|
|
66
|
-
const config = {
|
|
67
|
-
...baseConfig,
|
|
68
|
-
structured_output: {
|
|
69
|
-
enabled: true,
|
|
70
|
-
schema: {
|
|
71
|
-
type: 'object',
|
|
72
|
-
properties: {
|
|
73
|
-
result: { type: 'string' },
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
const context = AgentContext.fromConfig(config);
|
|
79
|
-
expect(context.isStructuredOutputMode).toBe(true);
|
|
80
|
-
});
|
|
81
|
-
it('should return false when structured_output is not enabled', () => {
|
|
82
|
-
const config = {
|
|
83
|
-
...baseConfig,
|
|
84
|
-
structured_output: {
|
|
85
|
-
enabled: false,
|
|
86
|
-
schema: {
|
|
87
|
-
type: 'object',
|
|
88
|
-
properties: {
|
|
89
|
-
result: { type: 'string' },
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
const context = AgentContext.fromConfig(config);
|
|
95
|
-
expect(context.isStructuredOutputMode).toBe(false);
|
|
96
|
-
});
|
|
97
|
-
it('should return false when structured_output has no schema', () => {
|
|
98
|
-
const config = {
|
|
99
|
-
...baseConfig,
|
|
100
|
-
structured_output: {
|
|
101
|
-
enabled: true,
|
|
102
|
-
// No schema
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
const context = AgentContext.fromConfig(config);
|
|
106
|
-
expect(context.isStructuredOutputMode).toBe(false);
|
|
107
|
-
});
|
|
108
|
-
it('should prefer structuredOutput (camelCase) over structured_output (snake_case)', () => {
|
|
109
|
-
const config = {
|
|
110
|
-
...baseConfig,
|
|
111
|
-
structuredOutput: {
|
|
112
|
-
schema: {
|
|
113
|
-
type: 'object',
|
|
114
|
-
properties: { camel: { type: 'string' } },
|
|
115
|
-
},
|
|
116
|
-
name: 'CamelSchema',
|
|
117
|
-
},
|
|
118
|
-
structured_output: {
|
|
119
|
-
enabled: true,
|
|
120
|
-
schema: {
|
|
121
|
-
type: 'object',
|
|
122
|
-
properties: { snake: { type: 'string' } },
|
|
123
|
-
},
|
|
124
|
-
name: 'SnakeSchema',
|
|
125
|
-
},
|
|
126
|
-
};
|
|
127
|
-
const context = AgentContext.fromConfig(config);
|
|
128
|
-
expect(context.isStructuredOutputMode).toBe(true);
|
|
129
|
-
expect(context.structuredOutput?.name).toBe('CamelSchema');
|
|
130
|
-
});
|
|
131
|
-
it('should convert structured_output properties correctly', () => {
|
|
132
|
-
const config = {
|
|
133
|
-
...baseConfig,
|
|
134
|
-
structured_output: {
|
|
135
|
-
enabled: true,
|
|
136
|
-
schema: {
|
|
137
|
-
type: 'object',
|
|
138
|
-
properties: { data: { type: 'string' } },
|
|
139
|
-
},
|
|
140
|
-
name: 'TestResponse',
|
|
141
|
-
description: 'A test response',
|
|
142
|
-
mode: 'provider',
|
|
143
|
-
strict: true,
|
|
144
|
-
},
|
|
145
|
-
};
|
|
146
|
-
const context = AgentContext.fromConfig(config);
|
|
147
|
-
expect(context.structuredOutput).toEqual({
|
|
148
|
-
schema: {
|
|
149
|
-
type: 'object',
|
|
150
|
-
properties: { data: { type: 'string' } },
|
|
151
|
-
},
|
|
152
|
-
name: 'TestResponse',
|
|
153
|
-
description: 'A test response',
|
|
154
|
-
mode: 'provider',
|
|
155
|
-
strict: true,
|
|
156
|
-
});
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
describe('getStructuredOutputSchema', () => {
|
|
160
|
-
it('should return undefined when structuredOutput is not configured', () => {
|
|
161
|
-
const context = AgentContext.fromConfig(baseConfig);
|
|
162
|
-
expect(context.getStructuredOutputSchema()).toBeUndefined();
|
|
163
|
-
});
|
|
164
|
-
it('should return undefined when schema is not set', () => {
|
|
165
|
-
const config = {
|
|
166
|
-
...baseConfig,
|
|
167
|
-
structuredOutput: {},
|
|
168
|
-
};
|
|
169
|
-
const context = AgentContext.fromConfig(config);
|
|
170
|
-
expect(context.getStructuredOutputSchema()).toBeUndefined();
|
|
171
|
-
});
|
|
172
|
-
it('should return the schema as-is when properly configured', () => {
|
|
173
|
-
const schema = {
|
|
174
|
-
type: 'object',
|
|
175
|
-
properties: {
|
|
176
|
-
name: { type: 'string' },
|
|
177
|
-
age: { type: 'number' },
|
|
178
|
-
},
|
|
179
|
-
};
|
|
180
|
-
const config = {
|
|
181
|
-
...baseConfig,
|
|
182
|
-
structuredOutput: { schema },
|
|
183
|
-
};
|
|
184
|
-
const context = AgentContext.fromConfig(config);
|
|
185
|
-
const result = context.getStructuredOutputSchema();
|
|
186
|
-
expect(result).toMatchObject(schema);
|
|
187
|
-
});
|
|
188
|
-
it('should add type: object when properties exist but type is missing', () => {
|
|
189
|
-
const schema = {
|
|
190
|
-
properties: {
|
|
191
|
-
name: { type: 'string' },
|
|
192
|
-
},
|
|
193
|
-
};
|
|
194
|
-
const config = {
|
|
195
|
-
...baseConfig,
|
|
196
|
-
structuredOutput: { schema },
|
|
197
|
-
};
|
|
198
|
-
const context = AgentContext.fromConfig(config);
|
|
199
|
-
const result = context.getStructuredOutputSchema();
|
|
200
|
-
expect(result?.type).toBe('object');
|
|
201
|
-
});
|
|
202
|
-
it('should add title from config name', () => {
|
|
203
|
-
const config = {
|
|
204
|
-
...baseConfig,
|
|
205
|
-
structuredOutput: {
|
|
206
|
-
schema: { type: 'object' },
|
|
207
|
-
name: 'ResponseSchema',
|
|
208
|
-
},
|
|
209
|
-
};
|
|
210
|
-
const context = AgentContext.fromConfig(config);
|
|
211
|
-
const result = context.getStructuredOutputSchema();
|
|
212
|
-
expect(result?.title).toBe('ResponseSchema');
|
|
213
|
-
});
|
|
214
|
-
it('should not override existing title', () => {
|
|
215
|
-
const config = {
|
|
216
|
-
...baseConfig,
|
|
217
|
-
structuredOutput: {
|
|
218
|
-
schema: { type: 'object', title: 'ExistingTitle' },
|
|
219
|
-
name: 'NewName',
|
|
220
|
-
},
|
|
221
|
-
};
|
|
222
|
-
const context = AgentContext.fromConfig(config);
|
|
223
|
-
const result = context.getStructuredOutputSchema();
|
|
224
|
-
expect(result?.title).toBe('ExistingTitle');
|
|
225
|
-
});
|
|
226
|
-
it('should add description from config', () => {
|
|
227
|
-
const config = {
|
|
228
|
-
...baseConfig,
|
|
229
|
-
structuredOutput: {
|
|
230
|
-
schema: { type: 'object' },
|
|
231
|
-
description: 'A structured response',
|
|
232
|
-
},
|
|
233
|
-
};
|
|
234
|
-
const context = AgentContext.fromConfig(config);
|
|
235
|
-
const result = context.getStructuredOutputSchema();
|
|
236
|
-
expect(result?.description).toBe('A structured response');
|
|
237
|
-
});
|
|
238
|
-
it('should not override existing description', () => {
|
|
239
|
-
const config = {
|
|
240
|
-
...baseConfig,
|
|
241
|
-
structuredOutput: {
|
|
242
|
-
schema: { type: 'object', description: 'Original description' },
|
|
243
|
-
description: 'New description',
|
|
244
|
-
},
|
|
245
|
-
};
|
|
246
|
-
const context = AgentContext.fromConfig(config);
|
|
247
|
-
const result = context.getStructuredOutputSchema();
|
|
248
|
-
expect(result?.description).toBe('Original description');
|
|
249
|
-
});
|
|
250
|
-
it('should set additionalProperties: false in strict mode by default', () => {
|
|
251
|
-
const config = {
|
|
252
|
-
...baseConfig,
|
|
253
|
-
structuredOutput: {
|
|
254
|
-
schema: { type: 'object', properties: {} },
|
|
255
|
-
},
|
|
256
|
-
};
|
|
257
|
-
const context = AgentContext.fromConfig(config);
|
|
258
|
-
const result = context.getStructuredOutputSchema();
|
|
259
|
-
expect(result?.additionalProperties).toBe(false);
|
|
260
|
-
});
|
|
261
|
-
it('should set additionalProperties: false when strict is explicitly true', () => {
|
|
262
|
-
const config = {
|
|
263
|
-
...baseConfig,
|
|
264
|
-
structuredOutput: {
|
|
265
|
-
schema: { type: 'object', properties: {} },
|
|
266
|
-
strict: true,
|
|
267
|
-
},
|
|
268
|
-
};
|
|
269
|
-
const context = AgentContext.fromConfig(config);
|
|
270
|
-
const result = context.getStructuredOutputSchema();
|
|
271
|
-
expect(result?.additionalProperties).toBe(false);
|
|
272
|
-
});
|
|
273
|
-
it('should not set additionalProperties when strict is false', () => {
|
|
274
|
-
const config = {
|
|
275
|
-
...baseConfig,
|
|
276
|
-
structuredOutput: {
|
|
277
|
-
schema: { type: 'object', properties: {} },
|
|
278
|
-
strict: false,
|
|
279
|
-
},
|
|
280
|
-
};
|
|
281
|
-
const context = AgentContext.fromConfig(config);
|
|
282
|
-
const result = context.getStructuredOutputSchema();
|
|
283
|
-
expect(result?.additionalProperties).toBeUndefined();
|
|
284
|
-
});
|
|
285
|
-
it('should preserve existing additionalProperties value', () => {
|
|
286
|
-
const config = {
|
|
287
|
-
...baseConfig,
|
|
288
|
-
structuredOutput: {
|
|
289
|
-
schema: {
|
|
290
|
-
type: 'object',
|
|
291
|
-
properties: {},
|
|
292
|
-
additionalProperties: true,
|
|
293
|
-
},
|
|
294
|
-
strict: true,
|
|
295
|
-
},
|
|
296
|
-
};
|
|
297
|
-
const context = AgentContext.fromConfig(config);
|
|
298
|
-
const result = context.getStructuredOutputSchema();
|
|
299
|
-
expect(result?.additionalProperties).toBe(true);
|
|
300
|
-
});
|
|
301
|
-
it('should not affect non-object types', () => {
|
|
302
|
-
const config = {
|
|
303
|
-
...baseConfig,
|
|
304
|
-
structuredOutput: {
|
|
305
|
-
schema: { type: 'array', items: { type: 'string' } },
|
|
306
|
-
},
|
|
307
|
-
};
|
|
308
|
-
const context = AgentContext.fromConfig(config);
|
|
309
|
-
const result = context.getStructuredOutputSchema();
|
|
310
|
-
expect(result?.additionalProperties).toBeUndefined();
|
|
311
|
-
expect(result?.type).toBe('array');
|
|
312
|
-
});
|
|
313
|
-
it('should not mutate the original schema', () => {
|
|
314
|
-
const originalSchema = {
|
|
315
|
-
type: 'object',
|
|
316
|
-
properties: { name: { type: 'string' } },
|
|
317
|
-
};
|
|
318
|
-
const config = {
|
|
319
|
-
...baseConfig,
|
|
320
|
-
structuredOutput: {
|
|
321
|
-
schema: originalSchema,
|
|
322
|
-
name: 'TestSchema',
|
|
323
|
-
description: 'Test description',
|
|
324
|
-
},
|
|
325
|
-
};
|
|
326
|
-
const context = AgentContext.fromConfig(config);
|
|
327
|
-
context.getStructuredOutputSchema();
|
|
328
|
-
// Original should not have been modified
|
|
329
|
-
expect(originalSchema).not.toHaveProperty('title');
|
|
330
|
-
expect(originalSchema).not.toHaveProperty('description');
|
|
331
|
-
expect(originalSchema).not.toHaveProperty('additionalProperties');
|
|
332
|
-
});
|
|
333
|
-
});
|
|
334
|
-
describe('fromConfig with structuredOutput', () => {
|
|
335
|
-
it('should properly initialize structuredOutput from config', () => {
|
|
336
|
-
const structuredOutput = {
|
|
337
|
-
schema: {
|
|
338
|
-
type: 'object',
|
|
339
|
-
properties: {
|
|
340
|
-
response: { type: 'string' },
|
|
341
|
-
confidence: { type: 'number' },
|
|
342
|
-
},
|
|
343
|
-
required: ['response'],
|
|
344
|
-
},
|
|
345
|
-
name: 'AnalysisResult',
|
|
346
|
-
description: 'The analysis result',
|
|
347
|
-
mode: 'auto',
|
|
348
|
-
strict: true,
|
|
349
|
-
};
|
|
350
|
-
const config = {
|
|
351
|
-
...baseConfig,
|
|
352
|
-
structuredOutput,
|
|
353
|
-
};
|
|
354
|
-
const context = AgentContext.fromConfig(config);
|
|
355
|
-
expect(context.isStructuredOutputMode).toBe(true);
|
|
356
|
-
expect(context.structuredOutput).toEqual(structuredOutput);
|
|
357
|
-
});
|
|
358
|
-
it('should handle all mode options', () => {
|
|
359
|
-
const modes = [
|
|
360
|
-
'auto',
|
|
361
|
-
'tool',
|
|
362
|
-
'provider',
|
|
363
|
-
];
|
|
364
|
-
for (const mode of modes) {
|
|
365
|
-
const config = {
|
|
366
|
-
...baseConfig,
|
|
367
|
-
structuredOutput: {
|
|
368
|
-
schema: { type: 'object' },
|
|
369
|
-
mode,
|
|
370
|
-
},
|
|
371
|
-
};
|
|
372
|
-
const context = AgentContext.fromConfig(config);
|
|
373
|
-
expect(context.structuredOutput?.mode).toBe(mode);
|
|
374
|
-
}
|
|
375
|
-
});
|
|
376
|
-
});
|
|
377
|
-
});
|
|
378
|
-
describe('summarizeCallback', () => {
|
|
379
|
-
const baseConfig = {
|
|
380
|
-
agentId: 'test-agent',
|
|
381
|
-
provider: Providers.OPENAI,
|
|
382
|
-
clientOptions: {
|
|
383
|
-
model: 'gpt-4',
|
|
384
|
-
streaming: true,
|
|
385
|
-
},
|
|
386
|
-
};
|
|
387
|
-
it('should not have summarizeCallback by default', () => {
|
|
388
|
-
const context = AgentContext.fromConfig(baseConfig);
|
|
389
|
-
expect(context.summarizeCallback).toBeUndefined();
|
|
390
|
-
});
|
|
391
|
-
it('should set summarizeCallback when provided in config', () => {
|
|
392
|
-
const config = {
|
|
393
|
-
...baseConfig,
|
|
394
|
-
summarizeCallback: async () => 'summary',
|
|
395
|
-
};
|
|
396
|
-
const context = AgentContext.fromConfig(config);
|
|
397
|
-
expect(context.summarizeCallback).toBeDefined();
|
|
398
|
-
});
|
|
399
|
-
it('should preserve summarizeCallback function reference', () => {
|
|
400
|
-
const mockCallback = jest.fn(async () => 'mock summary');
|
|
401
|
-
const config = {
|
|
402
|
-
...baseConfig,
|
|
403
|
-
summarizeCallback: mockCallback,
|
|
404
|
-
};
|
|
405
|
-
const context = AgentContext.fromConfig(config);
|
|
406
|
-
expect(context.summarizeCallback).toBe(mockCallback);
|
|
407
|
-
});
|
|
408
|
-
it('should allow summarizeCallback to be called', async () => {
|
|
409
|
-
const mockCallback = jest.fn(async () => 'summarized content');
|
|
410
|
-
const config = {
|
|
411
|
-
...baseConfig,
|
|
412
|
-
summarizeCallback: mockCallback,
|
|
413
|
-
};
|
|
414
|
-
const context = AgentContext.fromConfig(config);
|
|
415
|
-
const result = await context.summarizeCallback([]);
|
|
416
|
-
expect(result).toBe('summarized content');
|
|
417
|
-
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
418
|
-
});
|
|
419
|
-
});
|
|
420
|
-
});
|
|
421
|
-
//# sourceMappingURL=AgentContext.test.js.map
|