@iqai/adk 0.6.0 → 0.6.1
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.js +103 -26
- package/dist/index.mjs +103 -26
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @iqai/adk
|
|
2
2
|
|
|
3
|
+
## 0.6.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3f78ed9: Fix: Wire up all missing plugin lifecycle callbacks
|
|
8
|
+
|
|
9
|
+
The PluginManager had several callback methods defined but never invoked, causing plugins implementing guardrails, logging, or error recovery to be silently ignored.
|
|
10
|
+
|
|
11
|
+
This fix adds the missing calls for:
|
|
12
|
+
|
|
13
|
+
- `beforeModelCallback` / `afterModelCallback` - intercept LLM requests/responses
|
|
14
|
+
- `onModelErrorCallback` - handle/recover from LLM errors
|
|
15
|
+
- `beforeToolCallback` / `afterToolCallback` - intercept tool execution
|
|
16
|
+
- `onToolErrorCallback` - handle/recover from tool errors
|
|
17
|
+
|
|
18
|
+
All 12 plugin callbacks are now properly wired up and invoked at the appropriate lifecycle points.
|
|
19
|
+
|
|
3
20
|
## 0.6.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
package/dist/index.js
CHANGED
|
@@ -7963,35 +7963,35 @@ async function handleFunctionCallsAsync(invocationContext, functionCallEvent, to
|
|
|
7963
7963
|
try {
|
|
7964
7964
|
const functionResponse = await _api.context.with(spanContext, async () => {
|
|
7965
7965
|
const argsForTool = { ...functionArgs };
|
|
7966
|
+
const pluginOverride = await invocationContext.pluginManager.runBeforeToolCallback({
|
|
7967
|
+
tool,
|
|
7968
|
+
toolArgs: argsForTool,
|
|
7969
|
+
toolContext
|
|
7970
|
+
});
|
|
7971
|
+
if (pluginOverride !== null && pluginOverride !== void 0) {
|
|
7972
|
+
wasOverridden = true;
|
|
7973
|
+
return handleToolOverride(
|
|
7974
|
+
pluginOverride,
|
|
7975
|
+
tool,
|
|
7976
|
+
argsForTool,
|
|
7977
|
+
toolContext,
|
|
7978
|
+
invocationContext,
|
|
7979
|
+
executionOrder
|
|
7980
|
+
);
|
|
7981
|
+
}
|
|
7966
7982
|
if (isLlmAgent2(agent)) {
|
|
7967
7983
|
for (const cb of agent.canonicalBeforeToolCallbacks) {
|
|
7968
7984
|
const maybeOverride = await cb(tool, argsForTool, toolContext);
|
|
7969
7985
|
if (maybeOverride !== null && maybeOverride !== void 0) {
|
|
7970
7986
|
wasOverridden = true;
|
|
7971
|
-
|
|
7972
|
-
tool,
|
|
7987
|
+
return handleToolOverride(
|
|
7973
7988
|
maybeOverride,
|
|
7974
|
-
toolContext,
|
|
7975
|
-
invocationContext
|
|
7976
|
-
);
|
|
7977
|
-
telemetryService.traceToolCall(
|
|
7978
7989
|
tool,
|
|
7979
7990
|
argsForTool,
|
|
7980
|
-
|
|
7981
|
-
|
|
7982
|
-
|
|
7983
|
-
invocationContext
|
|
7984
|
-
);
|
|
7985
|
-
telemetryService.traceEnhancedTool(
|
|
7986
|
-
executionOrder,
|
|
7987
|
-
void 0,
|
|
7988
|
-
// parallelGroup not used in sequential execution
|
|
7989
|
-
0,
|
|
7990
|
-
// no retry
|
|
7991
|
-
true
|
|
7992
|
-
// callback override
|
|
7991
|
+
toolContext,
|
|
7992
|
+
invocationContext,
|
|
7993
|
+
executionOrder
|
|
7993
7994
|
);
|
|
7994
|
-
return { result: maybeOverride, event: overriddenEvent };
|
|
7995
7995
|
}
|
|
7996
7996
|
}
|
|
7997
7997
|
}
|
|
@@ -7999,6 +7999,15 @@ async function handleFunctionCallsAsync(invocationContext, functionCallEvent, to
|
|
|
7999
7999
|
if (tool.isLongRunning && !result) {
|
|
8000
8000
|
return null;
|
|
8001
8001
|
}
|
|
8002
|
+
const pluginAfterResult = await invocationContext.pluginManager.runAfterToolCallback({
|
|
8003
|
+
tool,
|
|
8004
|
+
toolArgs: argsForTool,
|
|
8005
|
+
toolContext,
|
|
8006
|
+
result
|
|
8007
|
+
});
|
|
8008
|
+
if (pluginAfterResult !== null && pluginAfterResult !== void 0) {
|
|
8009
|
+
result = pluginAfterResult;
|
|
8010
|
+
}
|
|
8002
8011
|
if (isLlmAgent2(agent)) {
|
|
8003
8012
|
for (const cb of agent.canonicalAfterToolCallbacks) {
|
|
8004
8013
|
const maybeModified = await cb(
|
|
@@ -8068,6 +8077,22 @@ async function handleFunctionCallsAsync(invocationContext, functionCallEvent, to
|
|
|
8068
8077
|
status: toolStatus
|
|
8069
8078
|
});
|
|
8070
8079
|
telemetryService.recordError("tool", tool.name);
|
|
8080
|
+
const errorRecoveryResult = await invocationContext.pluginManager.runOnToolErrorCallback({
|
|
8081
|
+
tool,
|
|
8082
|
+
toolArgs: functionArgs,
|
|
8083
|
+
toolContext,
|
|
8084
|
+
error
|
|
8085
|
+
});
|
|
8086
|
+
if (errorRecoveryResult !== null && errorRecoveryResult !== void 0) {
|
|
8087
|
+
const recoveryEvent = buildResponseEvent(
|
|
8088
|
+
tool,
|
|
8089
|
+
errorRecoveryResult,
|
|
8090
|
+
toolContext,
|
|
8091
|
+
invocationContext
|
|
8092
|
+
);
|
|
8093
|
+
functionResponseEvents.push(recoveryEvent);
|
|
8094
|
+
continue;
|
|
8095
|
+
}
|
|
8071
8096
|
throw error;
|
|
8072
8097
|
} finally {
|
|
8073
8098
|
const toolDuration = Date.now() - toolStartTime;
|
|
@@ -8170,6 +8195,32 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
|
|
|
8170
8195
|
function isLlmAgent2(agent) {
|
|
8171
8196
|
return agent && typeof agent === "object" && "canonicalModel" in agent;
|
|
8172
8197
|
}
|
|
8198
|
+
function handleToolOverride(override, tool, argsForTool, toolContext, invocationContext, executionOrder) {
|
|
8199
|
+
const overriddenEvent = buildResponseEvent(
|
|
8200
|
+
tool,
|
|
8201
|
+
override,
|
|
8202
|
+
toolContext,
|
|
8203
|
+
invocationContext
|
|
8204
|
+
);
|
|
8205
|
+
telemetryService.traceToolCall(
|
|
8206
|
+
tool,
|
|
8207
|
+
argsForTool,
|
|
8208
|
+
overriddenEvent,
|
|
8209
|
+
void 0,
|
|
8210
|
+
// llmRequest
|
|
8211
|
+
invocationContext
|
|
8212
|
+
);
|
|
8213
|
+
telemetryService.traceEnhancedTool(
|
|
8214
|
+
executionOrder,
|
|
8215
|
+
void 0,
|
|
8216
|
+
// parallelGroup not used in sequential execution
|
|
8217
|
+
0,
|
|
8218
|
+
// no retry
|
|
8219
|
+
true
|
|
8220
|
+
// callback override
|
|
8221
|
+
);
|
|
8222
|
+
return { result: override, event: overriddenEvent };
|
|
8223
|
+
}
|
|
8173
8224
|
|
|
8174
8225
|
// src/flows/llm-flows/base-llm-flow.ts
|
|
8175
8226
|
var _ADK_AGENT_NAME_LABEL_KEY = "adk_agent_name";
|
|
@@ -8549,6 +8600,18 @@ var BaseLlmFlow = (_class26 = class {constructor() { _class26.prototype.__init55
|
|
|
8549
8600
|
} catch (error) {
|
|
8550
8601
|
llmStatus = "error";
|
|
8551
8602
|
telemetryService.recordError("llm", llm.model);
|
|
8603
|
+
const callbackContext = new CallbackContext(invocationContext, {
|
|
8604
|
+
eventActions: modelResponseEvent.actions
|
|
8605
|
+
});
|
|
8606
|
+
const errorRecoveryResponse = await invocationContext.pluginManager.runOnModelErrorCallback({
|
|
8607
|
+
callbackContext,
|
|
8608
|
+
llmRequest,
|
|
8609
|
+
error
|
|
8610
|
+
});
|
|
8611
|
+
if (errorRecoveryResponse) {
|
|
8612
|
+
yield errorRecoveryResponse;
|
|
8613
|
+
return;
|
|
8614
|
+
}
|
|
8552
8615
|
throw error;
|
|
8553
8616
|
} finally {
|
|
8554
8617
|
const llmDuration = Date.now() - llmStartTime;
|
|
@@ -8561,6 +8624,16 @@ var BaseLlmFlow = (_class26 = class {constructor() { _class26.prototype.__init55
|
|
|
8561
8624
|
}
|
|
8562
8625
|
}
|
|
8563
8626
|
async _handleBeforeModelCallback(invocationContext, llmRequest, modelResponseEvent) {
|
|
8627
|
+
const callbackContext = new CallbackContext(invocationContext, {
|
|
8628
|
+
eventActions: modelResponseEvent.actions
|
|
8629
|
+
});
|
|
8630
|
+
const pluginResult = await invocationContext.pluginManager.runBeforeModelCallback({
|
|
8631
|
+
callbackContext,
|
|
8632
|
+
llmRequest
|
|
8633
|
+
});
|
|
8634
|
+
if (pluginResult !== null && pluginResult !== void 0) {
|
|
8635
|
+
return pluginResult;
|
|
8636
|
+
}
|
|
8564
8637
|
const agent = invocationContext.agent;
|
|
8565
8638
|
if (!("canonicalBeforeModelCallbacks" in agent)) {
|
|
8566
8639
|
return;
|
|
@@ -8569,9 +8642,6 @@ var BaseLlmFlow = (_class26 = class {constructor() { _class26.prototype.__init55
|
|
|
8569
8642
|
if (!beforeCallbacks) {
|
|
8570
8643
|
return;
|
|
8571
8644
|
}
|
|
8572
|
-
const callbackContext = new CallbackContext(invocationContext, {
|
|
8573
|
-
eventActions: modelResponseEvent.actions
|
|
8574
|
-
});
|
|
8575
8645
|
for (const callback of beforeCallbacks) {
|
|
8576
8646
|
let beforeModelCallbackContent = callback({
|
|
8577
8647
|
callbackContext,
|
|
@@ -8586,6 +8656,16 @@ var BaseLlmFlow = (_class26 = class {constructor() { _class26.prototype.__init55
|
|
|
8586
8656
|
}
|
|
8587
8657
|
}
|
|
8588
8658
|
async _handleAfterModelCallback(invocationContext, llmResponse, modelResponseEvent) {
|
|
8659
|
+
const callbackContext = new CallbackContext(invocationContext, {
|
|
8660
|
+
eventActions: modelResponseEvent.actions
|
|
8661
|
+
});
|
|
8662
|
+
const pluginResult = await invocationContext.pluginManager.runAfterModelCallback({
|
|
8663
|
+
callbackContext,
|
|
8664
|
+
llmResponse
|
|
8665
|
+
});
|
|
8666
|
+
if (pluginResult) {
|
|
8667
|
+
return pluginResult;
|
|
8668
|
+
}
|
|
8589
8669
|
const agent = invocationContext.agent;
|
|
8590
8670
|
if (!("canonicalAfterModelCallbacks" in agent)) {
|
|
8591
8671
|
return;
|
|
@@ -8594,9 +8674,6 @@ var BaseLlmFlow = (_class26 = class {constructor() { _class26.prototype.__init55
|
|
|
8594
8674
|
if (!afterCallbacks) {
|
|
8595
8675
|
return;
|
|
8596
8676
|
}
|
|
8597
|
-
const callbackContext = new CallbackContext(invocationContext, {
|
|
8598
|
-
eventActions: modelResponseEvent.actions
|
|
8599
|
-
});
|
|
8600
8677
|
for (const callback of afterCallbacks) {
|
|
8601
8678
|
let afterModelCallbackContent = callback({
|
|
8602
8679
|
callbackContext,
|
package/dist/index.mjs
CHANGED
|
@@ -7963,35 +7963,35 @@ async function handleFunctionCallsAsync(invocationContext, functionCallEvent, to
|
|
|
7963
7963
|
try {
|
|
7964
7964
|
const functionResponse = await context2.with(spanContext, async () => {
|
|
7965
7965
|
const argsForTool = { ...functionArgs };
|
|
7966
|
+
const pluginOverride = await invocationContext.pluginManager.runBeforeToolCallback({
|
|
7967
|
+
tool,
|
|
7968
|
+
toolArgs: argsForTool,
|
|
7969
|
+
toolContext
|
|
7970
|
+
});
|
|
7971
|
+
if (pluginOverride !== null && pluginOverride !== void 0) {
|
|
7972
|
+
wasOverridden = true;
|
|
7973
|
+
return handleToolOverride(
|
|
7974
|
+
pluginOverride,
|
|
7975
|
+
tool,
|
|
7976
|
+
argsForTool,
|
|
7977
|
+
toolContext,
|
|
7978
|
+
invocationContext,
|
|
7979
|
+
executionOrder
|
|
7980
|
+
);
|
|
7981
|
+
}
|
|
7966
7982
|
if (isLlmAgent2(agent)) {
|
|
7967
7983
|
for (const cb of agent.canonicalBeforeToolCallbacks) {
|
|
7968
7984
|
const maybeOverride = await cb(tool, argsForTool, toolContext);
|
|
7969
7985
|
if (maybeOverride !== null && maybeOverride !== void 0) {
|
|
7970
7986
|
wasOverridden = true;
|
|
7971
|
-
|
|
7972
|
-
tool,
|
|
7987
|
+
return handleToolOverride(
|
|
7973
7988
|
maybeOverride,
|
|
7974
|
-
toolContext,
|
|
7975
|
-
invocationContext
|
|
7976
|
-
);
|
|
7977
|
-
telemetryService.traceToolCall(
|
|
7978
7989
|
tool,
|
|
7979
7990
|
argsForTool,
|
|
7980
|
-
|
|
7981
|
-
|
|
7982
|
-
|
|
7983
|
-
invocationContext
|
|
7984
|
-
);
|
|
7985
|
-
telemetryService.traceEnhancedTool(
|
|
7986
|
-
executionOrder,
|
|
7987
|
-
void 0,
|
|
7988
|
-
// parallelGroup not used in sequential execution
|
|
7989
|
-
0,
|
|
7990
|
-
// no retry
|
|
7991
|
-
true
|
|
7992
|
-
// callback override
|
|
7991
|
+
toolContext,
|
|
7992
|
+
invocationContext,
|
|
7993
|
+
executionOrder
|
|
7993
7994
|
);
|
|
7994
|
-
return { result: maybeOverride, event: overriddenEvent };
|
|
7995
7995
|
}
|
|
7996
7996
|
}
|
|
7997
7997
|
}
|
|
@@ -7999,6 +7999,15 @@ async function handleFunctionCallsAsync(invocationContext, functionCallEvent, to
|
|
|
7999
7999
|
if (tool.isLongRunning && !result) {
|
|
8000
8000
|
return null;
|
|
8001
8001
|
}
|
|
8002
|
+
const pluginAfterResult = await invocationContext.pluginManager.runAfterToolCallback({
|
|
8003
|
+
tool,
|
|
8004
|
+
toolArgs: argsForTool,
|
|
8005
|
+
toolContext,
|
|
8006
|
+
result
|
|
8007
|
+
});
|
|
8008
|
+
if (pluginAfterResult !== null && pluginAfterResult !== void 0) {
|
|
8009
|
+
result = pluginAfterResult;
|
|
8010
|
+
}
|
|
8002
8011
|
if (isLlmAgent2(agent)) {
|
|
8003
8012
|
for (const cb of agent.canonicalAfterToolCallbacks) {
|
|
8004
8013
|
const maybeModified = await cb(
|
|
@@ -8068,6 +8077,22 @@ async function handleFunctionCallsAsync(invocationContext, functionCallEvent, to
|
|
|
8068
8077
|
status: toolStatus
|
|
8069
8078
|
});
|
|
8070
8079
|
telemetryService.recordError("tool", tool.name);
|
|
8080
|
+
const errorRecoveryResult = await invocationContext.pluginManager.runOnToolErrorCallback({
|
|
8081
|
+
tool,
|
|
8082
|
+
toolArgs: functionArgs,
|
|
8083
|
+
toolContext,
|
|
8084
|
+
error
|
|
8085
|
+
});
|
|
8086
|
+
if (errorRecoveryResult !== null && errorRecoveryResult !== void 0) {
|
|
8087
|
+
const recoveryEvent = buildResponseEvent(
|
|
8088
|
+
tool,
|
|
8089
|
+
errorRecoveryResult,
|
|
8090
|
+
toolContext,
|
|
8091
|
+
invocationContext
|
|
8092
|
+
);
|
|
8093
|
+
functionResponseEvents.push(recoveryEvent);
|
|
8094
|
+
continue;
|
|
8095
|
+
}
|
|
8071
8096
|
throw error;
|
|
8072
8097
|
} finally {
|
|
8073
8098
|
const toolDuration = Date.now() - toolStartTime;
|
|
@@ -8170,6 +8195,32 @@ function mergeParallelFunctionResponseEvents(functionResponseEvents) {
|
|
|
8170
8195
|
function isLlmAgent2(agent) {
|
|
8171
8196
|
return agent && typeof agent === "object" && "canonicalModel" in agent;
|
|
8172
8197
|
}
|
|
8198
|
+
function handleToolOverride(override, tool, argsForTool, toolContext, invocationContext, executionOrder) {
|
|
8199
|
+
const overriddenEvent = buildResponseEvent(
|
|
8200
|
+
tool,
|
|
8201
|
+
override,
|
|
8202
|
+
toolContext,
|
|
8203
|
+
invocationContext
|
|
8204
|
+
);
|
|
8205
|
+
telemetryService.traceToolCall(
|
|
8206
|
+
tool,
|
|
8207
|
+
argsForTool,
|
|
8208
|
+
overriddenEvent,
|
|
8209
|
+
void 0,
|
|
8210
|
+
// llmRequest
|
|
8211
|
+
invocationContext
|
|
8212
|
+
);
|
|
8213
|
+
telemetryService.traceEnhancedTool(
|
|
8214
|
+
executionOrder,
|
|
8215
|
+
void 0,
|
|
8216
|
+
// parallelGroup not used in sequential execution
|
|
8217
|
+
0,
|
|
8218
|
+
// no retry
|
|
8219
|
+
true
|
|
8220
|
+
// callback override
|
|
8221
|
+
);
|
|
8222
|
+
return { result: override, event: overriddenEvent };
|
|
8223
|
+
}
|
|
8173
8224
|
|
|
8174
8225
|
// src/flows/llm-flows/base-llm-flow.ts
|
|
8175
8226
|
var _ADK_AGENT_NAME_LABEL_KEY = "adk_agent_name";
|
|
@@ -8549,6 +8600,18 @@ var BaseLlmFlow = class {
|
|
|
8549
8600
|
} catch (error) {
|
|
8550
8601
|
llmStatus = "error";
|
|
8551
8602
|
telemetryService.recordError("llm", llm.model);
|
|
8603
|
+
const callbackContext = new CallbackContext(invocationContext, {
|
|
8604
|
+
eventActions: modelResponseEvent.actions
|
|
8605
|
+
});
|
|
8606
|
+
const errorRecoveryResponse = await invocationContext.pluginManager.runOnModelErrorCallback({
|
|
8607
|
+
callbackContext,
|
|
8608
|
+
llmRequest,
|
|
8609
|
+
error
|
|
8610
|
+
});
|
|
8611
|
+
if (errorRecoveryResponse) {
|
|
8612
|
+
yield errorRecoveryResponse;
|
|
8613
|
+
return;
|
|
8614
|
+
}
|
|
8552
8615
|
throw error;
|
|
8553
8616
|
} finally {
|
|
8554
8617
|
const llmDuration = Date.now() - llmStartTime;
|
|
@@ -8561,6 +8624,16 @@ var BaseLlmFlow = class {
|
|
|
8561
8624
|
}
|
|
8562
8625
|
}
|
|
8563
8626
|
async _handleBeforeModelCallback(invocationContext, llmRequest, modelResponseEvent) {
|
|
8627
|
+
const callbackContext = new CallbackContext(invocationContext, {
|
|
8628
|
+
eventActions: modelResponseEvent.actions
|
|
8629
|
+
});
|
|
8630
|
+
const pluginResult = await invocationContext.pluginManager.runBeforeModelCallback({
|
|
8631
|
+
callbackContext,
|
|
8632
|
+
llmRequest
|
|
8633
|
+
});
|
|
8634
|
+
if (pluginResult !== null && pluginResult !== void 0) {
|
|
8635
|
+
return pluginResult;
|
|
8636
|
+
}
|
|
8564
8637
|
const agent = invocationContext.agent;
|
|
8565
8638
|
if (!("canonicalBeforeModelCallbacks" in agent)) {
|
|
8566
8639
|
return;
|
|
@@ -8569,9 +8642,6 @@ var BaseLlmFlow = class {
|
|
|
8569
8642
|
if (!beforeCallbacks) {
|
|
8570
8643
|
return;
|
|
8571
8644
|
}
|
|
8572
|
-
const callbackContext = new CallbackContext(invocationContext, {
|
|
8573
|
-
eventActions: modelResponseEvent.actions
|
|
8574
|
-
});
|
|
8575
8645
|
for (const callback of beforeCallbacks) {
|
|
8576
8646
|
let beforeModelCallbackContent = callback({
|
|
8577
8647
|
callbackContext,
|
|
@@ -8586,6 +8656,16 @@ var BaseLlmFlow = class {
|
|
|
8586
8656
|
}
|
|
8587
8657
|
}
|
|
8588
8658
|
async _handleAfterModelCallback(invocationContext, llmResponse, modelResponseEvent) {
|
|
8659
|
+
const callbackContext = new CallbackContext(invocationContext, {
|
|
8660
|
+
eventActions: modelResponseEvent.actions
|
|
8661
|
+
});
|
|
8662
|
+
const pluginResult = await invocationContext.pluginManager.runAfterModelCallback({
|
|
8663
|
+
callbackContext,
|
|
8664
|
+
llmResponse
|
|
8665
|
+
});
|
|
8666
|
+
if (pluginResult) {
|
|
8667
|
+
return pluginResult;
|
|
8668
|
+
}
|
|
8589
8669
|
const agent = invocationContext.agent;
|
|
8590
8670
|
if (!("canonicalAfterModelCallbacks" in agent)) {
|
|
8591
8671
|
return;
|
|
@@ -8594,9 +8674,6 @@ var BaseLlmFlow = class {
|
|
|
8594
8674
|
if (!afterCallbacks) {
|
|
8595
8675
|
return;
|
|
8596
8676
|
}
|
|
8597
|
-
const callbackContext = new CallbackContext(invocationContext, {
|
|
8598
|
-
eventActions: modelResponseEvent.actions
|
|
8599
|
-
});
|
|
8600
8677
|
for (const callback of afterCallbacks) {
|
|
8601
8678
|
let afterModelCallbackContent = callback({
|
|
8602
8679
|
callbackContext,
|