@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
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
BuiltInCodeExecutor,
|
|
32
32
|
isBuiltInCodeExecutor
|
|
33
33
|
} from "../code_executors/built_in_code_executor.js";
|
|
34
|
+
import { buildAbortEvents, isAbortEvent } from "../events/abort_events.js";
|
|
34
35
|
import { createEvent } from "../events/event.js";
|
|
35
36
|
import { createEventActions } from "../events/event_actions.js";
|
|
36
37
|
import {
|
|
@@ -64,8 +65,8 @@ const _Runner = class _Runner {
|
|
|
64
65
|
*/
|
|
65
66
|
constructor(input) {
|
|
66
67
|
this[_a] = true;
|
|
67
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
68
|
-
const appName = (_b = (_a2 = input.app) == null ? void 0 : _a2.name
|
|
68
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
69
|
+
const appName = (_b = input.appName) != null ? _b : (_a2 = input.app) == null ? void 0 : _a2.name;
|
|
69
70
|
const agent = (_d = (_c = input.app) == null ? void 0 : _c.rootAgent) != null ? _d : input.agent;
|
|
70
71
|
if (!agent) {
|
|
71
72
|
throw new Error(
|
|
@@ -82,6 +83,20 @@ const _Runner = class _Runner {
|
|
|
82
83
|
this.memoryService = input.memoryService;
|
|
83
84
|
this.credentialService = input.credentialService;
|
|
84
85
|
this.resumabilityConfig = (_i = (_h = input.app) == null ? void 0 : _h.resumabilityConfig) != null ? _i : input.resumabilityConfig;
|
|
86
|
+
this.autoCreateSession = (_j = input.autoCreateSession) != null ? _j : false;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Looks the session up, creating it first when `autoCreateSession` is set.
|
|
90
|
+
*
|
|
91
|
+
* A runner with no `appName` cannot address a session, so it falls through to
|
|
92
|
+
* the plain lookup rather than creating one under an undefined app name.
|
|
93
|
+
*/
|
|
94
|
+
async resolveSession(userId, sessionId) {
|
|
95
|
+
const key = { appName: this.appName, userId, sessionId };
|
|
96
|
+
if (this.autoCreateSession && this.appName) {
|
|
97
|
+
return this.sessionService.getOrCreateSession(key);
|
|
98
|
+
}
|
|
99
|
+
return this.sessionService.getSession(key);
|
|
85
100
|
}
|
|
86
101
|
/**
|
|
87
102
|
* Runs the agent with a new, ephemeral session.
|
|
@@ -142,12 +157,8 @@ const _Runner = class _Runner {
|
|
|
142
157
|
ctx,
|
|
143
158
|
this,
|
|
144
159
|
async function* () {
|
|
145
|
-
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
146
|
-
const session = await this.
|
|
147
|
-
appName: this.appName,
|
|
148
|
-
userId,
|
|
149
|
-
sessionId
|
|
150
|
-
});
|
|
160
|
+
var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
161
|
+
const session = await this.resolveSession(userId, sessionId);
|
|
151
162
|
if ((_a2 = params.abortSignal) == null ? void 0 : _a2.aborted) {
|
|
152
163
|
return;
|
|
153
164
|
}
|
|
@@ -258,35 +269,45 @@ const _Runner = class _Runner {
|
|
|
258
269
|
}
|
|
259
270
|
yield earlyExitEvent;
|
|
260
271
|
} else {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
session,
|
|
280
|
-
event: outputEvent
|
|
281
|
-
});
|
|
272
|
+
let abortSealed = false;
|
|
273
|
+
const sealAbortedInvocation = /* @__PURE__ */ __name(() => {
|
|
274
|
+
abortSealed = true;
|
|
275
|
+
return this.synthesizeAbortEvents(invocationContext);
|
|
276
|
+
}, "sealAbortedInvocation");
|
|
277
|
+
try {
|
|
278
|
+
for await (const event of this.runRoot(invocationContext)) {
|
|
279
|
+
if ((_h = params.abortSignal) == null ? void 0 : _h.aborted) {
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
const outputEvent = await this.processAndAppendEvent(
|
|
283
|
+
invocationContext,
|
|
284
|
+
event
|
|
285
|
+
);
|
|
286
|
+
if ((_i = params.abortSignal) == null ? void 0 : _i.aborted) {
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
yield outputEvent;
|
|
282
290
|
}
|
|
283
291
|
if ((_j = params.abortSignal) == null ? void 0 : _j.aborted) {
|
|
292
|
+
for (const abortEvent of await sealAbortedInvocation()) {
|
|
293
|
+
yield abortEvent;
|
|
294
|
+
}
|
|
284
295
|
return;
|
|
285
296
|
}
|
|
286
|
-
|
|
297
|
+
} finally {
|
|
298
|
+
if (((_k = params.abortSignal) == null ? void 0 : _k.aborted) && !abortSealed) {
|
|
299
|
+
try {
|
|
300
|
+
await sealAbortedInvocation();
|
|
301
|
+
} catch (e) {
|
|
302
|
+
logger.error(
|
|
303
|
+
`Failed to seal aborted invocation ${invocationContext.invocationId}.`,
|
|
304
|
+
e
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
287
308
|
}
|
|
288
309
|
await this.pluginManager.runAfterRunCallback({ invocationContext });
|
|
289
|
-
if ((
|
|
310
|
+
if ((_l = params.abortSignal) == null ? void 0 : _l.aborted) {
|
|
290
311
|
return;
|
|
291
312
|
}
|
|
292
313
|
}
|
|
@@ -318,6 +339,56 @@ const _Runner = class _Runner {
|
|
|
318
339
|
}
|
|
319
340
|
yield* runNodeAsInvocation(this.agent, invocationContext);
|
|
320
341
|
}
|
|
342
|
+
/**
|
|
343
|
+
* Runs the on_event plugin callbacks on an event and appends the result to
|
|
344
|
+
* the session unless it is partial.
|
|
345
|
+
*
|
|
346
|
+
* @returns The event as streamed to the caller.
|
|
347
|
+
*/
|
|
348
|
+
async processAndAppendEvent(invocationContext, event) {
|
|
349
|
+
var _a2;
|
|
350
|
+
const modifiedEvent = await this.pluginManager.runOnEventCallback({
|
|
351
|
+
invocationContext,
|
|
352
|
+
event
|
|
353
|
+
});
|
|
354
|
+
const outputEvent = modifiedEvent ? {
|
|
355
|
+
...withInternalMetadataOf(event, modifiedEvent),
|
|
356
|
+
id: event.id,
|
|
357
|
+
invocationId: event.invocationId,
|
|
358
|
+
timestamp: event.timestamp,
|
|
359
|
+
author: modifiedEvent.author || event.author,
|
|
360
|
+
branch: (_a2 = modifiedEvent.branch) != null ? _a2 : event.branch
|
|
361
|
+
} : event;
|
|
362
|
+
if (!event.partial) {
|
|
363
|
+
await this.sessionService.appendEvent({
|
|
364
|
+
session: invocationContext.session,
|
|
365
|
+
event: outputEvent
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
return outputEvent;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Seals an aborted invocation in session history: answers its dangling
|
|
372
|
+
* function calls with error responses, or records a plain abort event when
|
|
373
|
+
* there is nothing to answer.
|
|
374
|
+
*
|
|
375
|
+
* @returns The synthetic events after plugin processing and persistence.
|
|
376
|
+
*/
|
|
377
|
+
async synthesizeAbortEvents(invocationContext) {
|
|
378
|
+
const abortEvents = buildAbortEvents({
|
|
379
|
+
events: invocationContext.session.events,
|
|
380
|
+
invocationId: invocationContext.invocationId,
|
|
381
|
+
rootAgentName: this.agent.name,
|
|
382
|
+
branch: invocationContext.branch
|
|
383
|
+
});
|
|
384
|
+
const outputEvents = [];
|
|
385
|
+
for (const event of abortEvents) {
|
|
386
|
+
outputEvents.push(
|
|
387
|
+
await this.processAndAppendEvent(invocationContext, event)
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
return outputEvents;
|
|
391
|
+
}
|
|
321
392
|
/**
|
|
322
393
|
* Saves artifacts from the message parts and replaces the inline data with
|
|
323
394
|
* a file name placeholder and optional file reference.
|
|
@@ -564,7 +635,8 @@ function isLiveModelMediaEventWithInlineData(event) {
|
|
|
564
635
|
}
|
|
565
636
|
__name(isLiveModelMediaEventWithInlineData, "isLiveModelMediaEventWithInlineData");
|
|
566
637
|
function determineAgentForResumption(session, rootAgent, resumabilityConfig) {
|
|
567
|
-
const
|
|
638
|
+
const lastEvent = session.events[session.events.length - 1];
|
|
639
|
+
const event = lastEvent && !isAbortEvent(lastEvent) ? findEventByLastFunctionResponseId(session.events) : null;
|
|
568
640
|
const isResumable = Boolean(resumabilityConfig == null ? void 0 : resumabilityConfig.isResumable);
|
|
569
641
|
if (event && event.author && isResumable) {
|
|
570
642
|
const conflictingAuthors = getConflictingFunctionResponseAuthors(
|
|
@@ -588,7 +660,7 @@ function determineAgentForResumption(session, rootAgent, resumabilityConfig) {
|
|
|
588
660
|
for (let i = session.events.length - 1; i >= 0; i--) {
|
|
589
661
|
logger.debug("event:", stringifyWithRedactedInlineData(session.events[i]));
|
|
590
662
|
const event2 = session.events[i];
|
|
591
|
-
if (event2.author === "user" || !event2.author) {
|
|
663
|
+
if (event2.author === "user" || !event2.author || isAbortEvent(event2)) {
|
|
592
664
|
continue;
|
|
593
665
|
}
|
|
594
666
|
if (event2.author === rootAgent.name) {
|
|
@@ -281,7 +281,7 @@ async function getConnectionOptionsFromUri(uri) {
|
|
|
281
281
|
);
|
|
282
282
|
return {
|
|
283
283
|
entities: ENTITIES,
|
|
284
|
-
dbName: uri === "sqlite://:memory:" ? ":memory:" : uri.substring("sqlite://".length),
|
|
284
|
+
dbName: uri === "sqlite://:memory:" || uri === "sqlite:///:memory:" ? ":memory:" : uri.substring("sqlite://".length),
|
|
285
285
|
driver: SqliteDriver
|
|
286
286
|
};
|
|
287
287
|
}
|
|
@@ -47,7 +47,9 @@ const _InMemorySessionService = class _InMemorySessionService extends BaseSessio
|
|
|
47
47
|
var _a;
|
|
48
48
|
const filteredState = state ? trimTempState(state) : void 0;
|
|
49
49
|
const session = createSession({
|
|
50
|
-
|
|
50
|
+
// Surrounding whitespace is dropped so that a later lookup by the bare
|
|
51
|
+
// id finds the session, and a blank id gets a generated one.
|
|
52
|
+
id: (sessionId == null ? void 0 : sessionId.trim()) || randomUUID(),
|
|
51
53
|
appName,
|
|
52
54
|
userId,
|
|
53
55
|
state: filteredState,
|
|
@@ -74,16 +74,19 @@ const _State = class _State {
|
|
|
74
74
|
/**
|
|
75
75
|
* Returns the value of the state dict for the given key.
|
|
76
76
|
*
|
|
77
|
+
* Only keys the state holds itself are found. Names inherited from
|
|
78
|
+
* `Object.prototype`, such as `toString`, are treated as missing.
|
|
79
|
+
*
|
|
77
80
|
* @param key The key to get the value for.
|
|
78
81
|
* @param defaultValue The default value to return if the key is not found.
|
|
79
82
|
* @return The value of the state for the given key, or the default value if
|
|
80
83
|
* not found.
|
|
81
84
|
*/
|
|
82
85
|
get(key, defaultValue) {
|
|
83
|
-
if (
|
|
86
|
+
if (Object.hasOwn(this.delta, key)) {
|
|
84
87
|
return this.delta[key];
|
|
85
88
|
}
|
|
86
|
-
if (
|
|
89
|
+
if (Object.hasOwn(this.value, key)) {
|
|
87
90
|
return this.value[key];
|
|
88
91
|
}
|
|
89
92
|
return defaultValue;
|
|
@@ -101,10 +104,11 @@ const _State = class _State {
|
|
|
101
104
|
recordStateWrite(this.value, this.delta, key);
|
|
102
105
|
}
|
|
103
106
|
/**
|
|
104
|
-
* Whether the state
|
|
107
|
+
* Whether the state holds the given key, either as a stored value or as a
|
|
108
|
+
* pending delta. Names inherited from `Object.prototype` are not keys.
|
|
105
109
|
*/
|
|
106
110
|
has(key) {
|
|
107
|
-
return
|
|
111
|
+
return Object.hasOwn(this.value, key) || Object.hasOwn(this.delta, key);
|
|
108
112
|
}
|
|
109
113
|
/**
|
|
110
114
|
* Whether the state has pending delta.
|
|
@@ -44,17 +44,22 @@ function quoteFilterLiteral(value) {
|
|
|
44
44
|
return `"${escaped}"`;
|
|
45
45
|
}
|
|
46
46
|
__name(quoteFilterLiteral, "quoteFilterLiteral");
|
|
47
|
+
function toStateMap(state) {
|
|
48
|
+
return Object.assign(/* @__PURE__ */ Object.create(null), state);
|
|
49
|
+
}
|
|
50
|
+
__name(toStateMap, "toStateMap");
|
|
47
51
|
let VertexAiSessionService = class extends BaseSessionService {
|
|
48
52
|
constructor(options) {
|
|
49
53
|
super();
|
|
50
54
|
this.agentEngineId = options.agentEngineId;
|
|
51
|
-
this.projectId = options.projectId;
|
|
52
|
-
this.location = options.location;
|
|
53
55
|
this.expressModeApiKey = getExpressModeApiKey(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
options.projectId,
|
|
57
|
+
options.location,
|
|
56
58
|
options.expressModeApiKey
|
|
57
59
|
);
|
|
60
|
+
const useEnvironment = !options.expressModeApiKey;
|
|
61
|
+
this.projectId = options.projectId || (useEnvironment ? process.env["GOOGLE_CLOUD_PROJECT"] : void 0);
|
|
62
|
+
this.location = options.location || (useEnvironment ? process.env["GOOGLE_CLOUD_LOCATION"] : void 0);
|
|
58
63
|
if (options.sessions) {
|
|
59
64
|
this.sessions = options.sessions;
|
|
60
65
|
} else {
|
|
@@ -140,7 +145,7 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
140
145
|
id,
|
|
141
146
|
appName,
|
|
142
147
|
userId,
|
|
143
|
-
state: getSessionResponse.sessionState,
|
|
148
|
+
state: toStateMap(getSessionResponse.sessionState),
|
|
144
149
|
events: [],
|
|
145
150
|
lastUpdateTime: getSessionResponse.updateTime ? Date.parse(getSessionResponse.updateTime) : Date.now()
|
|
146
151
|
});
|
|
@@ -155,13 +160,14 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
155
160
|
const sessionResourceName = `reasoningEngines/${reasoningEngineId}/sessions/${sessionId}`;
|
|
156
161
|
try {
|
|
157
162
|
let getSessionResponse;
|
|
158
|
-
|
|
163
|
+
const eventsIterator = [];
|
|
164
|
+
const listConfig = {};
|
|
165
|
+
let pageToken;
|
|
159
166
|
if (config && config.numRecentEvents === 0) {
|
|
160
167
|
getSessionResponse = await this.sessions.get({
|
|
161
168
|
name: sessionResourceName
|
|
162
169
|
});
|
|
163
170
|
} else {
|
|
164
|
-
const listConfig = {};
|
|
165
171
|
if (config && config.afterTimestamp) {
|
|
166
172
|
listConfig.filter = `timestamp>="${new Date(
|
|
167
173
|
config.afterTimestamp
|
|
@@ -175,7 +181,9 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
175
181
|
})
|
|
176
182
|
]);
|
|
177
183
|
getSessionResponse = sessionRes;
|
|
178
|
-
|
|
184
|
+
const firstPage = eventsRes;
|
|
185
|
+
eventsIterator.push(...firstPage.sessionEvents || []);
|
|
186
|
+
pageToken = firstPage.nextPageToken;
|
|
179
187
|
}
|
|
180
188
|
const sessionObj = getSessionResponse;
|
|
181
189
|
if (sessionObj.userId !== userId) {
|
|
@@ -183,20 +191,29 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
183
191
|
`Session ${sessionId} does not belong to user ${userId}.`
|
|
184
192
|
);
|
|
185
193
|
}
|
|
194
|
+
while (pageToken) {
|
|
195
|
+
const eventsRes = await this.sessions.events.listInternal({
|
|
196
|
+
name: sessionResourceName,
|
|
197
|
+
config: {
|
|
198
|
+
...listConfig,
|
|
199
|
+
pageToken
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
eventsIterator.push(...eventsRes.sessionEvents || []);
|
|
203
|
+
pageToken = eventsRes.nextPageToken;
|
|
204
|
+
}
|
|
186
205
|
const session = createSession({
|
|
187
206
|
id: sessionId,
|
|
188
207
|
appName,
|
|
189
208
|
userId,
|
|
190
|
-
state: sessionObj.sessionState,
|
|
209
|
+
state: toStateMap(sessionObj.sessionState),
|
|
191
210
|
events: [],
|
|
192
211
|
lastUpdateTime: sessionObj.updateTime ? Date.parse(sessionObj.updateTime) : Date.now()
|
|
193
212
|
});
|
|
194
|
-
|
|
213
|
+
const recentEvents = config && config.numRecentEvents ? eventsIterator.slice(-config.numRecentEvents) : eventsIterator;
|
|
214
|
+
for (const event of recentEvents) {
|
|
195
215
|
session.events.push(_fromApiEvent(event));
|
|
196
216
|
}
|
|
197
|
-
if (config && config.numRecentEvents) {
|
|
198
|
-
session.events = session.events.slice(-config.numRecentEvents);
|
|
199
|
-
}
|
|
200
217
|
return session;
|
|
201
218
|
} catch (error) {
|
|
202
219
|
const err = error;
|
|
@@ -235,7 +252,7 @@ let VertexAiSessionService = class extends BaseSessionService {
|
|
|
235
252
|
id,
|
|
236
253
|
appName,
|
|
237
254
|
userId: sessionObj.userId,
|
|
238
|
-
state: sessionObj.sessionState,
|
|
255
|
+
state: toStateMap(sessionObj.sessionState),
|
|
239
256
|
events: [],
|
|
240
257
|
lastUpdateTime: sessionObj.updateTime ? new Date(sessionObj.updateTime).getTime() : Date.now()
|
|
241
258
|
})
|
|
@@ -481,7 +498,9 @@ function _fromApiEvent(apiEventObj) {
|
|
|
481
498
|
}
|
|
482
499
|
}
|
|
483
500
|
const eventActions = {
|
|
484
|
-
stateDelta:
|
|
501
|
+
stateDelta: toStateMap(
|
|
502
|
+
actions["stateDelta"]
|
|
503
|
+
),
|
|
485
504
|
artifactDelta: actions["artifactDelta"] || {},
|
|
486
505
|
requestedAuthConfigs: actions.requestedAuthConfigs || {},
|
|
487
506
|
requestedToolConfirmations: actions["requestedToolConfirmations"] || {},
|
|
@@ -9,21 +9,46 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
9
9
|
*/
|
|
10
10
|
import { context, trace } from "@opentelemetry/api";
|
|
11
11
|
import { version } from "../version.js";
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
var GenAiAttr = /* @__PURE__ */ ((GenAiAttr2) => {
|
|
13
|
+
GenAiAttr2["AGENT_DESCRIPTION"] = "gen_ai.agent.description";
|
|
14
|
+
GenAiAttr2["AGENT_NAME"] = "gen_ai.agent.name";
|
|
15
|
+
GenAiAttr2["CONVERSATION_ID"] = "gen_ai.conversation.id";
|
|
16
|
+
GenAiAttr2["OPERATION_NAME"] = "gen_ai.operation.name";
|
|
17
|
+
GenAiAttr2["SYSTEM"] = "gen_ai.system";
|
|
18
|
+
GenAiAttr2["TOOL_CALL_ID"] = "gen_ai.tool.call.id";
|
|
19
|
+
GenAiAttr2["TOOL_DESCRIPTION"] = "gen_ai.tool.description";
|
|
20
|
+
GenAiAttr2["TOOL_NAME"] = "gen_ai.tool.name";
|
|
21
|
+
GenAiAttr2["TOOL_TYPE"] = "gen_ai.tool.type";
|
|
22
|
+
GenAiAttr2["REQUEST_MODEL"] = "gen_ai.request.model";
|
|
23
|
+
GenAiAttr2["REQUEST_TOP_P"] = "gen_ai.request.top_p";
|
|
24
|
+
GenAiAttr2["REQUEST_MAX_TOKENS"] = "gen_ai.request.max_tokens";
|
|
25
|
+
GenAiAttr2["USAGE_INPUT_TOKENS"] = "gen_ai.usage.input_tokens";
|
|
26
|
+
GenAiAttr2["USAGE_OUTPUT_TOKENS"] = "gen_ai.usage.output_tokens";
|
|
27
|
+
GenAiAttr2["RESPONSE_FINISH_REASONS"] = "gen_ai.response.finish_reasons";
|
|
28
|
+
return GenAiAttr2;
|
|
29
|
+
})(GenAiAttr || {});
|
|
30
|
+
var AdkAttr = /* @__PURE__ */ ((AdkAttr2) => {
|
|
31
|
+
AdkAttr2["WORKFLOW_NAME"] = "adk.workflow.name";
|
|
32
|
+
AdkAttr2["NODE_PATH"] = "adk.node.path";
|
|
33
|
+
AdkAttr2["NODE_RUN_ID"] = "adk.node.run_id";
|
|
34
|
+
AdkAttr2["NODE_ATTEMPT"] = "adk.node.attempt";
|
|
35
|
+
AdkAttr2["NODE_STATUS"] = "adk.node.status";
|
|
36
|
+
AdkAttr2["NODE_INTERRUPT_COUNT"] = "adk.node.interrupt_count";
|
|
37
|
+
return AdkAttr2;
|
|
38
|
+
})(AdkAttr || {});
|
|
39
|
+
var GcpAttr = /* @__PURE__ */ ((GcpAttr2) => {
|
|
40
|
+
GcpAttr2["INVOCATION_ID"] = "gcp.vertex.agent.invocation_id";
|
|
41
|
+
GcpAttr2["SESSION_ID"] = "gcp.vertex.agent.session_id";
|
|
42
|
+
GcpAttr2["EVENT_ID"] = "gcp.vertex.agent.event_id";
|
|
43
|
+
GcpAttr2["LLM_REQUEST"] = "gcp.vertex.agent.llm_request";
|
|
44
|
+
GcpAttr2["LLM_RESPONSE"] = "gcp.vertex.agent.llm_response";
|
|
45
|
+
GcpAttr2["TOOL_CALL_ARGS"] = "gcp.vertex.agent.tool_call_args";
|
|
46
|
+
GcpAttr2["TOOL_RESPONSE"] = "gcp.vertex.agent.tool_response";
|
|
47
|
+
GcpAttr2["DATA"] = "gcp.vertex.agent.data";
|
|
48
|
+
return GcpAttr2;
|
|
49
|
+
})(GcpAttr || {});
|
|
50
|
+
const GEN_AI_SYSTEM_VALUE = "gcp.vertex.agent";
|
|
51
|
+
const tracer = trace.getTracer(GEN_AI_SYSTEM_VALUE, version);
|
|
27
52
|
function safeJsonSerialize(obj) {
|
|
28
53
|
try {
|
|
29
54
|
return JSON.stringify(obj);
|
|
@@ -39,11 +64,11 @@ function traceAgentInvocation({
|
|
|
39
64
|
const span = trace.getActiveSpan();
|
|
40
65
|
if (!span) return;
|
|
41
66
|
span.setAttributes({
|
|
42
|
-
[
|
|
67
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "invoke_agent",
|
|
43
68
|
// Conditionally Required
|
|
44
|
-
[
|
|
45
|
-
[
|
|
46
|
-
[
|
|
69
|
+
["gen_ai.agent.description" /* AGENT_DESCRIPTION */]: agent.description,
|
|
70
|
+
["gen_ai.agent.name" /* AGENT_NAME */]: agent.name,
|
|
71
|
+
["gen_ai.conversation.id" /* CONVERSATION_ID */]: invocationContext.session.id
|
|
47
72
|
});
|
|
48
73
|
}
|
|
49
74
|
__name(traceAgentInvocation, "traceAgentInvocation");
|
|
@@ -55,10 +80,10 @@ function traceWorkflowInvocation({
|
|
|
55
80
|
const span = trace.getActiveSpan();
|
|
56
81
|
if (!span) return;
|
|
57
82
|
span.setAttributes({
|
|
58
|
-
[
|
|
59
|
-
[
|
|
60
|
-
[
|
|
61
|
-
[
|
|
83
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "invoke_workflow",
|
|
84
|
+
["gen_ai.conversation.id" /* CONVERSATION_ID */]: sessionId,
|
|
85
|
+
["adk.workflow.name" /* WORKFLOW_NAME */]: workflowName,
|
|
86
|
+
["adk.node.path" /* NODE_PATH */]: nodePath
|
|
62
87
|
});
|
|
63
88
|
}
|
|
64
89
|
__name(traceWorkflowInvocation, "traceWorkflowInvocation");
|
|
@@ -72,34 +97,37 @@ function traceNodeExecution({
|
|
|
72
97
|
const span = trace.getActiveSpan();
|
|
73
98
|
if (!span) return;
|
|
74
99
|
span.setAttributes({
|
|
75
|
-
[
|
|
76
|
-
[
|
|
77
|
-
[
|
|
78
|
-
[
|
|
79
|
-
[
|
|
80
|
-
[
|
|
100
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "execute_node",
|
|
101
|
+
["adk.node.path" /* NODE_PATH */]: nodePath,
|
|
102
|
+
["adk.node.run_id" /* NODE_RUN_ID */]: runId,
|
|
103
|
+
["adk.node.attempt" /* NODE_ATTEMPT */]: attempt,
|
|
104
|
+
["adk.node.status" /* NODE_STATUS */]: status,
|
|
105
|
+
["adk.node.interrupt_count" /* NODE_INTERRUPT_COUNT */]: interruptCount
|
|
81
106
|
});
|
|
82
107
|
}
|
|
83
108
|
__name(traceNodeExecution, "traceNodeExecution");
|
|
84
109
|
function traceToolCall({
|
|
85
110
|
tool,
|
|
86
111
|
args,
|
|
87
|
-
functionResponseEvent
|
|
112
|
+
functionResponseEvent,
|
|
113
|
+
invocationContext
|
|
88
114
|
}) {
|
|
89
115
|
var _a, _b;
|
|
90
116
|
const span = trace.getActiveSpan();
|
|
91
117
|
if (!span) return;
|
|
92
118
|
span.setAttributes({
|
|
93
|
-
[
|
|
94
|
-
[
|
|
95
|
-
[
|
|
119
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "execute_tool",
|
|
120
|
+
["gen_ai.system" /* SYSTEM */]: GEN_AI_SYSTEM_VALUE,
|
|
121
|
+
["gen_ai.tool.description" /* TOOL_DESCRIPTION */]: tool.description || "",
|
|
122
|
+
["gen_ai.tool.name" /* TOOL_NAME */]: tool.name,
|
|
96
123
|
// e.g. FunctionTool
|
|
97
|
-
[
|
|
124
|
+
["gen_ai.tool.type" /* TOOL_TYPE */]: tool.constructor.name,
|
|
125
|
+
["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
|
|
98
126
|
// Setting empty llm request and response (as UI expect these) while not
|
|
99
127
|
// applicable for tool_response.
|
|
100
|
-
"gcp.vertex.agent.llm_request": "{}",
|
|
101
|
-
"gcp.vertex.agent.llm_response": "{}",
|
|
102
|
-
"gcp.vertex.agent.tool_call_args": shouldAddRequestResponseToSpans() ? safeJsonSerialize(args) : "{}"
|
|
128
|
+
["gcp.vertex.agent.llm_request" /* LLM_REQUEST */]: "{}",
|
|
129
|
+
["gcp.vertex.agent.llm_response" /* LLM_RESPONSE */]: "{}",
|
|
130
|
+
["gcp.vertex.agent.tool_call_args" /* TOOL_CALL_ARGS */]: shouldAddRequestResponseToSpans() ? safeJsonSerialize(args) : "{}"
|
|
103
131
|
});
|
|
104
132
|
let toolCallId = "<not specified>";
|
|
105
133
|
let toolResponse = "<not specified>";
|
|
@@ -117,32 +145,35 @@ function traceToolCall({
|
|
|
117
145
|
toolResponse = { result: toolResponse };
|
|
118
146
|
}
|
|
119
147
|
span.setAttributes({
|
|
120
|
-
[
|
|
121
|
-
"gcp.vertex.agent.event_id": functionResponseEvent.id,
|
|
122
|
-
"gcp.vertex.agent.tool_response": shouldAddRequestResponseToSpans() ? safeJsonSerialize(toolResponse) : "{}"
|
|
148
|
+
["gen_ai.tool.call.id" /* TOOL_CALL_ID */]: toolCallId,
|
|
149
|
+
["gcp.vertex.agent.event_id" /* EVENT_ID */]: functionResponseEvent.id,
|
|
150
|
+
["gcp.vertex.agent.tool_response" /* TOOL_RESPONSE */]: shouldAddRequestResponseToSpans() ? safeJsonSerialize(toolResponse) : "{}"
|
|
123
151
|
});
|
|
124
152
|
}
|
|
125
153
|
__name(traceToolCall, "traceToolCall");
|
|
126
154
|
function traceMergedToolCalls({
|
|
127
155
|
responseEventId,
|
|
128
|
-
functionResponseEvent
|
|
156
|
+
functionResponseEvent,
|
|
157
|
+
invocationContext
|
|
129
158
|
}) {
|
|
130
159
|
const span = trace.getActiveSpan();
|
|
131
160
|
if (!span) return;
|
|
132
161
|
span.setAttributes({
|
|
133
|
-
[
|
|
134
|
-
[
|
|
135
|
-
[
|
|
136
|
-
[
|
|
137
|
-
"
|
|
138
|
-
"gcp.vertex.agent.
|
|
162
|
+
["gen_ai.operation.name" /* OPERATION_NAME */]: "execute_tool",
|
|
163
|
+
["gen_ai.system" /* SYSTEM */]: GEN_AI_SYSTEM_VALUE,
|
|
164
|
+
["gen_ai.tool.name" /* TOOL_NAME */]: "(merged tools)",
|
|
165
|
+
["gen_ai.tool.description" /* TOOL_DESCRIPTION */]: "(merged tools)",
|
|
166
|
+
["gen_ai.tool.call.id" /* TOOL_CALL_ID */]: responseEventId,
|
|
167
|
+
["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
|
|
168
|
+
["gcp.vertex.agent.tool_call_args" /* TOOL_CALL_ARGS */]: "N/A",
|
|
169
|
+
["gcp.vertex.agent.event_id" /* EVENT_ID */]: responseEventId,
|
|
139
170
|
// Setting empty llm request and response (as UI expect these) while not
|
|
140
171
|
// applicable for tool_response.
|
|
141
|
-
"gcp.vertex.agent.llm_request": "{}",
|
|
142
|
-
"gcp.vertex.agent.llm_response": "{}"
|
|
172
|
+
["gcp.vertex.agent.llm_request" /* LLM_REQUEST */]: "{}",
|
|
173
|
+
["gcp.vertex.agent.llm_response" /* LLM_RESPONSE */]: "{}"
|
|
143
174
|
});
|
|
144
175
|
span.setAttribute(
|
|
145
|
-
"gcp.vertex.agent.tool_response"
|
|
176
|
+
"gcp.vertex.agent.tool_response" /* TOOL_RESPONSE */,
|
|
146
177
|
shouldAddRequestResponseToSpans() ? safeJsonSerialize(functionResponseEvent) : "{}"
|
|
147
178
|
);
|
|
148
179
|
}
|
|
@@ -157,43 +188,43 @@ function traceCallLlm({
|
|
|
157
188
|
const span = trace.getActiveSpan();
|
|
158
189
|
if (!span) return;
|
|
159
190
|
span.setAttributes({
|
|
160
|
-
"gen_ai.system":
|
|
161
|
-
"gen_ai.request.model": llmRequest.model,
|
|
162
|
-
...((_a = invocationContext.agent) == null ? void 0 : _a.name) ? { [
|
|
163
|
-
"gcp.vertex.agent.invocation_id": invocationContext.invocationId,
|
|
164
|
-
"gcp.vertex.agent.session_id": invocationContext.session.id,
|
|
165
|
-
"gcp.vertex.agent.event_id": eventId,
|
|
191
|
+
["gen_ai.system" /* SYSTEM */]: GEN_AI_SYSTEM_VALUE,
|
|
192
|
+
["gen_ai.request.model" /* REQUEST_MODEL */]: llmRequest.model,
|
|
193
|
+
...((_a = invocationContext.agent) == null ? void 0 : _a.name) ? { ["gen_ai.agent.name" /* AGENT_NAME */]: invocationContext.agent.name } : {},
|
|
194
|
+
["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
|
|
195
|
+
["gcp.vertex.agent.session_id" /* SESSION_ID */]: invocationContext.session.id,
|
|
196
|
+
["gcp.vertex.agent.event_id" /* EVENT_ID */]: eventId,
|
|
166
197
|
// Consider removing once GenAI SDK provides a way to record this info.
|
|
167
|
-
"gcp.vertex.agent.llm_request": shouldAddRequestResponseToSpans() ? safeJsonSerialize(buildLlmRequestForTrace(llmRequest)) : "{}"
|
|
198
|
+
["gcp.vertex.agent.llm_request" /* LLM_REQUEST */]: shouldAddRequestResponseToSpans() ? safeJsonSerialize(buildLlmRequestForTrace(llmRequest)) : "{}"
|
|
168
199
|
});
|
|
169
200
|
if ((_b = llmRequest.config) == null ? void 0 : _b.topP) {
|
|
170
|
-
span.setAttribute("gen_ai.request.top_p"
|
|
201
|
+
span.setAttribute("gen_ai.request.top_p" /* REQUEST_TOP_P */, llmRequest.config.topP);
|
|
171
202
|
}
|
|
172
203
|
if (((_c = llmRequest.config) == null ? void 0 : _c.maxOutputTokens) !== void 0) {
|
|
173
204
|
span.setAttribute(
|
|
174
|
-
"gen_ai.request.max_tokens"
|
|
205
|
+
"gen_ai.request.max_tokens" /* REQUEST_MAX_TOKENS */,
|
|
175
206
|
llmRequest.config.maxOutputTokens
|
|
176
207
|
);
|
|
177
208
|
}
|
|
178
209
|
span.setAttribute(
|
|
179
|
-
"gcp.vertex.agent.llm_response"
|
|
210
|
+
"gcp.vertex.agent.llm_response" /* LLM_RESPONSE */,
|
|
180
211
|
shouldAddRequestResponseToSpans() ? safeJsonSerialize(llmResponse) : "{}"
|
|
181
212
|
);
|
|
182
213
|
if (llmResponse.usageMetadata) {
|
|
183
214
|
span.setAttribute(
|
|
184
|
-
"gen_ai.usage.input_tokens"
|
|
215
|
+
"gen_ai.usage.input_tokens" /* USAGE_INPUT_TOKENS */,
|
|
185
216
|
llmResponse.usageMetadata.promptTokenCount || 0
|
|
186
217
|
);
|
|
187
218
|
}
|
|
188
219
|
if ((_d = llmResponse.usageMetadata) == null ? void 0 : _d.candidatesTokenCount) {
|
|
189
220
|
span.setAttribute(
|
|
190
|
-
"gen_ai.usage.output_tokens"
|
|
221
|
+
"gen_ai.usage.output_tokens" /* USAGE_OUTPUT_TOKENS */,
|
|
191
222
|
llmResponse.usageMetadata.candidatesTokenCount
|
|
192
223
|
);
|
|
193
224
|
}
|
|
194
225
|
if (llmResponse.finishReason) {
|
|
195
226
|
const finishReasonValue = typeof llmResponse.finishReason === "string" ? llmResponse.finishReason.toLowerCase() : String(llmResponse.finishReason).toLowerCase();
|
|
196
|
-
span.setAttribute("gen_ai.response.finish_reasons"
|
|
227
|
+
span.setAttribute("gen_ai.response.finish_reasons" /* RESPONSE_FINISH_REASONS */, [finishReasonValue]);
|
|
197
228
|
}
|
|
198
229
|
}
|
|
199
230
|
__name(traceCallLlm, "traceCallLlm");
|
|
@@ -205,11 +236,11 @@ function traceSendData({
|
|
|
205
236
|
const span = trace.getActiveSpan();
|
|
206
237
|
if (!span) return;
|
|
207
238
|
span.setAttributes({
|
|
208
|
-
"gcp.vertex.agent.invocation_id": invocationContext.invocationId,
|
|
209
|
-
"gcp.vertex.agent.event_id": eventId
|
|
239
|
+
["gcp.vertex.agent.invocation_id" /* INVOCATION_ID */]: invocationContext.invocationId,
|
|
240
|
+
["gcp.vertex.agent.event_id" /* EVENT_ID */]: eventId
|
|
210
241
|
});
|
|
211
242
|
span.setAttribute(
|
|
212
|
-
"gcp.vertex.agent.data"
|
|
243
|
+
"gcp.vertex.agent.data" /* DATA */,
|
|
213
244
|
shouldAddRequestResponseToSpans() ? safeJsonSerialize(data) : "{}"
|
|
214
245
|
);
|
|
215
246
|
}
|