@google/adk 2.2.1 → 2.3.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_remote_agent.js +4 -1
- package/dist/cjs/a2a/agent_card.js +102 -26
- package/dist/cjs/a2a/agent_to_a2a.js +1 -1
- package/dist/cjs/agents/functions.js +199 -25
- package/dist/cjs/agents/instructions.js +4 -1
- package/dist/cjs/agents/invocation_context.js +26 -4
- package/dist/cjs/agents/langgraph_agent.js +152 -0
- package/dist/cjs/agents/llm_agent.js +175 -101
- package/dist/cjs/agents/processors/code_execution_request_processor.js +10 -6
- package/dist/cjs/agents/remote_agent.js +187 -0
- package/dist/cjs/artifacts/in_memory_artifact_service.js +14 -0
- package/dist/cjs/auth/auth_handler.js +37 -5
- package/dist/cjs/auth/auth_schemes.js +9 -0
- package/dist/cjs/cli/cli_eval.js +532 -0
- package/dist/cjs/cli/utils/envs.js +116 -0
- package/dist/cjs/cli/utils/evals.js +137 -0
- package/dist/cjs/cli/utils/logs.js +150 -0
- package/dist/cjs/code_executors/agent_engine_sandbox_code_executor.js +7 -2
- package/dist/cjs/code_executors/code_execution_utils.js +48 -16
- package/dist/cjs/code_executors/code_executor_context.js +6 -2
- package/dist/cjs/common.js +72 -0
- package/dist/cjs/context/summarizers/llm_summarizer.js +12 -10
- package/dist/cjs/context/token_based_context_compactor.js +2 -1
- package/dist/cjs/events/event.js +4 -2
- package/dist/cjs/examples/example_util.js +23 -2
- package/dist/cjs/flows/llm_flows/audio_transcriber.js +170 -0
- package/dist/cjs/index.js +97 -1
- package/dist/cjs/integrations/agent_registry/helpers.js +1 -1
- package/dist/cjs/models/gemini_llm_connection.js +16 -8
- package/dist/cjs/models/google_llm.js +13 -16
- package/dist/cjs/models/llm_response.js +9 -1
- package/dist/cjs/models/registry.js +1 -1
- package/dist/cjs/models/routed_llm.js +9 -8
- package/dist/cjs/planners/plan_re_act_planner.js +1 -1
- package/dist/cjs/runner/in_memory_runner.js +6 -11
- package/dist/cjs/runner/runner.js +105 -33
- package/dist/cjs/sessions/db/operations.js +1 -1
- package/dist/cjs/sessions/in_memory_session_service.js +3 -1
- package/dist/cjs/sessions/state.js +8 -4
- package/dist/cjs/sessions/vertex_ai_session_service.js +34 -15
- package/dist/cjs/telemetry/tracing.js +97 -66
- package/dist/cjs/tools/agent_tool.js +44 -0
- package/dist/cjs/tools/apihub_tool/apihub_toolset.js +142 -0
- package/dist/cjs/tools/apihub_tool/clients/apihub_client.js +272 -0
- package/dist/cjs/tools/apihub_tool/clients/secret_client.js +148 -0
- package/dist/cjs/tools/apihub_tool/clients/service_account.js +48 -0
- package/dist/cjs/tools/application_integration_tool/application_integration_toolset.js +185 -0
- package/dist/cjs/tools/application_integration_tool/clients/cloud_request.js +133 -0
- package/dist/cjs/tools/application_integration_tool/clients/connections_client.js +603 -0
- package/dist/cjs/tools/application_integration_tool/clients/integration_client.js +219 -0
- package/dist/cjs/tools/crewai_tool.js +132 -0
- package/dist/cjs/tools/example_tool.js +10 -0
- package/dist/cjs/tools/function_tool.js +319 -0
- package/dist/cjs/tools/google_api_tool/google_api_tool.js +97 -0
- package/dist/cjs/tools/google_api_tool/google_api_tool_set.js +226 -0
- package/dist/cjs/tools/google_api_tool/google_api_tool_sets.js +58 -0
- package/dist/cjs/tools/google_api_tool/googleapi_to_openapi_converter.js +440 -0
- package/dist/cjs/tools/google_api_tool/index.js +64 -0
- package/dist/cjs/tools/langchain_tool.js +172 -0
- package/dist/cjs/tools/mcp/index.js +12 -0
- package/dist/cjs/tools/mcp/mcp_session_manager.js +25 -0
- package/dist/cjs/tools/openapi_tool/auth/auth_helpers.js +1 -2
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +46 -2
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -1
- package/dist/cjs/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
- package/dist/cjs/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +14 -2
- package/dist/cjs/tools/retrieval/base_retrieval_tool.js +18 -3
- package/dist/cjs/tools/toolbox_tool.js +108 -0
- package/dist/cjs/utils/env_aware_utils.js +6 -8
- package/dist/cjs/utils/error_utils.js +11 -11
- package/dist/cjs/utils/file_extension_utils.js +11 -0
- package/dist/cjs/utils/file_utils.js +2 -24
- package/dist/cjs/utils/gemini_schema_util.js +4 -1
- package/dist/cjs/utils/json_utils.js +49 -0
- package/dist/cjs/utils/live_connection_utils.js +4 -5
- package/dist/cjs/utils/logger_node.js +7 -1
- package/dist/cjs/utils/object_notation_utils.js +6 -3
- package/dist/cjs/utils/streaming_utils.js +12 -12
- package/dist/cjs/version.js +1 -1
- package/dist/esm/a2a/a2a_remote_agent.js +4 -1
- package/dist/esm/a2a/agent_card.js +103 -27
- package/dist/esm/a2a/agent_to_a2a.js +5 -2
- package/dist/esm/agents/functions.js +198 -25
- package/dist/esm/agents/instructions.js +4 -1
- package/dist/esm/agents/invocation_context.js +24 -4
- package/dist/esm/agents/langgraph_agent.js +123 -0
- package/dist/esm/agents/llm_agent.js +185 -104
- package/dist/esm/agents/processors/code_execution_request_processor.js +13 -8
- package/dist/esm/agents/remote_agent.js +164 -0
- package/dist/esm/artifacts/in_memory_artifact_service.js +14 -0
- package/dist/esm/auth/auth_handler.js +37 -5
- package/dist/esm/auth/auth_schemes.js +8 -0
- package/dist/esm/cli/cli_eval.js +510 -0
- package/dist/esm/cli/utils/envs.js +78 -0
- package/dist/esm/cli/utils/evals.js +109 -0
- package/dist/esm/cli/utils/logs.js +111 -0
- package/dist/esm/code_executors/agent_engine_sandbox_code_executor.js +7 -2
- package/dist/esm/code_executors/code_execution_utils.js +46 -16
- package/dist/esm/code_executors/code_executor_context.js +5 -2
- package/dist/esm/common.js +67 -3
- package/dist/esm/context/summarizers/llm_summarizer.js +12 -10
- package/dist/esm/context/token_based_context_compactor.js +2 -1
- package/dist/esm/events/event.js +4 -2
- package/dist/esm/examples/example_util.js +21 -1
- package/dist/esm/flows/llm_flows/audio_transcriber.js +142 -0
- package/dist/esm/index.js +99 -1
- package/dist/esm/integrations/agent_registry/helpers.js +1 -1
- package/dist/esm/models/gemini_llm_connection.js +16 -8
- package/dist/esm/models/google_llm.js +14 -17
- package/dist/esm/models/llm_response.js +9 -1
- package/dist/esm/models/registry.js +1 -1
- package/dist/esm/models/routed_llm.js +9 -8
- package/dist/esm/planners/plan_re_act_planner.js +1 -1
- package/dist/esm/runner/in_memory_runner.js +6 -11
- package/dist/esm/runner/runner.js +105 -33
- package/dist/esm/sessions/db/operations.js +1 -1
- package/dist/esm/sessions/in_memory_session_service.js +3 -1
- package/dist/esm/sessions/state.js +8 -4
- package/dist/esm/sessions/vertex_ai_session_service.js +34 -15
- package/dist/esm/telemetry/tracing.js +97 -66
- package/dist/esm/tools/agent_tool.js +44 -0
- package/dist/esm/tools/apihub_tool/apihub_toolset.js +106 -0
- package/dist/esm/tools/apihub_tool/clients/apihub_client.js +244 -0
- package/dist/esm/tools/apihub_tool/clients/secret_client.js +132 -0
- package/dist/esm/tools/apihub_tool/clients/service_account.js +21 -0
- package/dist/esm/tools/application_integration_tool/application_integration_toolset.js +163 -0
- package/dist/esm/tools/application_integration_tool/clients/cloud_request.js +103 -0
- package/dist/esm/tools/application_integration_tool/clients/connections_client.js +561 -0
- package/dist/esm/tools/application_integration_tool/clients/integration_client.js +215 -0
- package/dist/esm/tools/crewai_tool.js +107 -0
- package/dist/esm/tools/example_tool.js +13 -1
- package/dist/esm/tools/function_tool.js +316 -0
- package/dist/esm/tools/google_api_tool/google_api_tool.js +70 -0
- package/dist/esm/tools/google_api_tool/google_api_tool_set.js +188 -0
- package/dist/esm/tools/google_api_tool/google_api_tool_sets.js +24 -0
- package/dist/esm/tools/google_api_tool/googleapi_to_openapi_converter.js +393 -0
- package/dist/esm/tools/google_api_tool/index.js +33 -0
- package/dist/esm/tools/langchain_tool.js +148 -0
- package/dist/esm/tools/mcp/index.js +6 -0
- package/dist/esm/tools/mcp/mcp_session_manager.js +25 -0
- package/dist/esm/tools/openapi_tool/auth/auth_helpers.js +1 -2
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.js +50 -3
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/oauth2_exchanger.js +2 -1
- package/dist/esm/tools/openapi_tool/auth/credential_exchangers/service_account_exchanger.js +94 -10
- package/dist/esm/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.js +15 -2
- package/dist/esm/tools/retrieval/base_retrieval_tool.js +16 -2
- package/dist/esm/tools/toolbox_tool.js +80 -0
- package/dist/esm/utils/env_aware_utils.js +6 -8
- package/dist/esm/utils/error_utils.js +9 -10
- package/dist/esm/utils/file_extension_utils.js +11 -0
- package/dist/esm/utils/file_utils.js +2 -23
- package/dist/esm/utils/gemini_schema_util.js +4 -1
- package/dist/esm/utils/json_utils.js +21 -0
- package/dist/esm/utils/live_connection_utils.js +4 -5
- package/dist/esm/utils/logger_node.js +7 -1
- package/dist/esm/utils/object_notation_utils.js +4 -2
- package/dist/esm/utils/streaming_utils.js +11 -11
- package/dist/esm/version.js +1 -1
- package/dist/types/a2a/a2a_remote_agent.d.ts +9 -0
- package/dist/types/a2a/agent_card.d.ts +44 -1
- package/dist/types/a2a/agent_to_a2a.d.ts +9 -0
- package/dist/types/a2a/index.d.ts +1 -0
- package/dist/types/agents/functions.d.ts +33 -1
- package/dist/types/agents/invocation_context.d.ts +20 -1
- package/dist/types/agents/langgraph_agent.d.ts +153 -0
- package/dist/types/agents/remote_agent.d.ts +68 -0
- package/dist/types/auth/auth_handler.d.ts +28 -1
- package/dist/types/auth/auth_schemes.d.ts +13 -0
- package/dist/types/cli/cli_eval.d.ts +173 -0
- package/dist/types/cli/utils/envs.d.ts +23 -0
- package/dist/types/cli/utils/evals.d.ts +47 -0
- package/dist/types/cli/utils/logs.d.ts +38 -0
- package/dist/types/code_executors/code_execution_utils.d.ts +39 -0
- package/dist/types/code_executors/code_executor_context.d.ts +1 -0
- package/dist/types/common.d.ts +27 -4
- package/dist/types/events/event.d.ts +4 -0
- package/dist/types/examples/example_util.d.ts +17 -0
- package/dist/types/flows/llm_flows/audio_transcriber.d.ts +85 -0
- package/dist/types/index.d.ts +16 -1
- package/dist/types/models/gemini_llm_connection.d.ts +6 -7
- package/dist/types/models/routed_llm.d.ts +1 -1
- package/dist/types/runner/in_memory_runner.d.ts +2 -1
- package/dist/types/runner/runner.d.ts +34 -0
- package/dist/types/sessions/state.d.ts +5 -1
- package/dist/types/sessions/vertex_ai_session_service.d.ts +8 -0
- package/dist/types/skills/skill.d.ts +1 -1
- package/dist/types/telemetry/tracing.d.ts +4 -2
- package/dist/types/tools/apihub_tool/apihub_toolset.d.ts +122 -0
- package/dist/types/tools/apihub_tool/clients/apihub_client.d.ts +142 -0
- package/dist/types/tools/apihub_tool/clients/secret_client.d.ts +55 -0
- package/dist/types/tools/apihub_tool/clients/service_account.d.ts +11 -0
- package/dist/types/tools/application_integration_tool/application_integration_toolset.d.ts +86 -0
- package/dist/types/tools/application_integration_tool/clients/cloud_request.d.ts +53 -0
- package/dist/types/tools/application_integration_tool/clients/connections_client.d.ts +215 -0
- package/dist/types/tools/application_integration_tool/clients/integration_client.d.ts +72 -0
- package/dist/types/tools/crewai_tool.d.ts +85 -0
- package/dist/types/tools/example_tool.d.ts +10 -0
- package/dist/types/tools/function_tool.d.ts +32 -0
- package/dist/types/tools/google_api_tool/google_api_tool.d.ts +30 -0
- package/dist/types/tools/google_api_tool/google_api_tool_set.d.ts +78 -0
- package/dist/types/tools/google_api_tool/google_api_tool_sets.d.ts +33 -0
- package/dist/types/tools/google_api_tool/googleapi_to_openapi_converter.d.ts +164 -0
- package/dist/types/tools/google_api_tool/index.d.ts +11 -0
- package/dist/types/tools/langchain_tool.d.ts +103 -0
- package/dist/types/tools/mcp/index.d.ts +3 -0
- package/dist/types/tools/mcp/mcp_session_manager.d.ts +34 -1
- package/dist/types/tools/mcp/mcp_toolset.d.ts +15 -0
- package/dist/types/tools/openapi_tool/auth/auth_helpers.d.ts +19 -0
- package/dist/types/tools/openapi_tool/auth/credential_exchangers/auto_auth_credential_exchanger.d.ts +18 -1
- package/dist/types/tools/openapi_tool/openapi_spec_parser/tool_auth_handler.d.ts +2 -1
- package/dist/types/tools/retrieval/base_retrieval_tool.d.ts +15 -0
- package/dist/types/tools/toolbox_tool.d.ts +73 -0
- package/dist/types/utils/env_aware_utils.d.ts +18 -2
- package/dist/types/utils/error_utils.d.ts +7 -0
- package/dist/types/utils/file_utils.d.ts +6 -1
- package/dist/types/utils/gemini_schema_util.d.ts +1 -2
- package/dist/types/utils/json_utils.d.ts +11 -0
- package/dist/types/utils/object_notation_utils.d.ts +7 -0
- package/dist/types/utils/streaming_utils.d.ts +11 -4
- package/dist/types/version.d.ts +1 -1
- package/dist/web/index_web.js +102 -103
- package/dist/web/index_web.js.map +4 -4
- package/package.json +8 -3
- package/dist/cjs/models/gemini_continuation.js +0 -232
- package/dist/esm/models/gemini_continuation.js +0 -205
- package/dist/types/models/gemini_continuation.d.ts +0 -59
|
@@ -43,6 +43,7 @@ var import_run_config = require("../agents/run_config.js");
|
|
|
43
43
|
var import_scoped_artifact_service = require("../artifacts/scoped_artifact_service.js");
|
|
44
44
|
var import_session_artifact_service = require("../artifacts/session_artifact_service.js");
|
|
45
45
|
var import_built_in_code_executor = require("../code_executors/built_in_code_executor.js");
|
|
46
|
+
var import_abort_events = require("../events/abort_events.js");
|
|
46
47
|
var import_event = require("../events/event.js");
|
|
47
48
|
var import_event_actions = require("../events/event_actions.js");
|
|
48
49
|
var import_internal_metadata = require("../events/internal_metadata.js");
|
|
@@ -73,8 +74,8 @@ const _Runner = class _Runner {
|
|
|
73
74
|
*/
|
|
74
75
|
constructor(input) {
|
|
75
76
|
this[_a] = true;
|
|
76
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
77
|
-
const appName = (_b = (_a2 = input.app) == null ? void 0 : _a2.name
|
|
77
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
78
|
+
const appName = (_b = input.appName) != null ? _b : (_a2 = input.app) == null ? void 0 : _a2.name;
|
|
78
79
|
const agent = (_d = (_c = input.app) == null ? void 0 : _c.rootAgent) != null ? _d : input.agent;
|
|
79
80
|
if (!agent) {
|
|
80
81
|
throw new Error(
|
|
@@ -91,6 +92,20 @@ const _Runner = class _Runner {
|
|
|
91
92
|
this.memoryService = input.memoryService;
|
|
92
93
|
this.credentialService = input.credentialService;
|
|
93
94
|
this.resumabilityConfig = (_i = (_h = input.app) == null ? void 0 : _h.resumabilityConfig) != null ? _i : input.resumabilityConfig;
|
|
95
|
+
this.autoCreateSession = (_j = input.autoCreateSession) != null ? _j : false;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Looks the session up, creating it first when `autoCreateSession` is set.
|
|
99
|
+
*
|
|
100
|
+
* A runner with no `appName` cannot address a session, so it falls through to
|
|
101
|
+
* the plain lookup rather than creating one under an undefined app name.
|
|
102
|
+
*/
|
|
103
|
+
async resolveSession(userId, sessionId) {
|
|
104
|
+
const key = { appName: this.appName, userId, sessionId };
|
|
105
|
+
if (this.autoCreateSession && this.appName) {
|
|
106
|
+
return this.sessionService.getOrCreateSession(key);
|
|
107
|
+
}
|
|
108
|
+
return this.sessionService.getSession(key);
|
|
94
109
|
}
|
|
95
110
|
/**
|
|
96
111
|
* Runs the agent with a new, ephemeral session.
|
|
@@ -151,12 +166,8 @@ const _Runner = class _Runner {
|
|
|
151
166
|
ctx,
|
|
152
167
|
this,
|
|
153
168
|
async function* () {
|
|
154
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
155
|
-
const session = await this.
|
|
156
|
-
appName: this.appName,
|
|
157
|
-
userId,
|
|
158
|
-
sessionId
|
|
159
|
-
});
|
|
169
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
170
|
+
const session = await this.resolveSession(userId, sessionId);
|
|
160
171
|
if ((_a2 = params.abortSignal) == null ? void 0 : _a2.aborted) {
|
|
161
172
|
return;
|
|
162
173
|
}
|
|
@@ -267,35 +278,45 @@ const _Runner = class _Runner {
|
|
|
267
278
|
}
|
|
268
279
|
yield earlyExitEvent;
|
|
269
280
|
} else {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
session,
|
|
289
|
-
event: outputEvent
|
|
290
|
-
});
|
|
281
|
+
let abortSealed = false;
|
|
282
|
+
const sealAbortedInvocation = /* @__PURE__ */ __name(() => {
|
|
283
|
+
abortSealed = true;
|
|
284
|
+
return this.synthesizeAbortEvents(invocationContext);
|
|
285
|
+
}, "sealAbortedInvocation");
|
|
286
|
+
try {
|
|
287
|
+
for await (const event of this.runRoot(invocationContext)) {
|
|
288
|
+
if ((_h = params.abortSignal) == null ? void 0 : _h.aborted) {
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
const outputEvent = await this.processAndAppendEvent(
|
|
292
|
+
invocationContext,
|
|
293
|
+
event
|
|
294
|
+
);
|
|
295
|
+
if ((_i = params.abortSignal) == null ? void 0 : _i.aborted) {
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
yield outputEvent;
|
|
291
299
|
}
|
|
292
300
|
if ((_j = params.abortSignal) == null ? void 0 : _j.aborted) {
|
|
301
|
+
for (const abortEvent of await sealAbortedInvocation()) {
|
|
302
|
+
yield abortEvent;
|
|
303
|
+
}
|
|
293
304
|
return;
|
|
294
305
|
}
|
|
295
|
-
|
|
306
|
+
} finally {
|
|
307
|
+
if (((_k = params.abortSignal) == null ? void 0 : _k.aborted) && !abortSealed) {
|
|
308
|
+
try {
|
|
309
|
+
await sealAbortedInvocation();
|
|
310
|
+
} catch (e) {
|
|
311
|
+
import_logger.logger.error(
|
|
312
|
+
`Failed to seal aborted invocation ${invocationContext.invocationId}.`,
|
|
313
|
+
e
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
296
317
|
}
|
|
297
318
|
await this.pluginManager.runAfterRunCallback({ invocationContext });
|
|
298
|
-
if ((
|
|
319
|
+
if ((_l = params.abortSignal) == null ? void 0 : _l.aborted) {
|
|
299
320
|
return;
|
|
300
321
|
}
|
|
301
322
|
}
|
|
@@ -327,6 +348,56 @@ const _Runner = class _Runner {
|
|
|
327
348
|
}
|
|
328
349
|
yield* (0, import_run_node_as_invocation.runNodeAsInvocation)(this.agent, invocationContext);
|
|
329
350
|
}
|
|
351
|
+
/**
|
|
352
|
+
* Runs the on_event plugin callbacks on an event and appends the result to
|
|
353
|
+
* the session unless it is partial.
|
|
354
|
+
*
|
|
355
|
+
* @returns The event as streamed to the caller.
|
|
356
|
+
*/
|
|
357
|
+
async processAndAppendEvent(invocationContext, event) {
|
|
358
|
+
var _a2;
|
|
359
|
+
const modifiedEvent = await this.pluginManager.runOnEventCallback({
|
|
360
|
+
invocationContext,
|
|
361
|
+
event
|
|
362
|
+
});
|
|
363
|
+
const outputEvent = modifiedEvent ? {
|
|
364
|
+
...withInternalMetadataOf(event, modifiedEvent),
|
|
365
|
+
id: event.id,
|
|
366
|
+
invocationId: event.invocationId,
|
|
367
|
+
timestamp: event.timestamp,
|
|
368
|
+
author: modifiedEvent.author || event.author,
|
|
369
|
+
branch: (_a2 = modifiedEvent.branch) != null ? _a2 : event.branch
|
|
370
|
+
} : event;
|
|
371
|
+
if (!event.partial) {
|
|
372
|
+
await this.sessionService.appendEvent({
|
|
373
|
+
session: invocationContext.session,
|
|
374
|
+
event: outputEvent
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
return outputEvent;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Seals an aborted invocation in session history: answers its dangling
|
|
381
|
+
* function calls with error responses, or records a plain abort event when
|
|
382
|
+
* there is nothing to answer.
|
|
383
|
+
*
|
|
384
|
+
* @returns The synthetic events after plugin processing and persistence.
|
|
385
|
+
*/
|
|
386
|
+
async synthesizeAbortEvents(invocationContext) {
|
|
387
|
+
const abortEvents = (0, import_abort_events.buildAbortEvents)({
|
|
388
|
+
events: invocationContext.session.events,
|
|
389
|
+
invocationId: invocationContext.invocationId,
|
|
390
|
+
rootAgentName: this.agent.name,
|
|
391
|
+
branch: invocationContext.branch
|
|
392
|
+
});
|
|
393
|
+
const outputEvents = [];
|
|
394
|
+
for (const event of abortEvents) {
|
|
395
|
+
outputEvents.push(
|
|
396
|
+
await this.processAndAppendEvent(invocationContext, event)
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
return outputEvents;
|
|
400
|
+
}
|
|
330
401
|
/**
|
|
331
402
|
* Saves artifacts from the message parts and replaces the inline data with
|
|
332
403
|
* a file name placeholder and optional file reference.
|
|
@@ -573,7 +644,8 @@ function isLiveModelMediaEventWithInlineData(event) {
|
|
|
573
644
|
}
|
|
574
645
|
__name(isLiveModelMediaEventWithInlineData, "isLiveModelMediaEventWithInlineData");
|
|
575
646
|
function determineAgentForResumption(session, rootAgent, resumabilityConfig) {
|
|
576
|
-
const
|
|
647
|
+
const lastEvent = session.events[session.events.length - 1];
|
|
648
|
+
const event = lastEvent && !(0, import_abort_events.isAbortEvent)(lastEvent) ? findEventByLastFunctionResponseId(session.events) : null;
|
|
577
649
|
const isResumable = Boolean(resumabilityConfig == null ? void 0 : resumabilityConfig.isResumable);
|
|
578
650
|
if (event && event.author && isResumable) {
|
|
579
651
|
const conflictingAuthors = (0, import_functions.getConflictingFunctionResponseAuthors)(
|
|
@@ -597,7 +669,7 @@ function determineAgentForResumption(session, rootAgent, resumabilityConfig) {
|
|
|
597
669
|
for (let i = session.events.length - 1; i >= 0; i--) {
|
|
598
670
|
import_logger.logger.debug("event:", (0, import_redact_inline_data.stringifyWithRedactedInlineData)(session.events[i]));
|
|
599
671
|
const event2 = session.events[i];
|
|
600
|
-
if (event2.author === "user" || !event2.author) {
|
|
672
|
+
if (event2.author === "user" || !event2.author || (0, import_abort_events.isAbortEvent)(event2)) {
|
|
601
673
|
continue;
|
|
602
674
|
}
|
|
603
675
|
if (event2.author === rootAgent.name) {
|
|
@@ -293,7 +293,7 @@ async function getConnectionOptionsFromUri(uri) {
|
|
|
293
293
|
);
|
|
294
294
|
return {
|
|
295
295
|
entities: import_schema.ENTITIES,
|
|
296
|
-
dbName: uri === "sqlite://:memory:" ? ":memory:" : uri.substring("sqlite://".length),
|
|
296
|
+
dbName: uri === "sqlite://:memory:" || uri === "sqlite:///:memory:" ? ":memory:" : uri.substring("sqlite://".length),
|
|
297
297
|
driver: SqliteDriver
|
|
298
298
|
};
|
|
299
299
|
}
|
|
@@ -70,7 +70,9 @@ const _InMemorySessionService = class _InMemorySessionService extends import_bas
|
|
|
70
70
|
var _a;
|
|
71
71
|
const filteredState = state ? (0, import_base_session_service.trimTempState)(state) : void 0;
|
|
72
72
|
const session = (0, import_session.createSession)({
|
|
73
|
-
|
|
73
|
+
// Surrounding whitespace is dropped so that a later lookup by the bare
|
|
74
|
+
// id finds the session, and a blank id gets a generated one.
|
|
75
|
+
id: (sessionId == null ? void 0 : sessionId.trim()) || (0, import_env_aware_utils.randomUUID)(),
|
|
74
76
|
appName,
|
|
75
77
|
userId,
|
|
76
78
|
state: filteredState,
|
|
@@ -102,16 +102,19 @@ const _State = class _State {
|
|
|
102
102
|
/**
|
|
103
103
|
* Returns the value of the state dict for the given key.
|
|
104
104
|
*
|
|
105
|
+
* Only keys the state holds itself are found. Names inherited from
|
|
106
|
+
* `Object.prototype`, such as `toString`, are treated as missing.
|
|
107
|
+
*
|
|
105
108
|
* @param key The key to get the value for.
|
|
106
109
|
* @param defaultValue The default value to return if the key is not found.
|
|
107
110
|
* @return The value of the state for the given key, or the default value if
|
|
108
111
|
* not found.
|
|
109
112
|
*/
|
|
110
113
|
get(key, defaultValue) {
|
|
111
|
-
if (
|
|
114
|
+
if (Object.hasOwn(this.delta, key)) {
|
|
112
115
|
return this.delta[key];
|
|
113
116
|
}
|
|
114
|
-
if (
|
|
117
|
+
if (Object.hasOwn(this.value, key)) {
|
|
115
118
|
return this.value[key];
|
|
116
119
|
}
|
|
117
120
|
return defaultValue;
|
|
@@ -129,10 +132,11 @@ const _State = class _State {
|
|
|
129
132
|
(0, import_state_write_order.recordStateWrite)(this.value, this.delta, key);
|
|
130
133
|
}
|
|
131
134
|
/**
|
|
132
|
-
* Whether the state
|
|
135
|
+
* Whether the state holds the given key, either as a stored value or as a
|
|
136
|
+
* pending delta. Names inherited from `Object.prototype` are not keys.
|
|
133
137
|
*/
|
|
134
138
|
has(key) {
|
|
135
|
-
return
|
|
139
|
+
return Object.hasOwn(this.value, key) || Object.hasOwn(this.delta, key);
|
|
136
140
|
}
|
|
137
141
|
/**
|
|
138
142
|
* Whether the state has pending delta.
|
|
@@ -65,17 +65,22 @@ function quoteFilterLiteral(value) {
|
|
|
65
65
|
return `"${escaped}"`;
|
|
66
66
|
}
|
|
67
67
|
__name(quoteFilterLiteral, "quoteFilterLiteral");
|
|
68
|
+
function toStateMap(state) {
|
|
69
|
+
return Object.assign(/* @__PURE__ */ Object.create(null), state);
|
|
70
|
+
}
|
|
71
|
+
__name(toStateMap, "toStateMap");
|
|
68
72
|
let VertexAiSessionService = class extends import_base_session_service.BaseSessionService {
|
|
69
73
|
constructor(options) {
|
|
70
74
|
super();
|
|
71
75
|
this.agentEngineId = options.agentEngineId;
|
|
72
|
-
this.projectId = options.projectId;
|
|
73
|
-
this.location = options.location;
|
|
74
76
|
this.expressModeApiKey = (0, import_vertex_ai_utils.getExpressModeApiKey)(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
+
options.projectId,
|
|
78
|
+
options.location,
|
|
77
79
|
options.expressModeApiKey
|
|
78
80
|
);
|
|
81
|
+
const useEnvironment = !options.expressModeApiKey;
|
|
82
|
+
this.projectId = options.projectId || (useEnvironment ? process.env["GOOGLE_CLOUD_PROJECT"] : void 0);
|
|
83
|
+
this.location = options.location || (useEnvironment ? process.env["GOOGLE_CLOUD_LOCATION"] : void 0);
|
|
79
84
|
if (options.sessions) {
|
|
80
85
|
this.sessions = options.sessions;
|
|
81
86
|
} else {
|
|
@@ -161,7 +166,7 @@ let VertexAiSessionService = class extends import_base_session_service.BaseSessi
|
|
|
161
166
|
id,
|
|
162
167
|
appName,
|
|
163
168
|
userId,
|
|
164
|
-
state: getSessionResponse.sessionState,
|
|
169
|
+
state: toStateMap(getSessionResponse.sessionState),
|
|
165
170
|
events: [],
|
|
166
171
|
lastUpdateTime: getSessionResponse.updateTime ? Date.parse(getSessionResponse.updateTime) : Date.now()
|
|
167
172
|
});
|
|
@@ -176,13 +181,14 @@ let VertexAiSessionService = class extends import_base_session_service.BaseSessi
|
|
|
176
181
|
const sessionResourceName = `reasoningEngines/${reasoningEngineId}/sessions/${sessionId}`;
|
|
177
182
|
try {
|
|
178
183
|
let getSessionResponse;
|
|
179
|
-
|
|
184
|
+
const eventsIterator = [];
|
|
185
|
+
const listConfig = {};
|
|
186
|
+
let pageToken;
|
|
180
187
|
if (config && config.numRecentEvents === 0) {
|
|
181
188
|
getSessionResponse = await this.sessions.get({
|
|
182
189
|
name: sessionResourceName
|
|
183
190
|
});
|
|
184
191
|
} else {
|
|
185
|
-
const listConfig = {};
|
|
186
192
|
if (config && config.afterTimestamp) {
|
|
187
193
|
listConfig.filter = `timestamp>="${new Date(
|
|
188
194
|
config.afterTimestamp
|
|
@@ -196,7 +202,9 @@ let VertexAiSessionService = class extends import_base_session_service.BaseSessi
|
|
|
196
202
|
})
|
|
197
203
|
]);
|
|
198
204
|
getSessionResponse = sessionRes;
|
|
199
|
-
|
|
205
|
+
const firstPage = eventsRes;
|
|
206
|
+
eventsIterator.push(...firstPage.sessionEvents || []);
|
|
207
|
+
pageToken = firstPage.nextPageToken;
|
|
200
208
|
}
|
|
201
209
|
const sessionObj = getSessionResponse;
|
|
202
210
|
if (sessionObj.userId !== userId) {
|
|
@@ -204,20 +212,29 @@ let VertexAiSessionService = class extends import_base_session_service.BaseSessi
|
|
|
204
212
|
`Session ${sessionId} does not belong to user ${userId}.`
|
|
205
213
|
);
|
|
206
214
|
}
|
|
215
|
+
while (pageToken) {
|
|
216
|
+
const eventsRes = await this.sessions.events.listInternal({
|
|
217
|
+
name: sessionResourceName,
|
|
218
|
+
config: {
|
|
219
|
+
...listConfig,
|
|
220
|
+
pageToken
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
eventsIterator.push(...eventsRes.sessionEvents || []);
|
|
224
|
+
pageToken = eventsRes.nextPageToken;
|
|
225
|
+
}
|
|
207
226
|
const session = (0, import_session.createSession)({
|
|
208
227
|
id: sessionId,
|
|
209
228
|
appName,
|
|
210
229
|
userId,
|
|
211
|
-
state: sessionObj.sessionState,
|
|
230
|
+
state: toStateMap(sessionObj.sessionState),
|
|
212
231
|
events: [],
|
|
213
232
|
lastUpdateTime: sessionObj.updateTime ? Date.parse(sessionObj.updateTime) : Date.now()
|
|
214
233
|
});
|
|
215
|
-
|
|
234
|
+
const recentEvents = config && config.numRecentEvents ? eventsIterator.slice(-config.numRecentEvents) : eventsIterator;
|
|
235
|
+
for (const event of recentEvents) {
|
|
216
236
|
session.events.push(_fromApiEvent(event));
|
|
217
237
|
}
|
|
218
|
-
if (config && config.numRecentEvents) {
|
|
219
|
-
session.events = session.events.slice(-config.numRecentEvents);
|
|
220
|
-
}
|
|
221
238
|
return session;
|
|
222
239
|
} catch (error) {
|
|
223
240
|
const err = error;
|
|
@@ -256,7 +273,7 @@ let VertexAiSessionService = class extends import_base_session_service.BaseSessi
|
|
|
256
273
|
id,
|
|
257
274
|
appName,
|
|
258
275
|
userId: sessionObj.userId,
|
|
259
|
-
state: sessionObj.sessionState,
|
|
276
|
+
state: toStateMap(sessionObj.sessionState),
|
|
260
277
|
events: [],
|
|
261
278
|
lastUpdateTime: sessionObj.updateTime ? new Date(sessionObj.updateTime).getTime() : Date.now()
|
|
262
279
|
})
|
|
@@ -502,7 +519,9 @@ function _fromApiEvent(apiEventObj) {
|
|
|
502
519
|
}
|
|
503
520
|
}
|
|
504
521
|
const eventActions = {
|
|
505
|
-
stateDelta:
|
|
522
|
+
stateDelta: toStateMap(
|
|
523
|
+
actions["stateDelta"]
|
|
524
|
+
),
|
|
506
525
|
artifactDelta: actions["artifactDelta"] || {},
|
|
507
526
|
requestedAuthConfigs: actions.requestedAuthConfigs || {},
|
|
508
527
|
requestedToolConfirmations: actions["requestedToolConfirmations"] || {},
|
|
@@ -43,21 +43,46 @@ var import_version = require("../version.js");
|
|
|
43
43
|
* Copyright 2025 Google LLC
|
|
44
44
|
* SPDX-License-Identifier: Apache-2.0
|
|
45
45
|
*/
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
46
|
+
var GenAiAttr = /* @__PURE__ */ ((GenAiAttr2) => {
|
|
47
|
+
GenAiAttr2["AGENT_DESCRIPTION"] = "gen_ai.agent.description";
|
|
48
|
+
GenAiAttr2["AGENT_NAME"] = "gen_ai.agent.name";
|
|
49
|
+
GenAiAttr2["CONVERSATION_ID"] = "gen_ai.conversation.id";
|
|
50
|
+
GenAiAttr2["OPERATION_NAME"] = "gen_ai.operation.name";
|
|
51
|
+
GenAiAttr2["SYSTEM"] = "gen_ai.system";
|
|
52
|
+
GenAiAttr2["TOOL_CALL_ID"] = "gen_ai.tool.call.id";
|
|
53
|
+
GenAiAttr2["TOOL_DESCRIPTION"] = "gen_ai.tool.description";
|
|
54
|
+
GenAiAttr2["TOOL_NAME"] = "gen_ai.tool.name";
|
|
55
|
+
GenAiAttr2["TOOL_TYPE"] = "gen_ai.tool.type";
|
|
56
|
+
GenAiAttr2["REQUEST_MODEL"] = "gen_ai.request.model";
|
|
57
|
+
GenAiAttr2["REQUEST_TOP_P"] = "gen_ai.request.top_p";
|
|
58
|
+
GenAiAttr2["REQUEST_MAX_TOKENS"] = "gen_ai.request.max_tokens";
|
|
59
|
+
GenAiAttr2["USAGE_INPUT_TOKENS"] = "gen_ai.usage.input_tokens";
|
|
60
|
+
GenAiAttr2["USAGE_OUTPUT_TOKENS"] = "gen_ai.usage.output_tokens";
|
|
61
|
+
GenAiAttr2["RESPONSE_FINISH_REASONS"] = "gen_ai.response.finish_reasons";
|
|
62
|
+
return GenAiAttr2;
|
|
63
|
+
})(GenAiAttr || {});
|
|
64
|
+
var AdkAttr = /* @__PURE__ */ ((AdkAttr2) => {
|
|
65
|
+
AdkAttr2["WORKFLOW_NAME"] = "adk.workflow.name";
|
|
66
|
+
AdkAttr2["NODE_PATH"] = "adk.node.path";
|
|
67
|
+
AdkAttr2["NODE_RUN_ID"] = "adk.node.run_id";
|
|
68
|
+
AdkAttr2["NODE_ATTEMPT"] = "adk.node.attempt";
|
|
69
|
+
AdkAttr2["NODE_STATUS"] = "adk.node.status";
|
|
70
|
+
AdkAttr2["NODE_INTERRUPT_COUNT"] = "adk.node.interrupt_count";
|
|
71
|
+
return AdkAttr2;
|
|
72
|
+
})(AdkAttr || {});
|
|
73
|
+
var GcpAttr = /* @__PURE__ */ ((GcpAttr2) => {
|
|
74
|
+
GcpAttr2["INVOCATION_ID"] = "gcp.vertex.agent.invocation_id";
|
|
75
|
+
GcpAttr2["SESSION_ID"] = "gcp.vertex.agent.session_id";
|
|
76
|
+
GcpAttr2["EVENT_ID"] = "gcp.vertex.agent.event_id";
|
|
77
|
+
GcpAttr2["LLM_REQUEST"] = "gcp.vertex.agent.llm_request";
|
|
78
|
+
GcpAttr2["LLM_RESPONSE"] = "gcp.vertex.agent.llm_response";
|
|
79
|
+
GcpAttr2["TOOL_CALL_ARGS"] = "gcp.vertex.agent.tool_call_args";
|
|
80
|
+
GcpAttr2["TOOL_RESPONSE"] = "gcp.vertex.agent.tool_response";
|
|
81
|
+
GcpAttr2["DATA"] = "gcp.vertex.agent.data";
|
|
82
|
+
return GcpAttr2;
|
|
83
|
+
})(GcpAttr || {});
|
|
84
|
+
const GEN_AI_SYSTEM_VALUE = "gcp.vertex.agent";
|
|
85
|
+
const tracer = import_api.trace.getTracer(GEN_AI_SYSTEM_VALUE, import_version.version);
|
|
61
86
|
function safeJsonSerialize(obj) {
|
|
62
87
|
try {
|
|
63
88
|
return JSON.stringify(obj);
|
|
@@ -73,11 +98,11 @@ function traceAgentInvocation({
|
|
|
73
98
|
const span = import_api.trace.getActiveSpan();
|
|
74
99
|
if (!span) return;
|
|
75
100
|
span.setAttributes({
|
|
76
|
-
[
|
|
101
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "invoke_agent",
|
|
77
102
|
// Conditionally Required
|
|
78
|
-
[
|
|
79
|
-
[
|
|
80
|
-
[
|
|
103
|
+
["gen_ai.agent.description" /* AGENT_DESCRIPTION */]: agent.description,
|
|
104
|
+
["gen_ai.agent.name" /* AGENT_NAME */]: agent.name,
|
|
105
|
+
["gen_ai.conversation.id" /* CONVERSATION_ID */]: invocationContext.session.id
|
|
81
106
|
});
|
|
82
107
|
}
|
|
83
108
|
__name(traceAgentInvocation, "traceAgentInvocation");
|
|
@@ -89,10 +114,10 @@ function traceWorkflowInvocation({
|
|
|
89
114
|
const span = import_api.trace.getActiveSpan();
|
|
90
115
|
if (!span) return;
|
|
91
116
|
span.setAttributes({
|
|
92
|
-
[
|
|
93
|
-
[
|
|
94
|
-
[
|
|
95
|
-
[
|
|
117
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "invoke_workflow",
|
|
118
|
+
["gen_ai.conversation.id" /* CONVERSATION_ID */]: sessionId,
|
|
119
|
+
["adk.workflow.name" /* WORKFLOW_NAME */]: workflowName,
|
|
120
|
+
["adk.node.path" /* NODE_PATH */]: nodePath
|
|
96
121
|
});
|
|
97
122
|
}
|
|
98
123
|
__name(traceWorkflowInvocation, "traceWorkflowInvocation");
|
|
@@ -106,34 +131,37 @@ function traceNodeExecution({
|
|
|
106
131
|
const span = import_api.trace.getActiveSpan();
|
|
107
132
|
if (!span) return;
|
|
108
133
|
span.setAttributes({
|
|
109
|
-
[
|
|
110
|
-
[
|
|
111
|
-
[
|
|
112
|
-
[
|
|
113
|
-
[
|
|
114
|
-
[
|
|
134
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "execute_node",
|
|
135
|
+
["adk.node.path" /* NODE_PATH */]: nodePath,
|
|
136
|
+
["adk.node.run_id" /* NODE_RUN_ID */]: runId,
|
|
137
|
+
["adk.node.attempt" /* NODE_ATTEMPT */]: attempt,
|
|
138
|
+
["adk.node.status" /* NODE_STATUS */]: status,
|
|
139
|
+
["adk.node.interrupt_count" /* NODE_INTERRUPT_COUNT */]: interruptCount
|
|
115
140
|
});
|
|
116
141
|
}
|
|
117
142
|
__name(traceNodeExecution, "traceNodeExecution");
|
|
118
143
|
function traceToolCall({
|
|
119
144
|
tool,
|
|
120
145
|
args,
|
|
121
|
-
functionResponseEvent
|
|
146
|
+
functionResponseEvent,
|
|
147
|
+
invocationContext
|
|
122
148
|
}) {
|
|
123
149
|
var _a, _b;
|
|
124
150
|
const span = import_api.trace.getActiveSpan();
|
|
125
151
|
if (!span) return;
|
|
126
152
|
span.setAttributes({
|
|
127
|
-
[
|
|
128
|
-
[
|
|
129
|
-
[
|
|
153
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "execute_tool",
|
|
154
|
+
["gen_ai.system" /* SYSTEM */]: GEN_AI_SYSTEM_VALUE,
|
|
155
|
+
["gen_ai.tool.description" /* TOOL_DESCRIPTION */]: tool.description || "",
|
|
156
|
+
["gen_ai.tool.name" /* TOOL_NAME */]: tool.name,
|
|
130
157
|
// e.g. FunctionTool
|
|
131
|
-
[
|
|
158
|
+
["gen_ai.tool.type" /* TOOL_TYPE */]: tool.constructor.name,
|
|
159
|
+
["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
|
|
132
160
|
// Setting empty llm request and response (as UI expect these) while not
|
|
133
161
|
// applicable for tool_response.
|
|
134
|
-
"gcp.vertex.agent.llm_request": "{}",
|
|
135
|
-
"gcp.vertex.agent.llm_response": "{}",
|
|
136
|
-
"gcp.vertex.agent.tool_call_args": shouldAddRequestResponseToSpans() ? safeJsonSerialize(args) : "{}"
|
|
162
|
+
["gcp.vertex.agent.llm_request" /* LLM_REQUEST */]: "{}",
|
|
163
|
+
["gcp.vertex.agent.llm_response" /* LLM_RESPONSE */]: "{}",
|
|
164
|
+
["gcp.vertex.agent.tool_call_args" /* TOOL_CALL_ARGS */]: shouldAddRequestResponseToSpans() ? safeJsonSerialize(args) : "{}"
|
|
137
165
|
});
|
|
138
166
|
let toolCallId = "<not specified>";
|
|
139
167
|
let toolResponse = "<not specified>";
|
|
@@ -151,32 +179,35 @@ function traceToolCall({
|
|
|
151
179
|
toolResponse = { result: toolResponse };
|
|
152
180
|
}
|
|
153
181
|
span.setAttributes({
|
|
154
|
-
[
|
|
155
|
-
"gcp.vertex.agent.event_id": functionResponseEvent.id,
|
|
156
|
-
"gcp.vertex.agent.tool_response": shouldAddRequestResponseToSpans() ? safeJsonSerialize(toolResponse) : "{}"
|
|
182
|
+
["gen_ai.tool.call.id" /* TOOL_CALL_ID */]: toolCallId,
|
|
183
|
+
["gcp.vertex.agent.event_id" /* EVENT_ID */]: functionResponseEvent.id,
|
|
184
|
+
["gcp.vertex.agent.tool_response" /* TOOL_RESPONSE */]: shouldAddRequestResponseToSpans() ? safeJsonSerialize(toolResponse) : "{}"
|
|
157
185
|
});
|
|
158
186
|
}
|
|
159
187
|
__name(traceToolCall, "traceToolCall");
|
|
160
188
|
function traceMergedToolCalls({
|
|
161
189
|
responseEventId,
|
|
162
|
-
functionResponseEvent
|
|
190
|
+
functionResponseEvent,
|
|
191
|
+
invocationContext
|
|
163
192
|
}) {
|
|
164
193
|
const span = import_api.trace.getActiveSpan();
|
|
165
194
|
if (!span) return;
|
|
166
195
|
span.setAttributes({
|
|
167
|
-
[
|
|
168
|
-
[
|
|
169
|
-
[
|
|
170
|
-
[
|
|
171
|
-
"
|
|
172
|
-
"gcp.vertex.agent.
|
|
196
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "execute_tool",
|
|
197
|
+
["gen_ai.system" /* SYSTEM */]: GEN_AI_SYSTEM_VALUE,
|
|
198
|
+
["gen_ai.tool.name" /* TOOL_NAME */]: "(merged tools)",
|
|
199
|
+
["gen_ai.tool.description" /* TOOL_DESCRIPTION */]: "(merged tools)",
|
|
200
|
+
["gen_ai.tool.call.id" /* TOOL_CALL_ID */]: responseEventId,
|
|
201
|
+
["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
|
|
202
|
+
["gcp.vertex.agent.tool_call_args" /* TOOL_CALL_ARGS */]: "N/A",
|
|
203
|
+
["gcp.vertex.agent.event_id" /* EVENT_ID */]: responseEventId,
|
|
173
204
|
// Setting empty llm request and response (as UI expect these) while not
|
|
174
205
|
// applicable for tool_response.
|
|
175
|
-
"gcp.vertex.agent.llm_request": "{}",
|
|
176
|
-
"gcp.vertex.agent.llm_response": "{}"
|
|
206
|
+
["gcp.vertex.agent.llm_request" /* LLM_REQUEST */]: "{}",
|
|
207
|
+
["gcp.vertex.agent.llm_response" /* LLM_RESPONSE */]: "{}"
|
|
177
208
|
});
|
|
178
209
|
span.setAttribute(
|
|
179
|
-
"gcp.vertex.agent.tool_response"
|
|
210
|
+
"gcp.vertex.agent.tool_response" /* TOOL_RESPONSE */,
|
|
180
211
|
shouldAddRequestResponseToSpans() ? safeJsonSerialize(functionResponseEvent) : "{}"
|
|
181
212
|
);
|
|
182
213
|
}
|
|
@@ -191,43 +222,43 @@ function traceCallLlm({
|
|
|
191
222
|
const span = import_api.trace.getActiveSpan();
|
|
192
223
|
if (!span) return;
|
|
193
224
|
span.setAttributes({
|
|
194
|
-
"gen_ai.system":
|
|
195
|
-
"gen_ai.request.model": llmRequest.model,
|
|
196
|
-
...((_a = invocationContext.agent) == null ? void 0 : _a.name) ? { [
|
|
197
|
-
"gcp.vertex.agent.invocation_id": invocationContext.invocationId,
|
|
198
|
-
"gcp.vertex.agent.session_id": invocationContext.session.id,
|
|
199
|
-
"gcp.vertex.agent.event_id": eventId,
|
|
225
|
+
["gen_ai.system" /* SYSTEM */]: GEN_AI_SYSTEM_VALUE,
|
|
226
|
+
["gen_ai.request.model" /* REQUEST_MODEL */]: llmRequest.model,
|
|
227
|
+
...((_a = invocationContext.agent) == null ? void 0 : _a.name) ? { ["gen_ai.agent.name" /* AGENT_NAME */]: invocationContext.agent.name } : {},
|
|
228
|
+
["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
|
|
229
|
+
["gcp.vertex.agent.session_id" /* SESSION_ID */]: invocationContext.session.id,
|
|
230
|
+
["gcp.vertex.agent.event_id" /* EVENT_ID */]: eventId,
|
|
200
231
|
// Consider removing once GenAI SDK provides a way to record this info.
|
|
201
|
-
"gcp.vertex.agent.llm_request": shouldAddRequestResponseToSpans() ? safeJsonSerialize(buildLlmRequestForTrace(llmRequest)) : "{}"
|
|
232
|
+
["gcp.vertex.agent.llm_request" /* LLM_REQUEST */]: shouldAddRequestResponseToSpans() ? safeJsonSerialize(buildLlmRequestForTrace(llmRequest)) : "{}"
|
|
202
233
|
});
|
|
203
234
|
if ((_b = llmRequest.config) == null ? void 0 : _b.topP) {
|
|
204
|
-
span.setAttribute("gen_ai.request.top_p"
|
|
235
|
+
span.setAttribute("gen_ai.request.top_p" /* REQUEST_TOP_P */, llmRequest.config.topP);
|
|
205
236
|
}
|
|
206
237
|
if (((_c = llmRequest.config) == null ? void 0 : _c.maxOutputTokens) !== void 0) {
|
|
207
238
|
span.setAttribute(
|
|
208
|
-
"gen_ai.request.max_tokens"
|
|
239
|
+
"gen_ai.request.max_tokens" /* REQUEST_MAX_TOKENS */,
|
|
209
240
|
llmRequest.config.maxOutputTokens
|
|
210
241
|
);
|
|
211
242
|
}
|
|
212
243
|
span.setAttribute(
|
|
213
|
-
"gcp.vertex.agent.llm_response"
|
|
244
|
+
"gcp.vertex.agent.llm_response" /* LLM_RESPONSE */,
|
|
214
245
|
shouldAddRequestResponseToSpans() ? safeJsonSerialize(llmResponse) : "{}"
|
|
215
246
|
);
|
|
216
247
|
if (llmResponse.usageMetadata) {
|
|
217
248
|
span.setAttribute(
|
|
218
|
-
"gen_ai.usage.input_tokens"
|
|
249
|
+
"gen_ai.usage.input_tokens" /* USAGE_INPUT_TOKENS */,
|
|
219
250
|
llmResponse.usageMetadata.promptTokenCount || 0
|
|
220
251
|
);
|
|
221
252
|
}
|
|
222
253
|
if ((_d = llmResponse.usageMetadata) == null ? void 0 : _d.candidatesTokenCount) {
|
|
223
254
|
span.setAttribute(
|
|
224
|
-
"gen_ai.usage.output_tokens"
|
|
255
|
+
"gen_ai.usage.output_tokens" /* USAGE_OUTPUT_TOKENS */,
|
|
225
256
|
llmResponse.usageMetadata.candidatesTokenCount
|
|
226
257
|
);
|
|
227
258
|
}
|
|
228
259
|
if (llmResponse.finishReason) {
|
|
229
260
|
const finishReasonValue = typeof llmResponse.finishReason === "string" ? llmResponse.finishReason.toLowerCase() : String(llmResponse.finishReason).toLowerCase();
|
|
230
|
-
span.setAttribute("gen_ai.response.finish_reasons"
|
|
261
|
+
span.setAttribute("gen_ai.response.finish_reasons" /* RESPONSE_FINISH_REASONS */, [finishReasonValue]);
|
|
231
262
|
}
|
|
232
263
|
}
|
|
233
264
|
__name(traceCallLlm, "traceCallLlm");
|
|
@@ -239,11 +270,11 @@ function traceSendData({
|
|
|
239
270
|
const span = import_api.trace.getActiveSpan();
|
|
240
271
|
if (!span) return;
|
|
241
272
|
span.setAttributes({
|
|
242
|
-
"gcp.vertex.agent.invocation_id": invocationContext.invocationId,
|
|
243
|
-
"gcp.vertex.agent.event_id": eventId
|
|
273
|
+
["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
|
|
274
|
+
["gcp.vertex.agent.event_id" /* EVENT_ID */]: eventId
|
|
244
275
|
});
|
|
245
276
|
span.setAttribute(
|
|
246
|
-
"gcp.vertex.agent.data"
|
|
277
|
+
"gcp.vertex.agent.data" /* DATA */,
|
|
247
278
|
shouldAddRequestResponseToSpans() ? safeJsonSerialize(data) : "{}"
|
|
248
279
|
);
|
|
249
280
|
}
|