@google/adk 0.3.0 → 0.5.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/dist/cjs/a2a/a2a_event.js +290 -0
- package/dist/cjs/a2a/event_converter_utils.js +201 -0
- package/dist/cjs/a2a/executor_context.js +53 -0
- package/dist/cjs/a2a/metadata_converter_utils.js +125 -0
- package/dist/cjs/a2a/part_converter_utils.js +212 -0
- package/dist/cjs/agents/active_streaming_tool.js +1 -1
- package/dist/cjs/agents/base_agent.js +6 -6
- package/dist/cjs/agents/content_processor_utils.js +1 -1
- package/dist/cjs/{tools/tool_context.js → agents/context.js} +71 -16
- package/dist/cjs/agents/functions.js +4 -3
- package/dist/cjs/agents/instructions.js +1 -1
- package/dist/cjs/agents/invocation_context.js +1 -1
- package/dist/cjs/agents/live_request_queue.js +1 -1
- package/dist/cjs/agents/llm_agent.js +76 -711
- package/dist/cjs/agents/loop_agent.js +1 -1
- package/dist/cjs/agents/parallel_agent.js +1 -1
- package/dist/cjs/agents/processors/agent_transfer_llm_request_processor.js +132 -0
- package/dist/cjs/agents/{base_llm_processor.js → processors/base_llm_processor.js} +1 -1
- package/dist/cjs/agents/processors/basic_llm_request_processor.js +68 -0
- package/dist/cjs/agents/processors/code_execution_request_processor.js +389 -0
- package/dist/cjs/agents/processors/content_request_processor.js +66 -0
- package/dist/cjs/agents/processors/identity_llm_request_processor.js +54 -0
- package/dist/cjs/agents/processors/instructions_llm_request_processor.js +85 -0
- package/dist/cjs/agents/processors/request_confirmation_llm_request_processor.js +165 -0
- package/dist/cjs/agents/readonly_context.js +13 -1
- package/dist/cjs/agents/run_config.js +2 -1
- package/dist/cjs/agents/sequential_agent.js +1 -1
- package/dist/cjs/agents/transcription_entry.js +1 -1
- package/dist/cjs/artifacts/base_artifact_service.js +1 -1
- package/dist/cjs/artifacts/file_artifact_service.js +491 -0
- package/dist/cjs/artifacts/gcs_artifact_service.js +127 -48
- package/dist/cjs/artifacts/in_memory_artifact_service.js +54 -6
- package/dist/cjs/artifacts/registry.js +55 -0
- package/dist/cjs/auth/auth_credential.js +1 -1
- package/dist/cjs/auth/auth_handler.js +1 -1
- package/dist/cjs/auth/auth_schemes.js +1 -1
- package/dist/cjs/auth/auth_tool.js +1 -1
- package/dist/cjs/auth/credential_service/base_credential_service.js +1 -1
- package/dist/cjs/auth/credential_service/in_memory_credential_service.js +1 -1
- package/dist/cjs/auth/exchanger/base_credential_exchanger.js +1 -1
- package/dist/cjs/auth/exchanger/credential_exchanger_registry.js +1 -1
- package/dist/cjs/code_executors/base_code_executor.js +1 -1
- package/dist/cjs/code_executors/built_in_code_executor.js +1 -1
- package/dist/cjs/code_executors/code_execution_utils.js +1 -1
- package/dist/cjs/code_executors/code_executor_context.js +1 -1
- package/dist/cjs/common.js +25 -8
- package/dist/cjs/events/event.js +33 -4
- package/dist/cjs/events/event_actions.js +2 -2
- package/dist/cjs/events/structured_events.js +105 -0
- package/dist/cjs/examples/base_example_provider.js +1 -1
- package/dist/cjs/examples/example.js +1 -1
- package/dist/cjs/examples/example_util.js +1 -1
- package/dist/cjs/index.js +24 -17
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/index_web.js +1 -1
- package/dist/cjs/memory/base_memory_service.js +1 -1
- package/dist/cjs/memory/in_memory_memory_service.js +1 -1
- package/dist/cjs/memory/memory_entry.js +1 -1
- package/dist/cjs/models/apigee_llm.js +182 -0
- package/dist/cjs/models/base_llm.js +1 -1
- package/dist/cjs/models/base_llm_connection.js +1 -1
- package/dist/cjs/models/gemini_llm_connection.js +1 -1
- package/dist/cjs/models/google_llm.js +70 -51
- package/dist/cjs/models/llm_request.js +1 -1
- package/dist/cjs/models/llm_response.js +3 -1
- package/dist/cjs/models/registry.js +3 -1
- package/dist/cjs/plugins/base_plugin.js +2 -2
- package/dist/cjs/plugins/logging_plugin.js +1 -1
- package/dist/cjs/plugins/plugin_manager.js +1 -1
- package/dist/cjs/plugins/security_plugin.js +1 -1
- package/dist/cjs/runner/in_memory_runner.js +1 -1
- package/dist/cjs/runner/runner.js +33 -2
- package/dist/cjs/sessions/base_session_service.js +53 -3
- package/dist/cjs/sessions/database_session_service.js +367 -0
- package/dist/cjs/sessions/db/operations.js +126 -0
- package/dist/cjs/sessions/db/schema.js +204 -0
- package/dist/cjs/sessions/in_memory_session_service.js +24 -22
- package/dist/cjs/sessions/registry.js +49 -0
- package/dist/cjs/sessions/session.js +1 -1
- package/dist/cjs/sessions/state.js +1 -1
- package/dist/cjs/telemetry/google_cloud.js +1 -1
- package/dist/cjs/telemetry/setup.js +1 -1
- package/dist/cjs/telemetry/tracing.js +1 -1
- package/dist/cjs/tools/agent_tool.js +1 -1
- package/dist/cjs/tools/base_tool.js +4 -1
- package/dist/cjs/tools/base_toolset.js +14 -4
- package/dist/cjs/tools/exit_loop_tool.js +63 -0
- package/dist/cjs/tools/forwarding_artifact_service.js +17 -1
- package/dist/cjs/tools/function_tool.js +1 -1
- package/dist/cjs/tools/google_search_tool.js +1 -1
- package/dist/cjs/tools/long_running_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +1 -1
- package/dist/cjs/tools/mcp/mcp_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_toolset.js +10 -6
- package/dist/cjs/tools/tool_confirmation.js +1 -1
- package/dist/cjs/utils/client_labels.js +1 -1
- package/dist/cjs/utils/env_aware_utils.js +10 -1
- package/dist/cjs/utils/gemini_schema_util.js +1 -1
- package/dist/cjs/utils/logger.js +62 -55
- package/dist/cjs/utils/model_name.js +1 -1
- package/dist/cjs/utils/object_notation_utils.js +78 -0
- package/dist/cjs/utils/simple_zod_to_json.js +1 -1
- package/dist/cjs/utils/variant_utils.js +3 -9
- package/dist/cjs/version.js +2 -2
- package/dist/esm/a2a/a2a_event.js +243 -0
- package/dist/esm/a2a/event_converter_utils.js +187 -0
- package/dist/esm/a2a/executor_context.js +23 -0
- package/dist/esm/a2a/metadata_converter_utils.js +90 -0
- package/dist/esm/a2a/part_converter_utils.js +175 -0
- package/dist/esm/agents/base_agent.js +5 -5
- package/dist/esm/{tools/tool_context.js → agents/context.js} +66 -11
- package/dist/esm/agents/functions.js +3 -2
- package/dist/esm/agents/llm_agent.js +69 -720
- package/dist/esm/agents/processors/agent_transfer_llm_request_processor.js +101 -0
- package/dist/esm/agents/processors/basic_llm_request_processor.js +37 -0
- package/dist/esm/agents/processors/code_execution_request_processor.js +363 -0
- package/dist/esm/agents/processors/content_request_processor.js +38 -0
- package/dist/esm/agents/processors/identity_llm_request_processor.js +23 -0
- package/dist/esm/agents/processors/instructions_llm_request_processor.js +54 -0
- package/dist/esm/agents/processors/request_confirmation_llm_request_processor.js +140 -0
- package/dist/esm/agents/readonly_context.js +12 -0
- package/dist/esm/agents/run_config.js +1 -0
- package/dist/esm/artifacts/file_artifact_service.js +451 -0
- package/dist/esm/artifacts/gcs_artifact_service.js +126 -47
- package/dist/esm/artifacts/in_memory_artifact_service.js +51 -4
- package/dist/esm/artifacts/registry.js +28 -0
- package/dist/esm/common.js +20 -10
- package/dist/esm/events/event.js +29 -2
- package/dist/esm/events/event_actions.js +1 -1
- package/dist/esm/events/structured_events.js +74 -0
- package/dist/esm/index.js +24 -17
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/models/apigee_llm.js +152 -0
- package/dist/esm/models/google_llm.js +67 -49
- package/dist/esm/models/llm_response.js +2 -0
- package/dist/esm/models/registry.js +2 -0
- package/dist/esm/plugins/base_plugin.js +1 -1
- package/dist/esm/runner/runner.js +32 -1
- package/dist/esm/sessions/base_session_service.js +49 -1
- package/dist/esm/sessions/database_session_service.js +353 -0
- package/dist/esm/sessions/db/operations.js +111 -0
- package/dist/esm/sessions/db/schema.js +172 -0
- package/dist/esm/sessions/in_memory_session_service.js +23 -21
- package/dist/esm/sessions/registry.js +25 -0
- package/dist/esm/tools/base_tool.js +3 -0
- package/dist/esm/tools/base_toolset.js +11 -2
- package/dist/esm/tools/exit_loop_tool.js +32 -0
- package/dist/esm/tools/forwarding_artifact_service.js +16 -0
- package/dist/esm/tools/mcp/mcp_toolset.js +9 -5
- package/dist/esm/utils/env_aware_utils.js +8 -0
- package/dist/esm/utils/logger.js +51 -54
- package/dist/esm/utils/object_notation_utils.js +47 -0
- package/dist/esm/utils/variant_utils.js +1 -7
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_event.d.ts +122 -0
- package/dist/types/a2a/event_converter_utils.d.ts +20 -0
- package/dist/types/a2a/executor_context.d.ts +33 -0
- package/dist/types/a2a/metadata_converter_utils.d.ts +62 -0
- package/dist/types/a2a/part_converter_utils.d.ts +48 -0
- package/dist/types/agents/base_agent.d.ts +2 -2
- package/dist/types/{tools/tool_context.d.ts → agents/context.d.ts} +43 -8
- package/dist/types/agents/llm_agent.d.ts +19 -42
- package/dist/types/agents/processors/agent_transfer_llm_request_processor.d.ts +18 -0
- package/dist/types/agents/{base_llm_processor.d.ts → processors/base_llm_processor.d.ts} +4 -4
- package/dist/types/agents/processors/basic_llm_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/code_execution_request_processor.d.ts +34 -0
- package/dist/types/agents/processors/content_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/identity_llm_request_processor.d.ts +13 -0
- package/dist/types/agents/processors/instructions_llm_request_processor.d.ts +16 -0
- package/dist/types/agents/processors/request_confirmation_llm_request_processor.d.ts +13 -0
- package/dist/types/agents/readonly_context.d.ts +8 -0
- package/dist/types/agents/run_config.d.ts +6 -0
- package/dist/types/artifacts/base_artifact_service.d.ts +31 -0
- package/dist/types/artifacts/file_artifact_service.d.ts +43 -0
- package/dist/types/artifacts/gcs_artifact_service.d.ts +3 -1
- package/dist/types/artifacts/in_memory_artifact_service.d.ts +5 -2
- package/dist/types/artifacts/registry.d.ts +7 -0
- package/dist/types/auth/credential_service/base_credential_service.d.ts +3 -3
- package/dist/types/auth/credential_service/in_memory_credential_service.d.ts +3 -3
- package/dist/types/common.d.ts +15 -6
- package/dist/types/events/event.d.ts +15 -1
- package/dist/types/events/event_actions.d.ts +1 -1
- package/dist/types/events/structured_events.d.ts +106 -0
- package/dist/types/index.d.ts +5 -1
- package/dist/types/models/apigee_llm.d.ts +59 -0
- package/dist/types/models/google_llm.d.ts +5 -2
- package/dist/types/models/llm_response.d.ts +5 -1
- package/dist/types/plugins/base_plugin.d.ts +12 -13
- package/dist/types/plugins/logging_plugin.d.ts +9 -10
- package/dist/types/plugins/plugin_manager.d.ts +9 -10
- package/dist/types/plugins/security_plugin.d.ts +2 -2
- package/dist/types/runner/runner.d.ts +15 -0
- package/dist/types/sessions/base_session_service.d.ts +20 -0
- package/dist/types/sessions/database_session_service.d.ts +32 -0
- package/dist/types/sessions/db/operations.d.ts +29 -0
- package/dist/types/sessions/db/schema.d.ts +45 -0
- package/dist/types/sessions/in_memory_session_service.d.ts +4 -1
- package/dist/types/sessions/registry.d.ts +7 -0
- package/dist/types/tools/base_tool.d.ts +3 -3
- package/dist/types/tools/base_toolset.d.ts +12 -3
- package/dist/types/tools/exit_loop_tool.d.ts +24 -0
- package/dist/types/tools/forwarding_artifact_service.d.ts +5 -3
- package/dist/types/tools/function_tool.d.ts +2 -2
- package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -1
- package/dist/types/utils/env_aware_utils.d.ts +7 -0
- package/dist/types/utils/logger.d.ts +5 -9
- package/dist/types/utils/object_notation_utils.d.ts +21 -0
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/a2a_event.js +243 -0
- package/dist/web/a2a/event_converter_utils.js +201 -0
- package/dist/web/a2a/executor_context.js +23 -0
- package/dist/web/a2a/metadata_converter_utils.js +107 -0
- package/dist/web/a2a/part_converter_utils.js +175 -0
- package/dist/web/agents/base_agent.js +5 -5
- package/dist/web/{tools/tool_context.js → agents/context.js} +66 -11
- package/dist/web/agents/functions.js +3 -2
- package/dist/web/agents/llm_agent.js +90 -717
- package/dist/web/agents/processors/agent_transfer_llm_request_processor.js +100 -0
- package/dist/web/agents/processors/basic_llm_request_processor.js +71 -0
- package/dist/web/agents/processors/code_execution_request_processor.js +365 -0
- package/dist/web/agents/processors/content_request_processor.js +56 -0
- package/dist/web/agents/processors/identity_llm_request_processor.js +41 -0
- package/dist/web/agents/processors/instructions_llm_request_processor.js +72 -0
- package/dist/web/agents/processors/request_confirmation_llm_request_processor.js +158 -0
- package/dist/web/agents/readonly_context.js +12 -0
- package/dist/web/agents/run_config.js +2 -1
- package/dist/web/artifacts/file_artifact_service.js +506 -0
- package/dist/web/artifacts/gcs_artifact_service.js +123 -46
- package/dist/web/artifacts/in_memory_artifact_service.js +51 -4
- package/dist/web/artifacts/registry.js +28 -0
- package/dist/web/common.js +20 -10
- package/dist/web/events/event.js +29 -2
- package/dist/web/events/event_actions.js +1 -1
- package/dist/web/events/structured_events.js +74 -0
- package/dist/web/index.js +7 -2
- package/dist/web/index.js.map +4 -4
- package/dist/web/models/apigee_llm.js +219 -0
- package/dist/web/models/google_llm.js +67 -46
- package/dist/web/models/llm_response.js +2 -0
- package/dist/web/models/registry.js +2 -0
- package/dist/web/plugins/base_plugin.js +1 -1
- package/dist/web/runner/runner.js +34 -1
- package/dist/web/sessions/base_session_service.js +49 -1
- package/dist/web/sessions/database_session_service.js +371 -0
- package/dist/web/sessions/db/operations.js +111 -0
- package/dist/web/sessions/db/schema.js +172 -0
- package/dist/web/sessions/in_memory_session_service.js +23 -21
- package/dist/web/sessions/registry.js +25 -0
- package/dist/web/tools/base_tool.js +3 -0
- package/dist/web/tools/base_toolset.js +11 -2
- package/dist/web/tools/exit_loop_tool.js +32 -0
- package/dist/web/tools/forwarding_artifact_service.js +16 -0
- package/dist/web/tools/mcp/mcp_toolset.js +27 -5
- package/dist/web/utils/env_aware_utils.js +8 -0
- package/dist/web/utils/logger.js +51 -54
- package/dist/web/utils/object_notation_utils.js +47 -0
- package/dist/web/utils/variant_utils.js +1 -7
- package/dist/web/version.js +1 -1
- package/package.json +13 -3
- package/dist/cjs/agents/callback_context.js +0 -101
- package/dist/esm/agents/callback_context.js +0 -71
- package/dist/types/agents/callback_context.d.ts +0 -42
- package/dist/web/agents/callback_context.js +0 -71
- /package/dist/esm/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
- /package/dist/web/agents/{base_llm_processor.js → processors/base_llm_processor.js} +0 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
2
|
+
var __await = function(promise, isYieldStar) {
|
|
3
|
+
this[0] = promise;
|
|
4
|
+
this[1] = isYieldStar;
|
|
5
|
+
};
|
|
6
|
+
var __asyncGenerator = (__this, __arguments, generator) => {
|
|
7
|
+
var resume = (k, v, yes, no) => {
|
|
8
|
+
try {
|
|
9
|
+
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
10
|
+
Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
|
|
11
|
+
} catch (e) {
|
|
12
|
+
no(e);
|
|
13
|
+
}
|
|
14
|
+
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
15
|
+
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @license
|
|
19
|
+
* Copyright 2025 Google LLC
|
|
20
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
21
|
+
*/
|
|
22
|
+
import { appendInstructions } from "../../models/llm_request.js";
|
|
23
|
+
import { injectSessionState } from "../instructions.js";
|
|
24
|
+
import { isLlmAgent } from "../llm_agent.js";
|
|
25
|
+
import { ReadonlyContext } from "../readonly_context.js";
|
|
26
|
+
import { BaseLlmRequestProcessor } from "./base_llm_processor.js";
|
|
27
|
+
class InstructionsLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
28
|
+
/**
|
|
29
|
+
* Handles instructions and global instructions for LLM flow.
|
|
30
|
+
*/
|
|
31
|
+
// eslint-disable-next-line require-yield
|
|
32
|
+
runAsync(invocationContext, llmRequest) {
|
|
33
|
+
return __asyncGenerator(this, null, function* () {
|
|
34
|
+
const agent = invocationContext.agent;
|
|
35
|
+
if (!isLlmAgent(agent) || !isLlmAgent(agent.rootAgent)) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const rootAgent = agent.rootAgent;
|
|
39
|
+
if (isLlmAgent(rootAgent) && rootAgent.globalInstruction) {
|
|
40
|
+
const { instruction, requireStateInjection } = yield new __await(rootAgent.canonicalGlobalInstruction(
|
|
41
|
+
new ReadonlyContext(invocationContext)
|
|
42
|
+
));
|
|
43
|
+
let instructionWithState = instruction;
|
|
44
|
+
if (requireStateInjection) {
|
|
45
|
+
instructionWithState = yield new __await(injectSessionState(
|
|
46
|
+
instruction,
|
|
47
|
+
new ReadonlyContext(invocationContext)
|
|
48
|
+
));
|
|
49
|
+
}
|
|
50
|
+
appendInstructions(llmRequest, [instructionWithState]);
|
|
51
|
+
}
|
|
52
|
+
if (agent.instruction) {
|
|
53
|
+
const { instruction, requireStateInjection } = yield new __await(agent.canonicalInstruction(
|
|
54
|
+
new ReadonlyContext(invocationContext)
|
|
55
|
+
));
|
|
56
|
+
let instructionWithState = instruction;
|
|
57
|
+
if (requireStateInjection) {
|
|
58
|
+
instructionWithState = yield new __await(injectSessionState(
|
|
59
|
+
instruction,
|
|
60
|
+
new ReadonlyContext(invocationContext)
|
|
61
|
+
));
|
|
62
|
+
}
|
|
63
|
+
appendInstructions(llmRequest, [instructionWithState]);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const INSTRUCTIONS_LLM_REQUEST_PROCESSOR = new InstructionsLlmRequestProcessor();
|
|
69
|
+
export {
|
|
70
|
+
INSTRUCTIONS_LLM_REQUEST_PROCESSOR,
|
|
71
|
+
InstructionsLlmRequestProcessor
|
|
72
|
+
};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
2
|
+
var __await = function(promise, isYieldStar) {
|
|
3
|
+
this[0] = promise;
|
|
4
|
+
this[1] = isYieldStar;
|
|
5
|
+
};
|
|
6
|
+
var __asyncGenerator = (__this, __arguments, generator) => {
|
|
7
|
+
var resume = (k, v, yes, no) => {
|
|
8
|
+
try {
|
|
9
|
+
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
10
|
+
Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
|
|
11
|
+
} catch (e) {
|
|
12
|
+
no(e);
|
|
13
|
+
}
|
|
14
|
+
}, method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no)), it = {};
|
|
15
|
+
return generator = generator.apply(__this, __arguments), it[__knownSymbol("asyncIterator")] = () => it, method("next"), method("throw"), method("return"), it;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* @license
|
|
19
|
+
* Copyright 2025 Google LLC
|
|
20
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
21
|
+
*/
|
|
22
|
+
import {
|
|
23
|
+
getFunctionCalls,
|
|
24
|
+
getFunctionResponses
|
|
25
|
+
} from "../../events/event.js";
|
|
26
|
+
import { ToolConfirmation } from "../../tools/tool_confirmation.js";
|
|
27
|
+
import {
|
|
28
|
+
REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
|
|
29
|
+
handleFunctionCallList
|
|
30
|
+
} from "../functions.js";
|
|
31
|
+
import { isLlmAgent } from "../llm_agent.js";
|
|
32
|
+
import { ReadonlyContext } from "../readonly_context.js";
|
|
33
|
+
import { BaseLlmRequestProcessor } from "./base_llm_processor.js";
|
|
34
|
+
class RequestConfirmationLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
35
|
+
/** Handles tool confirmation information to build the LLM request. */
|
|
36
|
+
runAsync(invocationContext) {
|
|
37
|
+
return __asyncGenerator(this, null, function* () {
|
|
38
|
+
const agent = invocationContext.agent;
|
|
39
|
+
if (!isLlmAgent(agent)) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const events = invocationContext.session.events;
|
|
43
|
+
if (!events || events.length === 0) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const requestConfirmationFunctionResponses = {};
|
|
47
|
+
let confirmationEventIndex = -1;
|
|
48
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
49
|
+
const event = events[i];
|
|
50
|
+
if (event.author !== "user") {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const responses = getFunctionResponses(event);
|
|
54
|
+
if (!responses) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
let foundConfirmation = false;
|
|
58
|
+
for (const functionResponse of responses) {
|
|
59
|
+
if (functionResponse.name !== REQUEST_CONFIRMATION_FUNCTION_CALL_NAME) {
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
foundConfirmation = true;
|
|
63
|
+
let toolConfirmation = null;
|
|
64
|
+
if (functionResponse.response && Object.keys(functionResponse.response).length === 1 && "response" in functionResponse.response) {
|
|
65
|
+
toolConfirmation = JSON.parse(
|
|
66
|
+
functionResponse.response["response"]
|
|
67
|
+
);
|
|
68
|
+
} else if (functionResponse.response) {
|
|
69
|
+
toolConfirmation = new ToolConfirmation({
|
|
70
|
+
hint: functionResponse.response["hint"],
|
|
71
|
+
payload: functionResponse.response["payload"],
|
|
72
|
+
confirmed: functionResponse.response["confirmed"]
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
if (functionResponse.id && toolConfirmation) {
|
|
76
|
+
requestConfirmationFunctionResponses[functionResponse.id] = toolConfirmation;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (foundConfirmation) {
|
|
80
|
+
confirmationEventIndex = i;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (Object.keys(requestConfirmationFunctionResponses).length === 0) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
for (let i = confirmationEventIndex - 1; i >= 0; i--) {
|
|
88
|
+
const event = events[i];
|
|
89
|
+
const functionCalls = getFunctionCalls(event);
|
|
90
|
+
if (!functionCalls) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
const toolsToResumeWithConfirmation = {};
|
|
94
|
+
const toolsToResumeWithArgs = {};
|
|
95
|
+
for (const functionCall of functionCalls) {
|
|
96
|
+
if (!functionCall.id || !(functionCall.id in requestConfirmationFunctionResponses)) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const args = functionCall.args;
|
|
100
|
+
if (!args || !("originalFunctionCall" in args)) {
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const originalFunctionCall = args["originalFunctionCall"];
|
|
104
|
+
if (originalFunctionCall.id) {
|
|
105
|
+
toolsToResumeWithConfirmation[originalFunctionCall.id] = requestConfirmationFunctionResponses[functionCall.id];
|
|
106
|
+
toolsToResumeWithArgs[originalFunctionCall.id] = originalFunctionCall;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (Object.keys(toolsToResumeWithConfirmation).length === 0) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
for (let j = events.length - 1; j > confirmationEventIndex; j--) {
|
|
113
|
+
const eventToCheck = events[j];
|
|
114
|
+
const functionResponses = getFunctionResponses(eventToCheck);
|
|
115
|
+
if (!functionResponses) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
for (const fr of functionResponses) {
|
|
119
|
+
if (fr.id && fr.id in toolsToResumeWithConfirmation) {
|
|
120
|
+
delete toolsToResumeWithConfirmation[fr.id];
|
|
121
|
+
delete toolsToResumeWithArgs[fr.id];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (Object.keys(toolsToResumeWithConfirmation).length === 0) {
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (Object.keys(toolsToResumeWithConfirmation).length === 0) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
const toolsList = yield new __await(agent.canonicalTools(
|
|
132
|
+
new ReadonlyContext(invocationContext)
|
|
133
|
+
));
|
|
134
|
+
const toolsDict = Object.fromEntries(
|
|
135
|
+
toolsList.map((tool) => [tool.name, tool])
|
|
136
|
+
);
|
|
137
|
+
const functionResponseEvent = yield new __await(handleFunctionCallList({
|
|
138
|
+
invocationContext,
|
|
139
|
+
functionCalls: Object.values(toolsToResumeWithArgs),
|
|
140
|
+
toolsDict,
|
|
141
|
+
beforeToolCallbacks: agent.canonicalBeforeToolCallbacks,
|
|
142
|
+
afterToolCallbacks: agent.canonicalAfterToolCallbacks,
|
|
143
|
+
filters: new Set(Object.keys(toolsToResumeWithConfirmation)),
|
|
144
|
+
toolConfirmationDict: toolsToResumeWithConfirmation
|
|
145
|
+
}));
|
|
146
|
+
if (functionResponseEvent) {
|
|
147
|
+
yield functionResponseEvent;
|
|
148
|
+
}
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
const REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR = new RequestConfirmationLlmRequestProcessor();
|
|
155
|
+
export {
|
|
156
|
+
REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR,
|
|
157
|
+
RequestConfirmationLlmRequestProcessor
|
|
158
|
+
};
|
|
@@ -20,6 +20,18 @@ class ReadonlyContext {
|
|
|
20
20
|
get invocationId() {
|
|
21
21
|
return this.invocationContext.invocationId;
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* The user ID of the current session.
|
|
25
|
+
*/
|
|
26
|
+
get userId() {
|
|
27
|
+
return this.invocationContext.userId;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The ID of the current session.
|
|
31
|
+
*/
|
|
32
|
+
get sessionId() {
|
|
33
|
+
return this.invocationContext.session.id;
|
|
34
|
+
}
|
|
23
35
|
/**
|
|
24
36
|
* The current agent name.
|
|
25
37
|
*/
|
|
@@ -32,7 +32,8 @@ function createRunConfig(params = {}) {
|
|
|
32
32
|
supportCfc: false,
|
|
33
33
|
enableAffectiveDialog: false,
|
|
34
34
|
streamingMode: "none" /* NONE */,
|
|
35
|
-
maxLlmCalls: validateMaxLlmCalls(params.maxLlmCalls || 500)
|
|
35
|
+
maxLlmCalls: validateMaxLlmCalls(params.maxLlmCalls || 500),
|
|
36
|
+
pauseOnToolCalls: false
|
|
36
37
|
}, params);
|
|
37
38
|
}
|
|
38
39
|
function validateMaxLlmCalls(value) {
|