@google/adk 0.2.5 → 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/dist/cjs/a2a/part_converter_utils.js +210 -0
- package/dist/cjs/agents/active_streaming_tool.js +1 -1
- package/dist/cjs/agents/base_agent.js +46 -24
- package/dist/cjs/agents/base_llm_processor.js +1 -1
- package/dist/cjs/agents/callback_context.js +5 -2
- package/dist/cjs/agents/content_processor_utils.js +16 -8
- package/dist/cjs/agents/functions.js +81 -30
- 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 +106 -62
- package/dist/cjs/agents/loop_agent.js +3 -2
- package/dist/cjs/agents/parallel_agent.js +4 -5
- 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 +145 -58
- package/dist/cjs/artifacts/in_memory_artifact_service.js +72 -10
- package/dist/cjs/artifacts/registry.js +55 -0
- package/dist/cjs/auth/auth_credential.js +1 -1
- package/dist/cjs/auth/auth_handler.js +4 -2
- 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 +4 -2
- package/dist/cjs/code_executors/built_in_code_executor.js +8 -4
- package/dist/cjs/code_executors/code_execution_utils.js +1 -1
- package/dist/cjs/code_executors/code_executor_context.js +6 -6
- package/dist/cjs/common.js +18 -1
- package/dist/cjs/events/event.js +34 -7
- 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 +54 -83
- 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 +4 -2
- 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 +9 -5
- package/dist/cjs/models/base_llm_connection.js +1 -1
- package/dist/cjs/models/gemini_llm_connection.js +2 -1
- package/dist/cjs/models/google_llm.js +73 -54
- package/dist/cjs/models/llm_request.js +1 -1
- package/dist/cjs/models/llm_response.js +1 -1
- package/dist/cjs/models/registry.js +3 -1
- package/dist/cjs/plugins/base_plugin.js +13 -1
- package/dist/cjs/plugins/logging_plugin.js +51 -14
- package/dist/cjs/plugins/plugin_manager.js +57 -25
- package/dist/cjs/plugins/security_plugin.js +2 -2
- package/dist/cjs/runner/in_memory_runner.js +1 -1
- package/dist/cjs/runner/runner.js +142 -96
- package/dist/cjs/sessions/base_session_service.js +53 -3
- package/dist/cjs/sessions/database_session_service.js +364 -0
- package/dist/cjs/sessions/db/operations.js +114 -0
- package/dist/cjs/sessions/db/schema.js +204 -0
- package/dist/cjs/sessions/in_memory_session_service.js +60 -34
- 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 +8 -10
- package/dist/cjs/telemetry/setup.js +16 -8
- package/dist/cjs/telemetry/tracing.js +38 -16
- package/dist/cjs/tools/agent_tool.js +9 -5
- package/dist/cjs/tools/base_tool.js +5 -3
- package/dist/cjs/tools/base_toolset.js +1 -1
- package/dist/cjs/tools/forwarding_artifact_service.js +18 -2
- package/dist/cjs/tools/function_tool.js +2 -3
- package/dist/cjs/tools/google_search_tool.js +2 -3
- package/dist/cjs/tools/long_running_tool.js +1 -1
- package/dist/cjs/tools/mcp/mcp_session_manager.js +17 -11
- package/dist/cjs/tools/mcp/mcp_tool.js +2 -4
- package/dist/cjs/tools/mcp/mcp_toolset.js +2 -2
- package/dist/cjs/tools/tool_confirmation.js +1 -1
- package/dist/cjs/tools/tool_context.js +1 -1
- package/dist/cjs/utils/client_labels.js +1 -1
- package/dist/cjs/utils/env_aware_utils.js +11 -2
- package/dist/cjs/utils/gemini_schema_util.js +10 -5
- package/dist/cjs/utils/logger.js +48 -4
- 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 +101 -142
- package/dist/cjs/utils/variant_utils.js +3 -9
- package/dist/cjs/version.js +2 -2
- package/dist/esm/a2a/part_converter_utils.js +171 -0
- package/dist/esm/agents/base_agent.js +50 -24
- package/dist/esm/agents/callback_context.js +4 -1
- package/dist/esm/agents/content_processor_utils.js +25 -9
- package/dist/esm/agents/functions.js +84 -29
- package/dist/esm/agents/llm_agent.js +110 -62
- package/dist/esm/agents/loop_agent.js +2 -1
- package/dist/esm/agents/parallel_agent.js +3 -4
- 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 +144 -57
- package/dist/esm/artifacts/in_memory_artifact_service.js +69 -8
- package/dist/esm/artifacts/registry.js +28 -0
- package/dist/esm/auth/auth_handler.js +3 -1
- package/dist/esm/code_executors/base_code_executor.js +3 -1
- package/dist/esm/code_executors/built_in_code_executor.js +7 -3
- package/dist/esm/code_executors/code_executor_context.js +5 -5
- package/dist/esm/common.js +12 -2
- package/dist/esm/events/event.js +30 -5
- package/dist/esm/events/event_actions.js +1 -1
- package/dist/esm/events/structured_events.js +74 -0
- package/dist/esm/index.js +18 -88
- package/dist/esm/memory/in_memory_memory_service.js +3 -1
- package/dist/esm/models/apigee_llm.js +152 -0
- package/dist/esm/models/base_llm.js +8 -4
- package/dist/esm/models/gemini_llm_connection.js +1 -0
- package/dist/esm/models/google_llm.js +75 -53
- package/dist/esm/models/registry.js +2 -0
- package/dist/esm/plugins/base_plugin.js +12 -0
- package/dist/esm/plugins/logging_plugin.js +55 -14
- package/dist/esm/plugins/plugin_manager.js +56 -24
- package/dist/esm/plugins/security_plugin.js +1 -1
- package/dist/esm/runner/runner.js +145 -96
- package/dist/esm/sessions/base_session_service.js +49 -1
- package/dist/esm/sessions/database_session_service.js +350 -0
- package/dist/esm/sessions/db/operations.js +87 -0
- package/dist/esm/sessions/db/schema.js +172 -0
- package/dist/esm/sessions/in_memory_session_service.js +61 -33
- package/dist/esm/sessions/registry.js +25 -0
- package/dist/esm/telemetry/google_cloud.js +7 -9
- package/dist/esm/telemetry/setup.js +23 -9
- package/dist/esm/telemetry/tracing.js +37 -15
- package/dist/esm/tools/agent_tool.js +8 -4
- package/dist/esm/tools/base_tool.js +4 -2
- package/dist/esm/tools/forwarding_artifact_service.js +17 -1
- package/dist/esm/tools/function_tool.js +1 -2
- package/dist/esm/tools/google_search_tool.js +2 -5
- package/dist/esm/tools/long_running_tool.js +3 -1
- package/dist/esm/tools/mcp/mcp_session_manager.js +22 -12
- package/dist/esm/tools/mcp/mcp_tool.js +1 -3
- package/dist/esm/tools/mcp/mcp_toolset.js +1 -1
- package/dist/esm/utils/env_aware_utils.js +9 -1
- package/dist/esm/utils/gemini_schema_util.js +9 -4
- package/dist/esm/utils/logger.js +43 -2
- package/dist/esm/utils/object_notation_utils.js +47 -0
- package/dist/esm/utils/simple_zod_to_json.js +102 -141
- package/dist/esm/utils/variant_utils.js +1 -7
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/part_converter_utils.d.ts +47 -0
- package/dist/types/agents/base_agent.d.ts +2 -1
- package/dist/types/agents/callback_context.d.ts +1 -1
- package/dist/types/agents/llm_agent.d.ts +12 -12
- package/dist/types/agents/loop_agent.d.ts +1 -1
- package/dist/types/agents/parallel_agent.d.ts +1 -1
- 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 +8 -5
- package/dist/types/artifacts/registry.d.ts +7 -0
- package/dist/types/code_executors/built_in_code_executor.d.ts +1 -1
- package/dist/types/code_executors/code_executor_context.d.ts +2 -4
- package/dist/types/common.d.ts +13 -3
- 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 +7 -3
- package/dist/types/models/apigee_llm.d.ts +59 -0
- package/dist/types/models/base_llm_connection.d.ts +1 -1
- package/dist/types/models/google_llm.d.ts +5 -2
- package/dist/types/models/llm_response.d.ts +1 -1
- package/dist/types/plugins/logging_plugin.d.ts +12 -12
- package/dist/types/plugins/plugin_manager.d.ts +12 -12
- package/dist/types/plugins/security_plugin.d.ts +1 -1
- package/dist/types/runner/runner.d.ts +16 -1
- package/dist/types/sessions/base_session_service.d.ts +20 -0
- package/dist/types/sessions/database_session_service.d.ts +31 -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 +9 -6
- package/dist/types/sessions/registry.d.ts +7 -0
- package/dist/types/telemetry/setup.d.ts +1 -1
- package/dist/types/telemetry/tracing.d.ts +7 -6
- package/dist/types/tools/agent_tool.d.ts +1 -1
- package/dist/types/tools/base_tool.d.ts +1 -1
- package/dist/types/tools/base_toolset.d.ts +2 -1
- package/dist/types/tools/forwarding_artifact_service.d.ts +4 -2
- package/dist/types/tools/function_tool.d.ts +4 -3
- package/dist/types/tools/google_search_tool.d.ts +3 -3
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +10 -3
- package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -2
- package/dist/types/utils/env_aware_utils.d.ts +7 -0
- package/dist/types/utils/gemini_schema_util.d.ts +4 -12
- package/dist/types/utils/logger.d.ts +11 -10
- package/dist/types/utils/object_notation_utils.d.ts +21 -0
- package/dist/types/utils/simple_zod_to_json.d.ts +5 -4
- package/dist/types/version.d.ts +1 -1
- package/dist/web/a2a/part_converter_utils.js +171 -0
- package/dist/web/agents/base_agent.js +96 -35
- package/dist/web/agents/callback_context.js +4 -1
- package/dist/web/agents/content_processor_utils.js +25 -9
- package/dist/web/agents/functions.js +84 -29
- package/dist/web/agents/llm_agent.js +166 -83
- package/dist/web/agents/loop_agent.js +2 -1
- package/dist/web/agents/parallel_agent.js +3 -4
- 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 +139 -54
- package/dist/web/artifacts/in_memory_artifact_service.js +69 -8
- package/dist/web/artifacts/registry.js +28 -0
- package/dist/web/auth/auth_handler.js +3 -1
- package/dist/web/code_executors/base_code_executor.js +3 -1
- package/dist/web/code_executors/built_in_code_executor.js +7 -3
- package/dist/web/code_executors/code_executor_context.js +5 -5
- package/dist/web/common.js +12 -2
- package/dist/web/events/event.js +30 -5
- package/dist/web/events/event_actions.js +1 -1
- package/dist/web/events/structured_events.js +74 -0
- package/dist/web/index.js +18 -8
- package/dist/web/memory/in_memory_memory_service.js +3 -1
- package/dist/web/models/apigee_llm.js +219 -0
- package/dist/web/models/base_llm.js +8 -4
- package/dist/web/models/gemini_llm_connection.js +1 -0
- package/dist/web/models/google_llm.js +75 -50
- package/dist/web/models/registry.js +2 -0
- package/dist/web/plugins/base_plugin.js +12 -0
- package/dist/web/plugins/logging_plugin.js +55 -14
- package/dist/web/plugins/plugin_manager.js +56 -24
- package/dist/web/plugins/security_plugin.js +1 -1
- package/dist/web/runner/runner.js +192 -108
- package/dist/web/sessions/base_session_service.js +49 -1
- package/dist/web/sessions/database_session_service.js +368 -0
- package/dist/web/sessions/db/operations.js +87 -0
- package/dist/web/sessions/db/schema.js +172 -0
- package/dist/web/sessions/in_memory_session_service.js +61 -33
- package/dist/web/sessions/registry.js +25 -0
- package/dist/web/telemetry/google_cloud.js +7 -9
- package/dist/web/telemetry/setup.js +23 -9
- package/dist/web/telemetry/tracing.js +37 -15
- package/dist/web/tools/agent_tool.js +8 -4
- package/dist/web/tools/base_tool.js +4 -2
- package/dist/web/tools/forwarding_artifact_service.js +17 -1
- package/dist/web/tools/function_tool.js +1 -2
- package/dist/web/tools/google_search_tool.js +2 -5
- package/dist/web/tools/long_running_tool.js +3 -1
- package/dist/web/tools/mcp/mcp_session_manager.js +22 -12
- package/dist/web/tools/mcp/mcp_tool.js +1 -3
- package/dist/web/tools/mcp/mcp_toolset.js +1 -1
- package/dist/web/utils/env_aware_utils.js +9 -1
- package/dist/web/utils/gemini_schema_util.js +9 -4
- package/dist/web/utils/logger.js +43 -2
- package/dist/web/utils/object_notation_utils.js +47 -0
- package/dist/web/utils/simple_zod_to_json.js +102 -155
- package/dist/web/utils/variant_utils.js +1 -7
- package/dist/web/version.js +1 -1
- package/package.json +16 -5
- package/dist/cjs/index.js.map +0 -7
- package/dist/esm/index.js.map +0 -7
- package/dist/web/index.js.map +0 -7
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
var _a, _b;
|
|
7
|
+
import { context, trace } from "@opentelemetry/api";
|
|
7
8
|
import { cloneDeep } from "lodash-es";
|
|
8
9
|
import { z } from "zod";
|
|
9
10
|
import {
|
|
@@ -32,12 +33,18 @@ import {
|
|
|
32
33
|
} from "../models/llm_request.js";
|
|
33
34
|
import { LLMRegistry } from "../models/registry.js";
|
|
34
35
|
import { State } from "../sessions/state.js";
|
|
35
|
-
import {
|
|
36
|
+
import { isBaseTool } from "../tools/base_tool.js";
|
|
36
37
|
import { FunctionTool } from "../tools/function_tool.js";
|
|
37
38
|
import { ToolConfirmation } from "../tools/tool_confirmation.js";
|
|
38
39
|
import { ToolContext } from "../tools/tool_context.js";
|
|
39
40
|
import { base64Decode } from "../utils/env_aware_utils.js";
|
|
40
41
|
import { logger } from "../utils/logger.js";
|
|
42
|
+
import {
|
|
43
|
+
runAsyncGeneratorWithOtelContext,
|
|
44
|
+
traceCallLlm,
|
|
45
|
+
tracer
|
|
46
|
+
} from "../telemetry/tracing.js";
|
|
47
|
+
import { isZodObject, zodObjectToSchema } from "../utils/simple_zod_to_json.js";
|
|
41
48
|
import { BaseAgent } from "./base_agent.js";
|
|
42
49
|
import {
|
|
43
50
|
BaseLlmRequestProcessor
|
|
@@ -60,13 +67,14 @@ import { injectSessionState } from "./instructions.js";
|
|
|
60
67
|
import { ReadonlyContext } from "./readonly_context.js";
|
|
61
68
|
import { StreamingMode } from "./run_config.js";
|
|
62
69
|
const ADK_AGENT_NAME_LABEL_KEY = "adk_agent_name";
|
|
63
|
-
async function convertToolUnionToTools(toolUnion,
|
|
64
|
-
if (toolUnion
|
|
70
|
+
async function convertToolUnionToTools(toolUnion, context2) {
|
|
71
|
+
if (isBaseTool(toolUnion)) {
|
|
65
72
|
return [toolUnion];
|
|
66
73
|
}
|
|
67
|
-
return await toolUnion.getTools(
|
|
74
|
+
return await toolUnion.getTools(context2);
|
|
68
75
|
}
|
|
69
76
|
class BasicLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
77
|
+
// eslint-disable-next-line require-yield
|
|
70
78
|
async *runAsync(invocationContext, llmRequest) {
|
|
71
79
|
var _a2;
|
|
72
80
|
const agent = invocationContext.agent;
|
|
@@ -91,6 +99,7 @@ class BasicLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
|
91
99
|
}
|
|
92
100
|
const BASIC_LLM_REQUEST_PROCESSOR = new BasicLlmRequestProcessor();
|
|
93
101
|
class IdentityLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
102
|
+
// eslint-disable-next-line require-yield
|
|
94
103
|
async *runAsync(invocationContext, llmRequest) {
|
|
95
104
|
const agent = invocationContext.agent;
|
|
96
105
|
const si = [`You are an agent. Your internal name is "${agent.name}".`];
|
|
@@ -105,9 +114,10 @@ class InstructionsLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
|
105
114
|
/**
|
|
106
115
|
* Handles instructions and global instructions for LLM flow.
|
|
107
116
|
*/
|
|
117
|
+
// eslint-disable-next-line require-yield
|
|
108
118
|
async *runAsync(invocationContext, llmRequest) {
|
|
109
119
|
const agent = invocationContext.agent;
|
|
110
|
-
if (!(agent
|
|
120
|
+
if (!isLlmAgent(agent) || !isLlmAgent(agent.rootAgent)) {
|
|
111
121
|
return;
|
|
112
122
|
}
|
|
113
123
|
const rootAgent = agent.rootAgent;
|
|
@@ -141,6 +151,7 @@ class InstructionsLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
|
141
151
|
}
|
|
142
152
|
const INSTRUCTIONS_LLM_REQUEST_PROCESSOR = new InstructionsLlmRequestProcessor();
|
|
143
153
|
class ContentRequestProcessor {
|
|
154
|
+
// eslint-disable-next-line require-yield
|
|
144
155
|
async *runAsync(invocationContext, llmRequest) {
|
|
145
156
|
const agent = invocationContext.agent;
|
|
146
157
|
if (!agent || !isLlmAgent(agent)) {
|
|
@@ -182,8 +193,9 @@ class AgentTransferLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
|
182
193
|
}
|
|
183
194
|
});
|
|
184
195
|
}
|
|
196
|
+
// eslint-disable-next-line require-yield
|
|
185
197
|
async *runAsync(invocationContext, llmRequest) {
|
|
186
|
-
if (!(invocationContext.agent
|
|
198
|
+
if (!isLlmAgent(invocationContext.agent)) {
|
|
187
199
|
return;
|
|
188
200
|
}
|
|
189
201
|
const transferTargets = this.getTransferTargets(invocationContext.agent);
|
|
@@ -250,7 +262,7 @@ to your parent agent.
|
|
|
250
262
|
const AGENT_TRANSFER_LLM_REQUEST_PROCESSOR = new AgentTransferLlmRequestProcessor();
|
|
251
263
|
class RequestConfirmationLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
252
264
|
/** Handles tool confirmation information to build the LLM request. */
|
|
253
|
-
async *runAsync(invocationContext
|
|
265
|
+
async *runAsync(invocationContext) {
|
|
254
266
|
const agent = invocationContext.agent;
|
|
255
267
|
if (!isLlmAgent(agent)) {
|
|
256
268
|
return;
|
|
@@ -369,7 +381,7 @@ class RequestConfirmationLlmRequestProcessor extends BaseLlmRequestProcessor {
|
|
|
369
381
|
const REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR = new RequestConfirmationLlmRequestProcessor();
|
|
370
382
|
class CodeExecutionRequestProcessor extends BaseLlmRequestProcessor {
|
|
371
383
|
async *runAsync(invocationContext, llmRequest) {
|
|
372
|
-
if (!(invocationContext.agent
|
|
384
|
+
if (!isLlmAgent(invocationContext.agent)) {
|
|
373
385
|
return;
|
|
374
386
|
}
|
|
375
387
|
if (!invocationContext.agent.codeExecutor) {
|
|
@@ -383,7 +395,7 @@ class CodeExecutionRequestProcessor extends BaseLlmRequestProcessor {
|
|
|
383
395
|
}
|
|
384
396
|
for (const content of llmRequest.contents) {
|
|
385
397
|
const delimeters = invocationContext.agent.codeExecutor.codeBlockDelimiters.length ? invocationContext.agent.codeExecutor.codeBlockDelimiters[0] : ["", ""];
|
|
386
|
-
|
|
398
|
+
convertCodeExecutionParts(
|
|
387
399
|
content,
|
|
388
400
|
delimeters,
|
|
389
401
|
invocationContext.agent.codeExecutor.executionResultDelimiters
|
|
@@ -593,7 +605,7 @@ async function* runPostProcessor(invocationContext, llmResponse) {
|
|
|
593
605
|
codeExecutorContext,
|
|
594
606
|
codeExecutionResult
|
|
595
607
|
);
|
|
596
|
-
llmResponse.content =
|
|
608
|
+
llmResponse.content = void 0;
|
|
597
609
|
}
|
|
598
610
|
function extractAndReplaceInlineFiles(codeExecutorContext, llmRequest) {
|
|
599
611
|
var _a2;
|
|
@@ -719,8 +731,8 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
719
731
|
this.disallowTransferToParent = (_d = config.disallowTransferToParent) != null ? _d : false;
|
|
720
732
|
this.disallowTransferToPeers = (_e = config.disallowTransferToPeers) != null ? _e : false;
|
|
721
733
|
this.includeContents = (_f = config.includeContents) != null ? _f : "default";
|
|
722
|
-
this.inputSchema = config.inputSchema;
|
|
723
|
-
this.outputSchema = config.outputSchema;
|
|
734
|
+
this.inputSchema = isZodObject(config.inputSchema) ? zodObjectToSchema(config.inputSchema) : config.inputSchema;
|
|
735
|
+
this.outputSchema = isZodObject(config.outputSchema) ? zodObjectToSchema(config.outputSchema) : config.outputSchema;
|
|
724
736
|
this.outputKey = config.outputKey;
|
|
725
737
|
this.beforeModelCallback = config.beforeModelCallback;
|
|
726
738
|
this.afterModelCallback = config.afterModelCallback;
|
|
@@ -765,16 +777,6 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
765
777
|
this.disallowTransferToParent = true;
|
|
766
778
|
this.disallowTransferToPeers = true;
|
|
767
779
|
}
|
|
768
|
-
if (this.subAgents && this.subAgents.length > 0) {
|
|
769
|
-
throw new Error(
|
|
770
|
-
`Invalid config for agent ${this.name}: if outputSchema is set, subAgents must be empty to disable agent transfer.`
|
|
771
|
-
);
|
|
772
|
-
}
|
|
773
|
-
if (this.tools && this.tools.length > 0) {
|
|
774
|
-
throw new Error(
|
|
775
|
-
`Invalid config for agent ${this.name}: if outputSchema is set, tools must be empty`
|
|
776
|
-
);
|
|
777
|
-
}
|
|
778
780
|
}
|
|
779
781
|
}
|
|
780
782
|
/**
|
|
@@ -806,12 +808,12 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
806
808
|
* @param context The context to retrieve the session state.
|
|
807
809
|
* @returns The resolved instruction field.
|
|
808
810
|
*/
|
|
809
|
-
async canonicalInstruction(
|
|
811
|
+
async canonicalInstruction(context2) {
|
|
810
812
|
if (typeof this.instruction === "string") {
|
|
811
813
|
return { instruction: this.instruction, requireStateInjection: true };
|
|
812
814
|
}
|
|
813
815
|
return {
|
|
814
|
-
instruction: await this.instruction(
|
|
816
|
+
instruction: await this.instruction(context2),
|
|
815
817
|
requireStateInjection: false
|
|
816
818
|
};
|
|
817
819
|
}
|
|
@@ -822,12 +824,15 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
822
824
|
* @param context The context to retrieve the session state.
|
|
823
825
|
* @returns The resolved globalInstruction field.
|
|
824
826
|
*/
|
|
825
|
-
async canonicalGlobalInstruction(
|
|
827
|
+
async canonicalGlobalInstruction(context2) {
|
|
826
828
|
if (typeof this.globalInstruction === "string") {
|
|
827
|
-
return {
|
|
829
|
+
return {
|
|
830
|
+
instruction: this.globalInstruction,
|
|
831
|
+
requireStateInjection: true
|
|
832
|
+
};
|
|
828
833
|
}
|
|
829
834
|
return {
|
|
830
|
-
instruction: await this.globalInstruction(
|
|
835
|
+
instruction: await this.globalInstruction(context2),
|
|
831
836
|
requireStateInjection: false
|
|
832
837
|
};
|
|
833
838
|
}
|
|
@@ -836,10 +841,10 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
836
841
|
*
|
|
837
842
|
* This method is only for use by Agent Development Kit.
|
|
838
843
|
*/
|
|
839
|
-
async canonicalTools(
|
|
844
|
+
async canonicalTools(context2) {
|
|
840
845
|
const resolvedTools = [];
|
|
841
846
|
for (const toolUnion of this.tools) {
|
|
842
|
-
const tools = await convertToolUnionToTools(toolUnion,
|
|
847
|
+
const tools = await convertToolUnionToTools(toolUnion, context2);
|
|
843
848
|
resolvedTools.push(...tools);
|
|
844
849
|
}
|
|
845
850
|
return resolvedTools;
|
|
@@ -943,10 +948,10 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
943
948
|
}
|
|
944
949
|
event.actions.stateDelta[this.outputKey] = result;
|
|
945
950
|
}
|
|
946
|
-
async *runAsyncImpl(
|
|
951
|
+
async *runAsyncImpl(context2) {
|
|
947
952
|
while (true) {
|
|
948
953
|
let lastEvent = void 0;
|
|
949
|
-
for await (const event of this.runOneStepAsync(
|
|
954
|
+
for await (const event of this.runOneStepAsync(context2)) {
|
|
950
955
|
lastEvent = event;
|
|
951
956
|
this.maybeSaveOutputToState(event);
|
|
952
957
|
yield event;
|
|
@@ -960,19 +965,20 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
960
965
|
}
|
|
961
966
|
}
|
|
962
967
|
}
|
|
963
|
-
async *runLiveImpl(
|
|
964
|
-
for await (const event of this.runLiveFlow(
|
|
968
|
+
async *runLiveImpl(context2) {
|
|
969
|
+
for await (const event of this.runLiveFlow(context2)) {
|
|
965
970
|
this.maybeSaveOutputToState(event);
|
|
966
971
|
yield event;
|
|
967
972
|
}
|
|
968
|
-
if (
|
|
973
|
+
if (context2.endInvocation) {
|
|
969
974
|
return;
|
|
970
975
|
}
|
|
971
976
|
}
|
|
972
977
|
// --------------------------------------------------------------------------
|
|
973
978
|
// #START LlmFlow Logic
|
|
974
979
|
// --------------------------------------------------------------------------
|
|
975
|
-
|
|
980
|
+
// eslint-disable-next-line require-yield
|
|
981
|
+
async *runLiveFlow(_invocationContext) {
|
|
976
982
|
await Promise.resolve();
|
|
977
983
|
throw new Error("LlmAgent.runLiveFlow not implemented");
|
|
978
984
|
}
|
|
@@ -1008,25 +1014,42 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
1008
1014
|
author: this.name,
|
|
1009
1015
|
branch: invocationContext.branch
|
|
1010
1016
|
});
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1017
|
+
const span = tracer.startSpan("call_llm");
|
|
1018
|
+
const ctx = trace.setSpan(context.active(), span);
|
|
1019
|
+
yield* runAsyncGeneratorWithOtelContext(
|
|
1020
|
+
ctx,
|
|
1021
|
+
this,
|
|
1022
|
+
async function* () {
|
|
1023
|
+
const responsesGenerator = async function* () {
|
|
1024
|
+
for await (const llmResponse of this.callLlmAsync(
|
|
1025
|
+
invocationContext,
|
|
1026
|
+
llmRequest,
|
|
1027
|
+
modelResponseEvent
|
|
1028
|
+
)) {
|
|
1029
|
+
for await (const event of this.postprocess(
|
|
1030
|
+
invocationContext,
|
|
1031
|
+
llmRequest,
|
|
1032
|
+
llmResponse,
|
|
1033
|
+
modelResponseEvent
|
|
1034
|
+
)) {
|
|
1035
|
+
modelResponseEvent.id = createNewEventId();
|
|
1036
|
+
modelResponseEvent.timestamp = (/* @__PURE__ */ new Date()).getTime();
|
|
1037
|
+
yield event;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
};
|
|
1041
|
+
yield* this.runAndHandleError(
|
|
1042
|
+
responsesGenerator.call(this),
|
|
1043
|
+
invocationContext,
|
|
1044
|
+
llmRequest,
|
|
1045
|
+
modelResponseEvent
|
|
1046
|
+
);
|
|
1025
1047
|
}
|
|
1026
|
-
|
|
1048
|
+
);
|
|
1049
|
+
span.end();
|
|
1027
1050
|
}
|
|
1028
1051
|
async *postprocess(invocationContext, llmRequest, llmResponse, modelResponseEvent) {
|
|
1029
|
-
var _a2;
|
|
1052
|
+
var _a2, _b2;
|
|
1030
1053
|
for (const processor of this.responseProcessors) {
|
|
1031
1054
|
for await (const event of processor.runAsync(
|
|
1032
1055
|
invocationContext,
|
|
@@ -1055,6 +1078,10 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
1055
1078
|
if (!((_a2 = getFunctionCalls(mergedEvent)) == null ? void 0 : _a2.length)) {
|
|
1056
1079
|
return;
|
|
1057
1080
|
}
|
|
1081
|
+
if ((_b2 = invocationContext.runConfig) == null ? void 0 : _b2.pauseOnToolCalls) {
|
|
1082
|
+
invocationContext.endInvocation = true;
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
1058
1085
|
const functionResponseEvent = await handleFunctionCallsAsync({
|
|
1059
1086
|
invocationContext,
|
|
1060
1087
|
functionCallEvent: mergedEvent,
|
|
@@ -1079,6 +1106,8 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
1079
1106
|
});
|
|
1080
1107
|
if (toolConfirmationEvent) {
|
|
1081
1108
|
yield toolConfirmationEvent;
|
|
1109
|
+
invocationContext.endInvocation = true;
|
|
1110
|
+
return;
|
|
1082
1111
|
}
|
|
1083
1112
|
yield functionResponseEvent;
|
|
1084
1113
|
const nextAgentName = functionResponseEvent.actions.transferToAgent;
|
|
@@ -1135,12 +1164,13 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
1135
1164
|
/* stream= */
|
|
1136
1165
|
((_e = invocationContext.runConfig) == null ? void 0 : _e.streamingMode) === StreamingMode.SSE
|
|
1137
1166
|
);
|
|
1138
|
-
for await (const llmResponse of
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1167
|
+
for await (const llmResponse of responsesGenerator) {
|
|
1168
|
+
traceCallLlm({
|
|
1169
|
+
invocationContext,
|
|
1170
|
+
eventId: modelResponseEvent.id,
|
|
1171
|
+
llmRequest,
|
|
1172
|
+
llmResponse
|
|
1173
|
+
});
|
|
1144
1174
|
const alteredLlmResponse = await this.handleAfterModelCallback(
|
|
1145
1175
|
invocationContext,
|
|
1146
1176
|
llmResponse,
|
|
@@ -1215,11 +1245,29 @@ class LlmAgent extends (_b = BaseAgent, _a = LLM_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
1215
1245
|
if (onModelErrorCallbackResponse) {
|
|
1216
1246
|
yield onModelErrorCallbackResponse;
|
|
1217
1247
|
} else {
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1248
|
+
let errorCode = "UNKNOWN_ERROR";
|
|
1249
|
+
let errorMessage = modelError.message;
|
|
1250
|
+
try {
|
|
1251
|
+
const errorResponse = JSON.parse(modelError.message);
|
|
1252
|
+
if (errorResponse == null ? void 0 : errorResponse.error) {
|
|
1253
|
+
errorCode = String(errorResponse.error.code || "UNKNOWN_ERROR");
|
|
1254
|
+
errorMessage = errorResponse.error.message || errorMessage;
|
|
1255
|
+
}
|
|
1256
|
+
} catch {
|
|
1257
|
+
}
|
|
1258
|
+
if (modelResponseEvent.actions) {
|
|
1259
|
+
yield createEvent({
|
|
1260
|
+
invocationId: invocationContext.invocationId,
|
|
1261
|
+
author: this.name,
|
|
1262
|
+
errorCode,
|
|
1263
|
+
errorMessage
|
|
1264
|
+
});
|
|
1265
|
+
} else {
|
|
1266
|
+
yield {
|
|
1267
|
+
errorCode,
|
|
1268
|
+
errorMessage
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1223
1271
|
}
|
|
1224
1272
|
} else {
|
|
1225
1273
|
logger.error("Unknown error during response generation", modelError);
|
|
@@ -38,7 +38,8 @@ class LoopAgent extends (_b = BaseAgent, _a = LOOP_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
|
38
38
|
}
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
// eslint-disable-next-line require-yield
|
|
42
|
+
async *runLiveImpl(_context) {
|
|
42
43
|
throw new Error("This is not supported yet for LoopAgent.");
|
|
43
44
|
}
|
|
44
45
|
}
|
|
@@ -20,15 +20,14 @@ class ParallelAgent extends (_b = BaseAgent, _a = PARALLEL_AGENT_SIGNATURE_SYMBO
|
|
|
20
20
|
}
|
|
21
21
|
async *runAsyncImpl(context) {
|
|
22
22
|
const agentRuns = this.subAgents.map(
|
|
23
|
-
(subAgent) => subAgent.runAsync(
|
|
24
|
-
createBranchCtxForSubAgent(this, subAgent, context)
|
|
25
|
-
)
|
|
23
|
+
(subAgent) => subAgent.runAsync(createBranchCtxForSubAgent(this, subAgent, context))
|
|
26
24
|
);
|
|
27
25
|
for await (const event of mergeAgentRuns(agentRuns)) {
|
|
28
26
|
yield event;
|
|
29
27
|
}
|
|
30
28
|
}
|
|
31
|
-
|
|
29
|
+
// eslint-disable-next-line require-yield
|
|
30
|
+
async *runLiveImpl(_context) {
|
|
32
31
|
throw new Error("This is not supported yet for ParallelAgent.");
|
|
33
32
|
}
|
|
34
33
|
}
|
|
@@ -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
|
*/
|