@google/adk 0.2.5 → 0.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/agents/base_agent.js +43 -21
- package/dist/cjs/agents/callback_context.js +4 -1
- package/dist/cjs/agents/content_processor_utils.js +15 -7
- package/dist/cjs/agents/functions.js +79 -29
- package/dist/cjs/agents/llm_agent.js +59 -33
- package/dist/cjs/agents/loop_agent.js +2 -1
- package/dist/cjs/agents/parallel_agent.js +3 -4
- package/dist/cjs/artifacts/gcs_artifact_service.js +28 -20
- package/dist/cjs/artifacts/in_memory_artifact_service.js +18 -4
- package/dist/cjs/auth/auth_handler.js +3 -1
- package/dist/cjs/code_executors/base_code_executor.js +3 -1
- package/dist/cjs/code_executors/built_in_code_executor.js +7 -3
- package/dist/cjs/code_executors/code_executor_context.js +5 -5
- package/dist/cjs/common.js +4 -0
- package/dist/cjs/events/event.js +1 -3
- package/dist/cjs/index.js +19 -19
- package/dist/cjs/index.js.map +4 -4
- package/dist/cjs/memory/in_memory_memory_service.js +3 -1
- package/dist/cjs/models/base_llm.js +8 -4
- package/dist/cjs/models/gemini_llm_connection.js +1 -0
- package/dist/cjs/models/google_llm.js +3 -3
- package/dist/cjs/plugins/base_plugin.js +12 -0
- package/dist/cjs/plugins/logging_plugin.js +50 -13
- package/dist/cjs/plugins/plugin_manager.js +56 -24
- package/dist/cjs/plugins/security_plugin.js +1 -1
- package/dist/cjs/runner/runner.js +110 -95
- package/dist/cjs/sessions/in_memory_session_service.js +38 -14
- package/dist/cjs/telemetry/google_cloud.js +7 -9
- package/dist/cjs/telemetry/setup.js +15 -7
- package/dist/cjs/telemetry/tracing.js +37 -15
- package/dist/cjs/tools/agent_tool.js +8 -4
- package/dist/cjs/tools/base_tool.js +4 -2
- package/dist/cjs/tools/forwarding_artifact_service.js +1 -1
- package/dist/cjs/tools/function_tool.js +1 -2
- package/dist/cjs/tools/google_search_tool.js +1 -2
- package/dist/cjs/tools/mcp/mcp_session_manager.js +16 -10
- package/dist/cjs/tools/mcp/mcp_tool.js +1 -3
- package/dist/cjs/tools/mcp/mcp_toolset.js +1 -1
- package/dist/cjs/utils/env_aware_utils.js +1 -1
- package/dist/cjs/utils/gemini_schema_util.js +9 -4
- package/dist/cjs/utils/logger.js +47 -3
- package/dist/cjs/utils/simple_zod_to_json.js +100 -141
- package/dist/cjs/utils/variant_utils.js +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/agents/base_agent.js +48 -22
- 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 +83 -29
- package/dist/esm/agents/llm_agent.js +63 -33
- package/dist/esm/agents/loop_agent.js +2 -1
- package/dist/esm/agents/parallel_agent.js +3 -4
- package/dist/esm/artifacts/gcs_artifact_service.js +28 -20
- package/dist/esm/artifacts/in_memory_artifact_service.js +18 -4
- 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 +3 -1
- package/dist/esm/events/event.js +1 -3
- package/dist/esm/index.js +19 -19
- package/dist/esm/index.js.map +4 -4
- package/dist/esm/memory/in_memory_memory_service.js +3 -1
- 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 +8 -4
- 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 +114 -96
- package/dist/esm/sessions/in_memory_session_service.js +41 -15
- 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 +1 -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 +1 -1
- package/dist/esm/utils/gemini_schema_util.js +9 -4
- package/dist/esm/utils/logger.js +43 -2
- package/dist/esm/utils/simple_zod_to_json.js +102 -141
- package/dist/esm/utils/variant_utils.js +1 -1
- package/dist/esm/version.js +1 -1
- 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 +1 -1
- package/dist/types/agents/loop_agent.d.ts +1 -1
- package/dist/types/agents/parallel_agent.d.ts +1 -1
- package/dist/types/artifacts/in_memory_artifact_service.d.ts +3 -3
- 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 +2 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/models/base_llm_connection.d.ts +1 -1
- 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 +1 -1
- package/dist/types/sessions/in_memory_session_service.d.ts +5 -5
- 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 +2 -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/gemini_schema_util.d.ts +4 -12
- package/dist/types/utils/logger.d.ts +11 -10
- package/dist/types/utils/simple_zod_to_json.d.ts +5 -4
- package/dist/types/version.d.ts +1 -1
- package/dist/web/agents/base_agent.js +94 -33
- 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 +83 -29
- package/dist/web/agents/llm_agent.js +117 -54
- package/dist/web/agents/loop_agent.js +2 -1
- package/dist/web/agents/parallel_agent.js +3 -4
- package/dist/web/artifacts/gcs_artifact_service.js +25 -17
- package/dist/web/artifacts/in_memory_artifact_service.js +18 -4
- 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 +3 -1
- package/dist/web/events/event.js +1 -3
- package/dist/web/index.js +1 -1
- package/dist/web/index.js.map +4 -4
- package/dist/web/memory/in_memory_memory_service.js +3 -1
- 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 +8 -4
- 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 +159 -108
- package/dist/web/sessions/in_memory_session_service.js +41 -15
- 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 +1 -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 +1 -1
- package/dist/web/utils/gemini_schema_util.js +9 -4
- package/dist/web/utils/logger.js +43 -2
- package/dist/web/utils/simple_zod_to_json.js +102 -155
- package/dist/web/utils/variant_utils.js +1 -1
- package/dist/web/version.js +1 -1
- package/package.json +4 -2
|
@@ -36,6 +36,7 @@ var import_built_in_code_executor = require("../code_executors/built_in_code_exe
|
|
|
36
36
|
var import_event = require("../events/event.js");
|
|
37
37
|
var import_event_actions = require("../events/event_actions.js");
|
|
38
38
|
var import_plugin_manager = require("../plugins/plugin_manager.js");
|
|
39
|
+
var import_tracing = require("../telemetry/tracing.js");
|
|
39
40
|
var import_logger = require("../utils/logger.js");
|
|
40
41
|
var import_model_name = require("../utils/model_name.js");
|
|
41
42
|
/**
|
|
@@ -67,109 +68,123 @@ class Runner {
|
|
|
67
68
|
*/
|
|
68
69
|
// TODO - b/425992518: user, sessionId, and runConfig can be internalized.
|
|
69
70
|
async *runAsync(params) {
|
|
70
|
-
var _a;
|
|
71
71
|
const { userId, sessionId, stateDelta } = params;
|
|
72
72
|
const runConfig = (0, import_run_config.createRunConfig)(params.runConfig);
|
|
73
73
|
let newMessage = params.newMessage;
|
|
74
|
-
const span =
|
|
74
|
+
const span = import_tracing.tracer.startSpan("invocation");
|
|
75
|
+
const ctx = import_api.trace.setSpan(import_api.context.active(), span);
|
|
75
76
|
try {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
credentialService: this.credentialService,
|
|
105
|
-
invocationId: (0, import_invocation_context.newInvocationContextId)(),
|
|
106
|
-
agent: this.agent,
|
|
107
|
-
session,
|
|
108
|
-
userContent: newMessage,
|
|
109
|
-
runConfig,
|
|
110
|
-
pluginManager: this.pluginManager
|
|
111
|
-
});
|
|
112
|
-
const pluginUserMessage = await this.pluginManager.runOnUserMessageCallback({
|
|
113
|
-
userMessage: newMessage,
|
|
114
|
-
invocationContext
|
|
115
|
-
});
|
|
116
|
-
if (pluginUserMessage) {
|
|
117
|
-
newMessage = pluginUserMessage;
|
|
118
|
-
}
|
|
119
|
-
if (newMessage) {
|
|
120
|
-
if (!((_a = newMessage.parts) == null ? void 0 : _a.length)) {
|
|
121
|
-
throw new Error("No parts in the newMessage.");
|
|
122
|
-
}
|
|
123
|
-
if (runConfig.saveInputBlobsAsArtifacts) {
|
|
124
|
-
await this.saveArtifacts(
|
|
125
|
-
invocationContext.invocationId,
|
|
126
|
-
session.userId,
|
|
127
|
-
session.id,
|
|
128
|
-
newMessage
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
await this.sessionService.appendEvent({
|
|
132
|
-
session,
|
|
133
|
-
event: (0, import_event.createEvent)({
|
|
134
|
-
invocationId: invocationContext.invocationId,
|
|
135
|
-
author: "user",
|
|
136
|
-
actions: stateDelta ? (0, import_event_actions.createEventActions)({ stateDelta }) : void 0,
|
|
137
|
-
content: newMessage
|
|
138
|
-
})
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
invocationContext.agent = this.determineAgentForResumption(
|
|
142
|
-
session,
|
|
143
|
-
this.agent
|
|
144
|
-
);
|
|
145
|
-
const beforeRunCallbackResponse = await this.pluginManager.runBeforeRunCallback({ invocationContext });
|
|
146
|
-
if (beforeRunCallbackResponse) {
|
|
147
|
-
const earlyExitEvent = (0, import_event.createEvent)({
|
|
148
|
-
invocationId: invocationContext.invocationId,
|
|
149
|
-
author: "model",
|
|
150
|
-
content: beforeRunCallbackResponse
|
|
151
|
-
});
|
|
152
|
-
await this.sessionService.appendEvent({ session, event: earlyExitEvent });
|
|
153
|
-
yield earlyExitEvent;
|
|
154
|
-
} else {
|
|
155
|
-
for await (const event of invocationContext.agent.runAsync(
|
|
156
|
-
invocationContext
|
|
157
|
-
)) {
|
|
158
|
-
if (!event.partial) {
|
|
159
|
-
await this.sessionService.appendEvent({ session, event });
|
|
77
|
+
yield* (0, import_tracing.runAsyncGeneratorWithOtelContext)(
|
|
78
|
+
ctx,
|
|
79
|
+
this,
|
|
80
|
+
async function* () {
|
|
81
|
+
var _a;
|
|
82
|
+
const session = await this.sessionService.getSession({
|
|
83
|
+
appName: this.appName,
|
|
84
|
+
userId,
|
|
85
|
+
sessionId
|
|
86
|
+
});
|
|
87
|
+
if (!session) {
|
|
88
|
+
if (!this.appName) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`Session lookup failed: appName must be provided in runner constructor`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
throw new Error(`Session not found: ${sessionId}`);
|
|
94
|
+
}
|
|
95
|
+
if (runConfig.supportCfc && (0, import_llm_agent.isLlmAgent)(this.agent)) {
|
|
96
|
+
const modelName = this.agent.canonicalModel.model;
|
|
97
|
+
if (!(0, import_model_name.isGemini2OrAbove)(modelName)) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
`CFC is not supported for model: ${modelName} in agent: ${this.agent.name}`
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
if (!(0, import_built_in_code_executor.isBuiltInCodeExecutor)(this.agent.codeExecutor)) {
|
|
103
|
+
this.agent.codeExecutor = new import_built_in_code_executor.BuiltInCodeExecutor();
|
|
104
|
+
}
|
|
160
105
|
}
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
106
|
+
const invocationContext = new import_invocation_context.InvocationContext({
|
|
107
|
+
artifactService: this.artifactService,
|
|
108
|
+
sessionService: this.sessionService,
|
|
109
|
+
memoryService: this.memoryService,
|
|
110
|
+
credentialService: this.credentialService,
|
|
111
|
+
invocationId: (0, import_invocation_context.newInvocationContextId)(),
|
|
112
|
+
agent: this.agent,
|
|
113
|
+
session,
|
|
114
|
+
userContent: newMessage,
|
|
115
|
+
runConfig,
|
|
116
|
+
pluginManager: this.pluginManager
|
|
164
117
|
});
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
118
|
+
const pluginUserMessage = await this.pluginManager.runOnUserMessageCallback({
|
|
119
|
+
userMessage: newMessage,
|
|
120
|
+
invocationContext
|
|
121
|
+
});
|
|
122
|
+
if (pluginUserMessage) {
|
|
123
|
+
newMessage = pluginUserMessage;
|
|
124
|
+
}
|
|
125
|
+
if (newMessage) {
|
|
126
|
+
if (!((_a = newMessage.parts) == null ? void 0 : _a.length)) {
|
|
127
|
+
throw new Error("No parts in the newMessage.");
|
|
128
|
+
}
|
|
129
|
+
if (runConfig.saveInputBlobsAsArtifacts) {
|
|
130
|
+
await this.saveArtifacts(
|
|
131
|
+
invocationContext.invocationId,
|
|
132
|
+
session.userId,
|
|
133
|
+
session.id,
|
|
134
|
+
newMessage
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
await this.sessionService.appendEvent({
|
|
138
|
+
session,
|
|
139
|
+
event: (0, import_event.createEvent)({
|
|
140
|
+
invocationId: invocationContext.invocationId,
|
|
141
|
+
author: "user",
|
|
142
|
+
actions: stateDelta ? (0, import_event_actions.createEventActions)({ stateDelta }) : void 0,
|
|
143
|
+
content: newMessage
|
|
144
|
+
})
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
invocationContext.agent = this.determineAgentForResumption(
|
|
148
|
+
session,
|
|
149
|
+
this.agent
|
|
150
|
+
);
|
|
151
|
+
if (newMessage) {
|
|
152
|
+
const beforeRunCallbackResponse = await this.pluginManager.runBeforeRunCallback({
|
|
153
|
+
invocationContext
|
|
154
|
+
});
|
|
155
|
+
if (beforeRunCallbackResponse) {
|
|
156
|
+
const earlyExitEvent = (0, import_event.createEvent)({
|
|
157
|
+
invocationId: invocationContext.invocationId,
|
|
158
|
+
author: "model",
|
|
159
|
+
content: beforeRunCallbackResponse
|
|
160
|
+
});
|
|
161
|
+
await this.sessionService.appendEvent({
|
|
162
|
+
session,
|
|
163
|
+
event: earlyExitEvent
|
|
164
|
+
});
|
|
165
|
+
yield earlyExitEvent;
|
|
166
|
+
} else {
|
|
167
|
+
for await (const event of invocationContext.agent.runAsync(
|
|
168
|
+
invocationContext
|
|
169
|
+
)) {
|
|
170
|
+
if (!event.partial) {
|
|
171
|
+
await this.sessionService.appendEvent({ session, event });
|
|
172
|
+
}
|
|
173
|
+
const modifiedEvent = await this.pluginManager.runOnEventCallback({
|
|
174
|
+
invocationContext,
|
|
175
|
+
event
|
|
176
|
+
});
|
|
177
|
+
if (modifiedEvent) {
|
|
178
|
+
yield modifiedEvent;
|
|
179
|
+
} else {
|
|
180
|
+
yield event;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
await this.pluginManager.runAfterRunCallback({ invocationContext });
|
|
184
|
+
}
|
|
169
185
|
}
|
|
170
186
|
}
|
|
171
|
-
|
|
172
|
-
await this.pluginManager.runAfterRunCallback({ invocationContext });
|
|
187
|
+
);
|
|
173
188
|
} finally {
|
|
174
189
|
span.end();
|
|
175
190
|
}
|
|
@@ -55,7 +55,12 @@ class InMemorySessionService extends import_base_session_service.BaseSessionServ
|
|
|
55
55
|
*/
|
|
56
56
|
this.appState = {};
|
|
57
57
|
}
|
|
58
|
-
createSession({
|
|
58
|
+
createSession({
|
|
59
|
+
appName,
|
|
60
|
+
userId,
|
|
61
|
+
state,
|
|
62
|
+
sessionId
|
|
63
|
+
}) {
|
|
59
64
|
const session = (0, import_session.createSession)({
|
|
60
65
|
id: sessionId || (0, import_env_aware_utils.randomUUID)(),
|
|
61
66
|
appName,
|
|
@@ -75,7 +80,12 @@ class InMemorySessionService extends import_base_session_service.BaseSessionServ
|
|
|
75
80
|
this.mergeState(appName, userId, (0, import_lodash_es.cloneDeep)(session))
|
|
76
81
|
);
|
|
77
82
|
}
|
|
78
|
-
getSession({
|
|
83
|
+
getSession({
|
|
84
|
+
appName,
|
|
85
|
+
userId,
|
|
86
|
+
sessionId,
|
|
87
|
+
config
|
|
88
|
+
}) {
|
|
79
89
|
if (!this.sessions[appName] || !this.sessions[appName][userId] || !this.sessions[appName][userId][sessionId]) {
|
|
80
90
|
return Promise.resolve(void 0);
|
|
81
91
|
}
|
|
@@ -83,7 +93,9 @@ class InMemorySessionService extends import_base_session_service.BaseSessionServ
|
|
|
83
93
|
const copiedSession = (0, import_lodash_es.cloneDeep)(session);
|
|
84
94
|
if (config) {
|
|
85
95
|
if (config.numRecentEvents) {
|
|
86
|
-
copiedSession.events = copiedSession.events.slice(
|
|
96
|
+
copiedSession.events = copiedSession.events.slice(
|
|
97
|
+
-config.numRecentEvents
|
|
98
|
+
);
|
|
87
99
|
}
|
|
88
100
|
if (config.afterTimestamp) {
|
|
89
101
|
let i = copiedSession.events.length - 1;
|
|
@@ -100,31 +112,43 @@ class InMemorySessionService extends import_base_session_service.BaseSessionServ
|
|
|
100
112
|
}
|
|
101
113
|
return Promise.resolve(this.mergeState(appName, userId, copiedSession));
|
|
102
114
|
}
|
|
103
|
-
listSessions({
|
|
115
|
+
listSessions({
|
|
116
|
+
appName,
|
|
117
|
+
userId
|
|
118
|
+
}) {
|
|
104
119
|
if (!this.sessions[appName] || !this.sessions[appName][userId]) {
|
|
105
120
|
return Promise.resolve({ sessions: [] });
|
|
106
121
|
}
|
|
107
122
|
const sessionsWithoutEvents = [];
|
|
108
123
|
for (const session of Object.values(this.sessions[appName][userId])) {
|
|
109
|
-
sessionsWithoutEvents.push(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
124
|
+
sessionsWithoutEvents.push(
|
|
125
|
+
(0, import_session.createSession)({
|
|
126
|
+
id: session.id,
|
|
127
|
+
appName: session.appName,
|
|
128
|
+
userId: session.userId,
|
|
129
|
+
state: {},
|
|
130
|
+
events: [],
|
|
131
|
+
lastUpdateTime: session.lastUpdateTime
|
|
132
|
+
})
|
|
133
|
+
);
|
|
117
134
|
}
|
|
118
135
|
return Promise.resolve({ sessions: sessionsWithoutEvents });
|
|
119
136
|
}
|
|
120
|
-
async deleteSession({
|
|
137
|
+
async deleteSession({
|
|
138
|
+
appName,
|
|
139
|
+
userId,
|
|
140
|
+
sessionId
|
|
141
|
+
}) {
|
|
121
142
|
const session = await this.getSession({ appName, userId, sessionId });
|
|
122
143
|
if (!session) {
|
|
123
144
|
return;
|
|
124
145
|
}
|
|
125
146
|
delete this.sessions[appName][userId][sessionId];
|
|
126
147
|
}
|
|
127
|
-
async appendEvent({
|
|
148
|
+
async appendEvent({
|
|
149
|
+
session,
|
|
150
|
+
event
|
|
151
|
+
}) {
|
|
128
152
|
await super.appendEvent({ session, event });
|
|
129
153
|
session.lastUpdateTime = event.timestamp;
|
|
130
154
|
const appName = session.appName;
|
|
@@ -28,13 +28,13 @@ __export(google_cloud_exports, {
|
|
|
28
28
|
getGcpResource: () => getGcpResource
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(google_cloud_exports);
|
|
31
|
-
var
|
|
32
|
-
var import_sdk_metrics = require("@opentelemetry/sdk-metrics");
|
|
33
|
-
var import_resources = require("@opentelemetry/resources");
|
|
34
|
-
var import_resource_detector_gcp = require("@opentelemetry/resource-detector-gcp");
|
|
31
|
+
var import_opentelemetry_cloud_monitoring_exporter = require("@google-cloud/opentelemetry-cloud-monitoring-exporter");
|
|
35
32
|
var import_opentelemetry_cloud_trace_exporter = require("@google-cloud/opentelemetry-cloud-trace-exporter");
|
|
33
|
+
var import_resource_detector_gcp = require("@opentelemetry/resource-detector-gcp");
|
|
34
|
+
var import_resources = require("@opentelemetry/resources");
|
|
35
|
+
var import_sdk_metrics = require("@opentelemetry/sdk-metrics");
|
|
36
36
|
var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
|
|
37
|
-
var
|
|
37
|
+
var import_google_auth_library = require("google-auth-library");
|
|
38
38
|
var import_logger = require("../utils/logger.js");
|
|
39
39
|
/**
|
|
40
40
|
* @license
|
|
@@ -47,7 +47,7 @@ async function getGcpProjectId() {
|
|
|
47
47
|
const auth = new import_google_auth_library.GoogleAuth();
|
|
48
48
|
const projectId = await auth.getProjectId();
|
|
49
49
|
return projectId || void 0;
|
|
50
|
-
} catch (
|
|
50
|
+
} catch (_e) {
|
|
51
51
|
return void 0;
|
|
52
52
|
}
|
|
53
53
|
}
|
|
@@ -63,9 +63,7 @@ async function getGcpExporters(config = {}) {
|
|
|
63
63
|
return {};
|
|
64
64
|
}
|
|
65
65
|
return {
|
|
66
|
-
spanProcessors: enableTracing ? [
|
|
67
|
-
new import_sdk_trace_base.BatchSpanProcessor(new import_opentelemetry_cloud_trace_exporter.TraceExporter({ projectId }))
|
|
68
|
-
] : [],
|
|
66
|
+
spanProcessors: enableTracing ? [new import_sdk_trace_base.BatchSpanProcessor(new import_opentelemetry_cloud_trace_exporter.TraceExporter({ projectId }))] : [],
|
|
69
67
|
metricReaders: enableMetrics ? [
|
|
70
68
|
new import_sdk_metrics.PeriodicExportingMetricReader({
|
|
71
69
|
exporter: new import_opentelemetry_cloud_monitoring_exporter.MetricExporter({ projectId }),
|
|
@@ -29,14 +29,14 @@ __export(setup_exports, {
|
|
|
29
29
|
module.exports = __toCommonJS(setup_exports);
|
|
30
30
|
var import_api = require("@opentelemetry/api");
|
|
31
31
|
var import_api_logs = require("@opentelemetry/api-logs");
|
|
32
|
+
var import_exporter_logs_otlp_http = require("@opentelemetry/exporter-logs-otlp-http");
|
|
33
|
+
var import_exporter_metrics_otlp_http = require("@opentelemetry/exporter-metrics-otlp-http");
|
|
34
|
+
var import_exporter_trace_otlp_http = require("@opentelemetry/exporter-trace-otlp-http");
|
|
35
|
+
var import_resources = require("@opentelemetry/resources");
|
|
32
36
|
var import_sdk_logs = require("@opentelemetry/sdk-logs");
|
|
33
37
|
var import_sdk_metrics = require("@opentelemetry/sdk-metrics");
|
|
34
|
-
var import_resources = require("@opentelemetry/resources");
|
|
35
38
|
var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
|
|
36
39
|
var import_sdk_trace_node = require("@opentelemetry/sdk-trace-node");
|
|
37
|
-
var import_exporter_trace_otlp_http = require("@opentelemetry/exporter-trace-otlp-http");
|
|
38
|
-
var import_exporter_metrics_otlp_http = require("@opentelemetry/exporter-metrics-otlp-http");
|
|
39
|
-
var import_exporter_logs_otlp_http = require("@opentelemetry/exporter-logs-otlp-http");
|
|
40
40
|
/**
|
|
41
41
|
* @license
|
|
42
42
|
* Copyright 2025 Google LLC
|
|
@@ -45,9 +45,13 @@ var import_exporter_logs_otlp_http = require("@opentelemetry/exporter-logs-otlp-
|
|
|
45
45
|
function maybeSetOtelProviders(otelHooksToSetup = [], otelResource) {
|
|
46
46
|
const resource = otelResource || getOtelResource();
|
|
47
47
|
const allHooks = [...otelHooksToSetup, getOtelExporters()];
|
|
48
|
-
const spanProcessors = allHooks.flatMap(
|
|
48
|
+
const spanProcessors = allHooks.flatMap(
|
|
49
|
+
(hooks) => hooks.spanProcessors || []
|
|
50
|
+
);
|
|
49
51
|
const metricReaders = allHooks.flatMap((hooks) => hooks.metricReaders || []);
|
|
50
|
-
const logRecordProcessors = allHooks.flatMap(
|
|
52
|
+
const logRecordProcessors = allHooks.flatMap(
|
|
53
|
+
(hooks) => hooks.logRecordProcessors || []
|
|
54
|
+
);
|
|
51
55
|
if (spanProcessors.length > 0) {
|
|
52
56
|
const tracerProvider = new import_sdk_trace_node.NodeTracerProvider({
|
|
53
57
|
resource,
|
|
@@ -87,7 +91,11 @@ function getOtelExporters(config = getOtelExportersConfig()) {
|
|
|
87
91
|
const { enableTracing, enableMetrics, enableLogging } = config;
|
|
88
92
|
return {
|
|
89
93
|
spanProcessors: enableTracing ? [new import_sdk_trace_base.BatchSpanProcessor(new import_exporter_trace_otlp_http.OTLPTraceExporter())] : [],
|
|
90
|
-
metricReaders: enableMetrics ? [
|
|
94
|
+
metricReaders: enableMetrics ? [
|
|
95
|
+
new import_sdk_metrics.PeriodicExportingMetricReader({
|
|
96
|
+
exporter: new import_exporter_metrics_otlp_http.OTLPMetricExporter()
|
|
97
|
+
})
|
|
98
|
+
] : [],
|
|
91
99
|
logRecordProcessors: enableLogging ? [new import_sdk_logs.BatchLogRecordProcessor(new import_exporter_logs_otlp_http.OTLPLogExporter())] : []
|
|
92
100
|
};
|
|
93
101
|
}
|
|
@@ -24,7 +24,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
25
|
var tracing_exports = {};
|
|
26
26
|
__export(tracing_exports, {
|
|
27
|
-
|
|
27
|
+
runAsyncGeneratorWithOtelContext: () => runAsyncGeneratorWithOtelContext,
|
|
28
28
|
traceAgentInvocation: () => traceAgentInvocation,
|
|
29
29
|
traceCallLlm: () => traceCallLlm,
|
|
30
30
|
traceMergedToolCalls: () => traceMergedToolCalls,
|
|
@@ -48,14 +48,11 @@ const GEN_AI_TOOL_CALL_ID = "gen_ai.tool.call.id";
|
|
|
48
48
|
const GEN_AI_TOOL_DESCRIPTION = "gen_ai.tool.description";
|
|
49
49
|
const GEN_AI_TOOL_NAME = "gen_ai.tool.name";
|
|
50
50
|
const GEN_AI_TOOL_TYPE = "gen_ai.tool.type";
|
|
51
|
-
const tracer = import_api.trace.getTracer(
|
|
52
|
-
"gcp.vertex.agent",
|
|
53
|
-
import_version.version
|
|
54
|
-
);
|
|
51
|
+
const tracer = import_api.trace.getTracer("gcp.vertex.agent", import_version.version);
|
|
55
52
|
function safeJsonSerialize(obj) {
|
|
56
53
|
try {
|
|
57
54
|
return JSON.stringify(obj);
|
|
58
|
-
} catch (
|
|
55
|
+
} catch (_e) {
|
|
59
56
|
return "<not serializable>";
|
|
60
57
|
}
|
|
61
58
|
}
|
|
@@ -132,7 +129,10 @@ function traceMergedToolCalls({
|
|
|
132
129
|
"gcp.vertex.agent.llm_request": "{}",
|
|
133
130
|
"gcp.vertex.agent.llm_response": "{}"
|
|
134
131
|
});
|
|
135
|
-
span.setAttribute(
|
|
132
|
+
span.setAttribute(
|
|
133
|
+
"gcp.vertex.agent.tool_response",
|
|
134
|
+
shouldAddRequestResponseToSpans() ? safeJsonSerialize(functionResponseEvent) : "{}"
|
|
135
|
+
);
|
|
136
136
|
}
|
|
137
137
|
function traceCallLlm({
|
|
138
138
|
invocationContext,
|
|
@@ -156,14 +156,26 @@ function traceCallLlm({
|
|
|
156
156
|
span.setAttribute("gen_ai.request.top_p", llmRequest.config.topP);
|
|
157
157
|
}
|
|
158
158
|
if (((_b = llmRequest.config) == null ? void 0 : _b.maxOutputTokens) !== void 0) {
|
|
159
|
-
span.setAttribute(
|
|
159
|
+
span.setAttribute(
|
|
160
|
+
"gen_ai.request.max_tokens",
|
|
161
|
+
llmRequest.config.maxOutputTokens
|
|
162
|
+
);
|
|
160
163
|
}
|
|
161
|
-
span.setAttribute(
|
|
164
|
+
span.setAttribute(
|
|
165
|
+
"gcp.vertex.agent.llm_response",
|
|
166
|
+
shouldAddRequestResponseToSpans() ? safeJsonSerialize(llmResponse) : "{}"
|
|
167
|
+
);
|
|
162
168
|
if (llmResponse.usageMetadata) {
|
|
163
|
-
span.setAttribute(
|
|
169
|
+
span.setAttribute(
|
|
170
|
+
"gen_ai.usage.input_tokens",
|
|
171
|
+
llmResponse.usageMetadata.promptTokenCount || 0
|
|
172
|
+
);
|
|
164
173
|
}
|
|
165
174
|
if ((_c = llmResponse.usageMetadata) == null ? void 0 : _c.candidatesTokenCount) {
|
|
166
|
-
span.setAttribute(
|
|
175
|
+
span.setAttribute(
|
|
176
|
+
"gen_ai.usage.output_tokens",
|
|
177
|
+
llmResponse.usageMetadata.candidatesTokenCount
|
|
178
|
+
);
|
|
167
179
|
}
|
|
168
180
|
if (llmResponse.finishReason) {
|
|
169
181
|
const finishReasonValue = typeof llmResponse.finishReason === "string" ? llmResponse.finishReason.toLowerCase() : String(llmResponse.finishReason).toLowerCase();
|
|
@@ -181,7 +193,10 @@ function traceSendData({
|
|
|
181
193
|
"gcp.vertex.agent.invocation_id": invocationContext.invocationId,
|
|
182
194
|
"gcp.vertex.agent.event_id": eventId
|
|
183
195
|
});
|
|
184
|
-
span.setAttribute(
|
|
196
|
+
span.setAttribute(
|
|
197
|
+
"gcp.vertex.agent.data",
|
|
198
|
+
shouldAddRequestResponseToSpans() ? safeJsonSerialize(data) : "{}"
|
|
199
|
+
);
|
|
185
200
|
}
|
|
186
201
|
function buildLlmRequestForTrace(llmRequest) {
|
|
187
202
|
const result = {
|
|
@@ -201,7 +216,7 @@ function buildLlmRequestForTrace(llmRequest) {
|
|
|
201
216
|
});
|
|
202
217
|
return result;
|
|
203
218
|
}
|
|
204
|
-
function
|
|
219
|
+
function bindOtelContextToAsyncGenerator(ctx, generator) {
|
|
205
220
|
return {
|
|
206
221
|
// Bind the next() method to execute within the provided context
|
|
207
222
|
next: import_api.context.bind(ctx, generator.next.bind(generator)),
|
|
@@ -211,17 +226,24 @@ function bindAsyncGenerator(ctx, generator) {
|
|
|
211
226
|
throw: import_api.context.bind(ctx, generator.throw.bind(generator)),
|
|
212
227
|
// Ensure the async iterator symbol also returns a context-bound generator
|
|
213
228
|
[Symbol.asyncIterator]() {
|
|
214
|
-
return
|
|
229
|
+
return bindOtelContextToAsyncGenerator(
|
|
230
|
+
ctx,
|
|
231
|
+
generator[Symbol.asyncIterator]()
|
|
232
|
+
);
|
|
215
233
|
}
|
|
216
234
|
};
|
|
217
235
|
}
|
|
236
|
+
function runAsyncGeneratorWithOtelContext(otelContext, generatorFnContext, generatorFn) {
|
|
237
|
+
const generator = generatorFn.call(generatorFnContext);
|
|
238
|
+
return bindOtelContextToAsyncGenerator(otelContext, generator);
|
|
239
|
+
}
|
|
218
240
|
function shouldAddRequestResponseToSpans() {
|
|
219
241
|
const envValue = process.env.ADK_CAPTURE_MESSAGE_CONTENT_IN_SPANS || "true";
|
|
220
242
|
return envValue === "true" || envValue === "1";
|
|
221
243
|
}
|
|
222
244
|
// Annotate the CommonJS export names for ESM import in node:
|
|
223
245
|
0 && (module.exports = {
|
|
224
|
-
|
|
246
|
+
runAsyncGeneratorWithOtelContext,
|
|
225
247
|
traceAgentInvocation,
|
|
226
248
|
traceCallLlm,
|
|
227
249
|
traceMergedToolCalls,
|
|
@@ -48,9 +48,10 @@ function isAgentTool(obj) {
|
|
|
48
48
|
}
|
|
49
49
|
class AgentTool extends (_b = import_base_tool.BaseTool, _a = AGENT_TOOL_SIGNATURE_SYMBOL, _b) {
|
|
50
50
|
constructor(config) {
|
|
51
|
-
super(
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
super({
|
|
52
|
+
name: config.agent.name,
|
|
53
|
+
description: config.agent.description || ""
|
|
54
|
+
});
|
|
54
55
|
/** A unique symbol to identify ADK agent tool class. */
|
|
55
56
|
this[_a] = true;
|
|
56
57
|
this.agent = config.agent;
|
|
@@ -88,7 +89,10 @@ class AgentTool extends (_b = import_base_tool.BaseTool, _a = AGENT_TOOL_SIGNATU
|
|
|
88
89
|
}
|
|
89
90
|
return declaration;
|
|
90
91
|
}
|
|
91
|
-
async runAsync({
|
|
92
|
+
async runAsync({
|
|
93
|
+
args,
|
|
94
|
+
toolContext
|
|
95
|
+
}) {
|
|
92
96
|
var _a2, _b2;
|
|
93
97
|
if (this.skipSummarization) {
|
|
94
98
|
toolContext.actions.skipSummarization = true;
|
|
@@ -79,7 +79,7 @@ class BaseTool {
|
|
|
79
79
|
*
|
|
80
80
|
* @param request The request to process the LLM request.
|
|
81
81
|
*/
|
|
82
|
-
async processLlmRequest({
|
|
82
|
+
async processLlmRequest({ llmRequest }) {
|
|
83
83
|
const functionDeclaration = this._getDeclaration();
|
|
84
84
|
if (!functionDeclaration) {
|
|
85
85
|
return;
|
|
@@ -108,7 +108,9 @@ class BaseTool {
|
|
|
108
108
|
}
|
|
109
109
|
function findToolWithFunctionDeclarations(llmRequest) {
|
|
110
110
|
var _a2;
|
|
111
|
-
return (((_a2 = llmRequest.config) == null ? void 0 : _a2.tools) || []).find(
|
|
111
|
+
return (((_a2 = llmRequest.config) == null ? void 0 : _a2.tools) || []).find(
|
|
112
|
+
(tool) => "functionDeclarations" in tool
|
|
113
|
+
);
|
|
112
114
|
}
|
|
113
115
|
// Annotate the CommonJS export names for ESM import in node:
|
|
114
116
|
0 && (module.exports = {
|
|
@@ -45,7 +45,7 @@ class ForwardingArtifactService {
|
|
|
45
45
|
async loadArtifact(request) {
|
|
46
46
|
return this.toolContext.loadArtifact(request.filename, request.version);
|
|
47
47
|
}
|
|
48
|
-
async listArtifactKeys(
|
|
48
|
+
async listArtifactKeys() {
|
|
49
49
|
return this.toolContext.listArtifacts();
|
|
50
50
|
}
|
|
51
51
|
async deleteArtifact(request) {
|
|
@@ -29,7 +29,6 @@ __export(function_tool_exports, {
|
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(function_tool_exports);
|
|
31
31
|
var import_genai = require("@google/genai");
|
|
32
|
-
var import_zod = require("zod");
|
|
33
32
|
var import_simple_zod_to_json = require("../utils/simple_zod_to_json.js");
|
|
34
33
|
var import_base_tool = require("./base_tool.js");
|
|
35
34
|
/**
|
|
@@ -90,7 +89,7 @@ class FunctionTool extends (_b = import_base_tool.BaseTool, _a = FUNCTION_TOOL_S
|
|
|
90
89
|
async runAsync(req) {
|
|
91
90
|
try {
|
|
92
91
|
let validatedArgs = req.args;
|
|
93
|
-
if (this.parameters
|
|
92
|
+
if ((0, import_simple_zod_to_json.isZodObject)(this.parameters)) {
|
|
94
93
|
validatedArgs = this.parameters.parse(req.args);
|
|
95
94
|
}
|
|
96
95
|
return await this.execute(
|
|
@@ -39,11 +39,10 @@ class GoogleSearchTool extends import_base_tool.BaseTool {
|
|
|
39
39
|
constructor() {
|
|
40
40
|
super({ name: "google_search", description: "Google Search Tool" });
|
|
41
41
|
}
|
|
42
|
-
runAsync(
|
|
42
|
+
runAsync() {
|
|
43
43
|
return Promise.resolve();
|
|
44
44
|
}
|
|
45
45
|
async processLlmRequest({
|
|
46
|
-
toolContext,
|
|
47
46
|
llmRequest
|
|
48
47
|
}) {
|
|
49
48
|
if (!llmRequest.model) {
|
|
@@ -40,6 +40,7 @@ class MCPSessionManager {
|
|
|
40
40
|
this.connectionParams = connectionParams;
|
|
41
41
|
}
|
|
42
42
|
async createSession() {
|
|
43
|
+
var _a;
|
|
43
44
|
const client = new import_client.Client({ name: "MCPClient", version: "1.0.0" });
|
|
44
45
|
switch (this.connectionParams.type) {
|
|
45
46
|
case "StdioConnectionParams":
|
|
@@ -47,20 +48,25 @@ class MCPSessionManager {
|
|
|
47
48
|
new import_stdio.StdioClientTransport(this.connectionParams.serverParams)
|
|
48
49
|
);
|
|
49
50
|
break;
|
|
50
|
-
case "StreamableHTTPConnectionParams":
|
|
51
|
-
const
|
|
52
|
-
|
|
51
|
+
case "StreamableHTTPConnectionParams": {
|
|
52
|
+
const options = (_a = this.connectionParams.transportOptions) != null ? _a : {};
|
|
53
|
+
if (!options.requestInit && this.connectionParams.header !== void 0) {
|
|
54
|
+
options.requestInit = {
|
|
53
55
|
headers: this.connectionParams.header
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
await client.connect(
|
|
57
|
-
new
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
await client.connect(
|
|
59
|
+
new import_streamableHttp.StreamableHTTPClientTransport(
|
|
60
|
+
new URL(this.connectionParams.url),
|
|
61
|
+
options
|
|
62
|
+
)
|
|
63
|
+
);
|
|
60
64
|
break;
|
|
61
|
-
|
|
65
|
+
}
|
|
66
|
+
default: {
|
|
62
67
|
const _exhaustiveCheck = this.connectionParams;
|
|
63
68
|
break;
|
|
69
|
+
}
|
|
64
70
|
}
|
|
65
71
|
return client;
|
|
66
72
|
}
|