@iqai/adk 0.3.6 → 0.4.0
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/CHANGELOG.md +17 -0
- package/dist/index.d.mts +9 -3
- package/dist/index.d.ts +9 -3
- package/dist/index.js +39 -10
- package/dist/index.mjs +39 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @iqai/adk
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- c538a1a: feat(adk): align before/after model callback signatures with runtime (single object arg) and wire before/after tool callbacks into tool execution.
|
|
8
|
+
|
|
9
|
+
- beforeModelCallback/afterModelCallback now receive `{ callbackContext, llmRequest|llmResponse }` to match runtime invocation; removes need for casts in examples.
|
|
10
|
+
- beforeToolCallback/afterToolCallback are now invoked around tool execution; allow argument mutation and result override.
|
|
11
|
+
- tracing updated to include final args and the produced event.
|
|
12
|
+
- minor lint/style cleanups in flows.
|
|
13
|
+
|
|
14
|
+
## 0.3.7
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 737cb0f: Adds support for gpt 5 models
|
|
19
|
+
|
|
3
20
|
## 0.3.6
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -1252,7 +1252,10 @@ type ToolUnion = BaseTool | ((...args: any[]) => any);
|
|
|
1252
1252
|
/**
|
|
1253
1253
|
* Single before model callback type
|
|
1254
1254
|
*/
|
|
1255
|
-
type SingleBeforeModelCallback = (
|
|
1255
|
+
type SingleBeforeModelCallback = (args: {
|
|
1256
|
+
callbackContext: CallbackContext;
|
|
1257
|
+
llmRequest: LlmRequest;
|
|
1258
|
+
}) => LlmResponse | null | Promise<LlmResponse | null>;
|
|
1256
1259
|
/**
|
|
1257
1260
|
* Before model callback type (single or array)
|
|
1258
1261
|
*/
|
|
@@ -1260,7 +1263,10 @@ type BeforeModelCallback = SingleBeforeModelCallback | SingleBeforeModelCallback
|
|
|
1260
1263
|
/**
|
|
1261
1264
|
* Single after model callback type
|
|
1262
1265
|
*/
|
|
1263
|
-
type SingleAfterModelCallback = (
|
|
1266
|
+
type SingleAfterModelCallback = (args: {
|
|
1267
|
+
callbackContext: CallbackContext;
|
|
1268
|
+
llmResponse: LlmResponse;
|
|
1269
|
+
}) => LlmResponse | null | Promise<LlmResponse | null>;
|
|
1264
1270
|
/**
|
|
1265
1271
|
* After model callback type (single or array)
|
|
1266
1272
|
*/
|
|
@@ -1517,7 +1523,7 @@ declare class LlmAgent<T extends BaseLlm = BaseLlm> extends BaseAgent {
|
|
|
1517
1523
|
* The resolved tools field as a list of BaseTool based on the context
|
|
1518
1524
|
* This method is only for use by Agent Development Kit
|
|
1519
1525
|
*/
|
|
1520
|
-
canonicalTools(
|
|
1526
|
+
canonicalTools(_ctx?: ReadonlyContext): Promise<BaseTool[]>;
|
|
1521
1527
|
/**
|
|
1522
1528
|
* Gets the canonical before model callbacks as an array
|
|
1523
1529
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -1252,7 +1252,10 @@ type ToolUnion = BaseTool | ((...args: any[]) => any);
|
|
|
1252
1252
|
/**
|
|
1253
1253
|
* Single before model callback type
|
|
1254
1254
|
*/
|
|
1255
|
-
type SingleBeforeModelCallback = (
|
|
1255
|
+
type SingleBeforeModelCallback = (args: {
|
|
1256
|
+
callbackContext: CallbackContext;
|
|
1257
|
+
llmRequest: LlmRequest;
|
|
1258
|
+
}) => LlmResponse | null | Promise<LlmResponse | null>;
|
|
1256
1259
|
/**
|
|
1257
1260
|
* Before model callback type (single or array)
|
|
1258
1261
|
*/
|
|
@@ -1260,7 +1263,10 @@ type BeforeModelCallback = SingleBeforeModelCallback | SingleBeforeModelCallback
|
|
|
1260
1263
|
/**
|
|
1261
1264
|
* Single after model callback type
|
|
1262
1265
|
*/
|
|
1263
|
-
type SingleAfterModelCallback = (
|
|
1266
|
+
type SingleAfterModelCallback = (args: {
|
|
1267
|
+
callbackContext: CallbackContext;
|
|
1268
|
+
llmResponse: LlmResponse;
|
|
1269
|
+
}) => LlmResponse | null | Promise<LlmResponse | null>;
|
|
1264
1270
|
/**
|
|
1265
1271
|
* After model callback type (single or array)
|
|
1266
1272
|
*/
|
|
@@ -1517,7 +1523,7 @@ declare class LlmAgent<T extends BaseLlm = BaseLlm> extends BaseAgent {
|
|
|
1517
1523
|
* The resolved tools field as a list of BaseTool based on the context
|
|
1518
1524
|
* This method is only for use by Agent Development Kit
|
|
1519
1525
|
*/
|
|
1520
|
-
canonicalTools(
|
|
1526
|
+
canonicalTools(_ctx?: ReadonlyContext): Promise<BaseTool[]>;
|
|
1521
1527
|
/**
|
|
1522
1528
|
* Gets the canonical before model callbacks as an array
|
|
1523
1529
|
*/
|
package/dist/index.js
CHANGED
|
@@ -2343,7 +2343,7 @@ var OpenAiLlm = class extends BaseLlm {
|
|
|
2343
2343
|
* Provides the list of supported models
|
|
2344
2344
|
*/
|
|
2345
2345
|
static supportedModels() {
|
|
2346
|
-
return ["gpt-3.5-.*", "gpt-4.*", "gpt-4o.*", "o1-.*", "o3-.*"];
|
|
2346
|
+
return ["gpt-3.5-.*", "gpt-4.*", "gpt-4o.*", "gpt-5.*", "o1-.*", "o3-.*"];
|
|
2347
2347
|
}
|
|
2348
2348
|
/**
|
|
2349
2349
|
* Main content generation method - handles both streaming and non-streaming
|
|
@@ -6531,7 +6531,6 @@ async function handleFunctionCallsAsync(invocationContext, functionCallEvent, to
|
|
|
6531
6531
|
}
|
|
6532
6532
|
const { tool, toolContext } = getToolAndContext(
|
|
6533
6533
|
invocationContext,
|
|
6534
|
-
functionCallEvent,
|
|
6535
6534
|
functionCall,
|
|
6536
6535
|
toolsDict
|
|
6537
6536
|
);
|
|
@@ -6541,10 +6540,44 @@ async function handleFunctionCallsAsync(invocationContext, functionCallEvent, to
|
|
|
6541
6540
|
const spanContext = _api.trace.setSpan(_api.context.active(), span);
|
|
6542
6541
|
try {
|
|
6543
6542
|
const functionResponse = await _api.context.with(spanContext, async () => {
|
|
6544
|
-
const
|
|
6543
|
+
const argsForTool = { ...functionArgs };
|
|
6544
|
+
if (isLlmAgent2(agent)) {
|
|
6545
|
+
for (const cb of agent.canonicalBeforeToolCallbacks) {
|
|
6546
|
+
const maybeOverride = await cb(tool, argsForTool, toolContext);
|
|
6547
|
+
if (maybeOverride !== null && maybeOverride !== void 0) {
|
|
6548
|
+
const overriddenEvent = buildResponseEvent(
|
|
6549
|
+
tool,
|
|
6550
|
+
maybeOverride,
|
|
6551
|
+
toolContext,
|
|
6552
|
+
invocationContext
|
|
6553
|
+
);
|
|
6554
|
+
telemetryService.traceToolCall(
|
|
6555
|
+
tool,
|
|
6556
|
+
argsForTool,
|
|
6557
|
+
overriddenEvent
|
|
6558
|
+
);
|
|
6559
|
+
return { result: maybeOverride, event: overriddenEvent };
|
|
6560
|
+
}
|
|
6561
|
+
}
|
|
6562
|
+
}
|
|
6563
|
+
let result = await callToolAsync(tool, argsForTool, toolContext);
|
|
6545
6564
|
if (tool.isLongRunning && !result) {
|
|
6546
6565
|
return null;
|
|
6547
6566
|
}
|
|
6567
|
+
if (isLlmAgent2(agent)) {
|
|
6568
|
+
for (const cb of agent.canonicalAfterToolCallbacks) {
|
|
6569
|
+
const maybeModified = await cb(
|
|
6570
|
+
tool,
|
|
6571
|
+
argsForTool,
|
|
6572
|
+
toolContext,
|
|
6573
|
+
result
|
|
6574
|
+
);
|
|
6575
|
+
if (maybeModified !== null && maybeModified !== void 0) {
|
|
6576
|
+
result = maybeModified;
|
|
6577
|
+
break;
|
|
6578
|
+
}
|
|
6579
|
+
}
|
|
6580
|
+
}
|
|
6548
6581
|
const functionResponseEvent = buildResponseEvent(
|
|
6549
6582
|
tool,
|
|
6550
6583
|
result,
|
|
@@ -6553,7 +6586,7 @@ async function handleFunctionCallsAsync(invocationContext, functionCallEvent, to
|
|
|
6553
6586
|
);
|
|
6554
6587
|
telemetryService.traceToolCall(
|
|
6555
6588
|
tool,
|
|
6556
|
-
|
|
6589
|
+
argsForTool,
|
|
6557
6590
|
functionResponseEvent
|
|
6558
6591
|
);
|
|
6559
6592
|
return { result, event: functionResponseEvent };
|
|
@@ -6583,7 +6616,7 @@ async function handleFunctionCallsLive(invocationContext, functionCallEvent, too
|
|
|
6583
6616
|
toolsDict
|
|
6584
6617
|
);
|
|
6585
6618
|
}
|
|
6586
|
-
function getToolAndContext(invocationContext,
|
|
6619
|
+
function getToolAndContext(invocationContext, functionCall, toolsDict) {
|
|
6587
6620
|
if (!(functionCall.name in toolsDict)) {
|
|
6588
6621
|
throw new Error(
|
|
6589
6622
|
`Function ${functionCall.name} is not found in the tools_dict.`
|
|
@@ -6700,12 +6733,10 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6700
6733
|
}
|
|
6701
6734
|
async *_runOneStepAsync(invocationContext) {
|
|
6702
6735
|
const llmRequest = new LlmRequest();
|
|
6703
|
-
let preprocessEventCount = 0;
|
|
6704
6736
|
for await (const event of this._preprocessAsync(
|
|
6705
6737
|
invocationContext,
|
|
6706
6738
|
llmRequest
|
|
6707
6739
|
)) {
|
|
6708
|
-
preprocessEventCount++;
|
|
6709
6740
|
yield event;
|
|
6710
6741
|
}
|
|
6711
6742
|
if (invocationContext.endInvocation) {
|
|
@@ -6718,13 +6749,11 @@ var BaseLlmFlow = (_class25 = class {constructor() { _class25.prototype.__init43
|
|
|
6718
6749
|
author: invocationContext.agent.name,
|
|
6719
6750
|
branch: invocationContext.branch
|
|
6720
6751
|
});
|
|
6721
|
-
let llmResponseCount = 0;
|
|
6722
6752
|
for await (const llmResponse of this._callLlmAsync(
|
|
6723
6753
|
invocationContext,
|
|
6724
6754
|
llmRequest,
|
|
6725
6755
|
modelResponseEvent
|
|
6726
6756
|
)) {
|
|
6727
|
-
llmResponseCount++;
|
|
6728
6757
|
for await (const event of this._postprocessAsync(
|
|
6729
6758
|
invocationContext,
|
|
6730
6759
|
llmRequest,
|
|
@@ -9241,7 +9270,7 @@ var LlmAgent = (_class27 = class _LlmAgent extends BaseAgent {
|
|
|
9241
9270
|
* The resolved tools field as a list of BaseTool based on the context
|
|
9242
9271
|
* This method is only for use by Agent Development Kit
|
|
9243
9272
|
*/
|
|
9244
|
-
async canonicalTools(
|
|
9273
|
+
async canonicalTools(_ctx) {
|
|
9245
9274
|
const resolvedTools = [];
|
|
9246
9275
|
for (const toolUnion of this.tools) {
|
|
9247
9276
|
if (typeof toolUnion === "function") {
|
package/dist/index.mjs
CHANGED
|
@@ -2343,7 +2343,7 @@ var OpenAiLlm = class extends BaseLlm {
|
|
|
2343
2343
|
* Provides the list of supported models
|
|
2344
2344
|
*/
|
|
2345
2345
|
static supportedModels() {
|
|
2346
|
-
return ["gpt-3.5-.*", "gpt-4.*", "gpt-4o.*", "o1-.*", "o3-.*"];
|
|
2346
|
+
return ["gpt-3.5-.*", "gpt-4.*", "gpt-4o.*", "gpt-5.*", "o1-.*", "o3-.*"];
|
|
2347
2347
|
}
|
|
2348
2348
|
/**
|
|
2349
2349
|
* Main content generation method - handles both streaming and non-streaming
|
|
@@ -6531,7 +6531,6 @@ async function handleFunctionCallsAsync(invocationContext, functionCallEvent, to
|
|
|
6531
6531
|
}
|
|
6532
6532
|
const { tool, toolContext } = getToolAndContext(
|
|
6533
6533
|
invocationContext,
|
|
6534
|
-
functionCallEvent,
|
|
6535
6534
|
functionCall,
|
|
6536
6535
|
toolsDict
|
|
6537
6536
|
);
|
|
@@ -6541,10 +6540,44 @@ async function handleFunctionCallsAsync(invocationContext, functionCallEvent, to
|
|
|
6541
6540
|
const spanContext = trace2.setSpan(context2.active(), span);
|
|
6542
6541
|
try {
|
|
6543
6542
|
const functionResponse = await context2.with(spanContext, async () => {
|
|
6544
|
-
const
|
|
6543
|
+
const argsForTool = { ...functionArgs };
|
|
6544
|
+
if (isLlmAgent2(agent)) {
|
|
6545
|
+
for (const cb of agent.canonicalBeforeToolCallbacks) {
|
|
6546
|
+
const maybeOverride = await cb(tool, argsForTool, toolContext);
|
|
6547
|
+
if (maybeOverride !== null && maybeOverride !== void 0) {
|
|
6548
|
+
const overriddenEvent = buildResponseEvent(
|
|
6549
|
+
tool,
|
|
6550
|
+
maybeOverride,
|
|
6551
|
+
toolContext,
|
|
6552
|
+
invocationContext
|
|
6553
|
+
);
|
|
6554
|
+
telemetryService.traceToolCall(
|
|
6555
|
+
tool,
|
|
6556
|
+
argsForTool,
|
|
6557
|
+
overriddenEvent
|
|
6558
|
+
);
|
|
6559
|
+
return { result: maybeOverride, event: overriddenEvent };
|
|
6560
|
+
}
|
|
6561
|
+
}
|
|
6562
|
+
}
|
|
6563
|
+
let result = await callToolAsync(tool, argsForTool, toolContext);
|
|
6545
6564
|
if (tool.isLongRunning && !result) {
|
|
6546
6565
|
return null;
|
|
6547
6566
|
}
|
|
6567
|
+
if (isLlmAgent2(agent)) {
|
|
6568
|
+
for (const cb of agent.canonicalAfterToolCallbacks) {
|
|
6569
|
+
const maybeModified = await cb(
|
|
6570
|
+
tool,
|
|
6571
|
+
argsForTool,
|
|
6572
|
+
toolContext,
|
|
6573
|
+
result
|
|
6574
|
+
);
|
|
6575
|
+
if (maybeModified !== null && maybeModified !== void 0) {
|
|
6576
|
+
result = maybeModified;
|
|
6577
|
+
break;
|
|
6578
|
+
}
|
|
6579
|
+
}
|
|
6580
|
+
}
|
|
6548
6581
|
const functionResponseEvent = buildResponseEvent(
|
|
6549
6582
|
tool,
|
|
6550
6583
|
result,
|
|
@@ -6553,7 +6586,7 @@ async function handleFunctionCallsAsync(invocationContext, functionCallEvent, to
|
|
|
6553
6586
|
);
|
|
6554
6587
|
telemetryService.traceToolCall(
|
|
6555
6588
|
tool,
|
|
6556
|
-
|
|
6589
|
+
argsForTool,
|
|
6557
6590
|
functionResponseEvent
|
|
6558
6591
|
);
|
|
6559
6592
|
return { result, event: functionResponseEvent };
|
|
@@ -6583,7 +6616,7 @@ async function handleFunctionCallsLive(invocationContext, functionCallEvent, too
|
|
|
6583
6616
|
toolsDict
|
|
6584
6617
|
);
|
|
6585
6618
|
}
|
|
6586
|
-
function getToolAndContext(invocationContext,
|
|
6619
|
+
function getToolAndContext(invocationContext, functionCall, toolsDict) {
|
|
6587
6620
|
if (!(functionCall.name in toolsDict)) {
|
|
6588
6621
|
throw new Error(
|
|
6589
6622
|
`Function ${functionCall.name} is not found in the tools_dict.`
|
|
@@ -6700,12 +6733,10 @@ var BaseLlmFlow = class {
|
|
|
6700
6733
|
}
|
|
6701
6734
|
async *_runOneStepAsync(invocationContext) {
|
|
6702
6735
|
const llmRequest = new LlmRequest();
|
|
6703
|
-
let preprocessEventCount = 0;
|
|
6704
6736
|
for await (const event of this._preprocessAsync(
|
|
6705
6737
|
invocationContext,
|
|
6706
6738
|
llmRequest
|
|
6707
6739
|
)) {
|
|
6708
|
-
preprocessEventCount++;
|
|
6709
6740
|
yield event;
|
|
6710
6741
|
}
|
|
6711
6742
|
if (invocationContext.endInvocation) {
|
|
@@ -6718,13 +6749,11 @@ var BaseLlmFlow = class {
|
|
|
6718
6749
|
author: invocationContext.agent.name,
|
|
6719
6750
|
branch: invocationContext.branch
|
|
6720
6751
|
});
|
|
6721
|
-
let llmResponseCount = 0;
|
|
6722
6752
|
for await (const llmResponse of this._callLlmAsync(
|
|
6723
6753
|
invocationContext,
|
|
6724
6754
|
llmRequest,
|
|
6725
6755
|
modelResponseEvent
|
|
6726
6756
|
)) {
|
|
6727
|
-
llmResponseCount++;
|
|
6728
6757
|
for await (const event of this._postprocessAsync(
|
|
6729
6758
|
invocationContext,
|
|
6730
6759
|
llmRequest,
|
|
@@ -9241,7 +9270,7 @@ var LlmAgent = class _LlmAgent extends BaseAgent {
|
|
|
9241
9270
|
* The resolved tools field as a list of BaseTool based on the context
|
|
9242
9271
|
* This method is only for use by Agent Development Kit
|
|
9243
9272
|
*/
|
|
9244
|
-
async canonicalTools(
|
|
9273
|
+
async canonicalTools(_ctx) {
|
|
9245
9274
|
const resolvedTools = [];
|
|
9246
9275
|
for (const toolUnion of this.tools) {
|
|
9247
9276
|
if (typeof toolUnion === "function") {
|