@google/adk 0.2.4 → 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 +52 -24
- 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/invocation_context.js +3 -1
- package/dist/cjs/agents/llm_agent.js +188 -108
- package/dist/cjs/agents/loop_agent.js +18 -6
- package/dist/cjs/agents/parallel_agent.js +20 -7
- package/dist/cjs/agents/readonly_context.js +4 -1
- package/dist/cjs/agents/sequential_agent.js +34 -12
- 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 +14 -2
- package/dist/cjs/code_executors/built_in_code_executor.js +21 -5
- package/dist/cjs/code_executors/code_executor_context.js +5 -5
- package/dist/cjs/common.js +45 -0
- package/dist/cjs/events/event.js +1 -3
- package/dist/cjs/examples/base_example_provider.js +18 -2
- package/dist/cjs/examples/example_util.js +1 -1
- 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 +71 -49
- 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 +5 -2
- package/dist/cjs/runner/runner.js +126 -101
- 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 +26 -13
- package/dist/cjs/tools/base_tool.js +19 -7
- package/dist/cjs/tools/forwarding_artifact_service.js +1 -1
- package/dist/cjs/tools/function_tool.js +15 -7
- package/dist/cjs/tools/google_search_tool.js +8 -4
- 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/tools/tool_context.js +4 -9
- package/dist/cjs/utils/env_aware_utils.js +1 -1
- package/dist/cjs/utils/gemini_schema_util.js +10 -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 +57 -25
- 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/invocation_context.js +3 -1
- package/dist/esm/agents/llm_agent.js +228 -116
- package/dist/esm/agents/loop_agent.js +16 -5
- package/dist/esm/agents/parallel_agent.js +18 -6
- package/dist/esm/agents/readonly_context.js +4 -1
- package/dist/esm/agents/sequential_agent.js +33 -12
- 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 +12 -1
- package/dist/esm/code_executors/built_in_code_executor.js +19 -4
- package/dist/esm/code_executors/code_executor_context.js +5 -5
- package/dist/esm/common.js +56 -11
- package/dist/esm/events/event.js +1 -3
- package/dist/esm/examples/base_example_provider.js +16 -1
- package/dist/esm/examples/example_util.js +4 -2
- 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 +71 -49
- 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 +5 -2
- package/dist/esm/runner/runner.js +139 -105
- 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 +25 -13
- package/dist/esm/tools/base_tool.js +17 -6
- package/dist/esm/tools/forwarding_artifact_service.js +1 -1
- package/dist/esm/tools/function_tool.js +13 -8
- package/dist/esm/tools/google_search_tool.js +6 -3
- 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/tools/tool_context.js +4 -9
- package/dist/esm/utils/env_aware_utils.js +1 -1
- package/dist/esm/utils/gemini_schema_util.js +10 -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 +16 -4
- package/dist/types/agents/callback_context.d.ts +1 -1
- package/dist/types/agents/invocation_context.d.ts +4 -2
- package/dist/types/agents/llm_agent.d.ts +43 -31
- package/dist/types/agents/loop_agent.d.ts +17 -1
- package/dist/types/agents/parallel_agent.d.ts +17 -1
- package/dist/types/agents/sequential_agent.d.ts +17 -1
- package/dist/types/artifacts/in_memory_artifact_service.d.ts +3 -3
- package/dist/types/auth/auth_schemes.d.ts +5 -2
- package/dist/types/code_executors/base_code_executor.d.ts +14 -0
- package/dist/types/code_executors/built_in_code_executor.d.ts +20 -1
- package/dist/types/code_executors/code_executor_context.d.ts +2 -4
- package/dist/types/common.d.ts +40 -15
- package/dist/types/examples/base_example_provider.d.ts +16 -0
- 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/base_plugin.d.ts +50 -40
- 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 +18 -10
- 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 +15 -1
- package/dist/types/tools/base_tool.d.ts +15 -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 +18 -4
- package/dist/types/tools/google_search_tool.d.ts +5 -6
- 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/tools/tool_context.d.ts +1 -1
- 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 +103 -36
- 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/invocation_context.js +3 -1
- package/dist/web/agents/llm_agent.js +282 -137
- package/dist/web/agents/loop_agent.js +16 -5
- package/dist/web/agents/parallel_agent.js +18 -6
- package/dist/web/agents/readonly_context.js +4 -1
- package/dist/web/agents/sequential_agent.js +33 -12
- 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 +12 -1
- package/dist/web/code_executors/built_in_code_executor.js +19 -4
- package/dist/web/code_executors/code_executor_context.js +5 -5
- package/dist/web/common.js +56 -11
- package/dist/web/events/event.js +1 -3
- package/dist/web/examples/base_example_provider.js +16 -1
- package/dist/web/examples/example_util.js +4 -2
- 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 +71 -49
- 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 +5 -2
- package/dist/web/runner/runner.js +186 -119
- 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 +25 -13
- package/dist/web/tools/base_tool.js +17 -6
- package/dist/web/tools/forwarding_artifact_service.js +1 -1
- package/dist/web/tools/function_tool.js +13 -8
- package/dist/web/tools/google_search_tool.js +6 -3
- 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/tools/tool_context.js +4 -9
- package/dist/web/utils/env_aware_utils.js +1 -1
- package/dist/web/utils/gemini_schema_util.js +10 -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 +5 -3
|
@@ -20,12 +20,21 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
|
|
|
20
20
|
* Copyright 2025 Google LLC
|
|
21
21
|
* SPDX-License-Identifier: Apache-2.0
|
|
22
22
|
*/
|
|
23
|
+
var _a, _b;
|
|
23
24
|
import { BaseAgent } from "./base_agent.js";
|
|
24
|
-
|
|
25
|
+
const LOOP_AGENT_SIGNATURE_SYMBOL = Symbol.for("google.adk.loopAgent");
|
|
26
|
+
function isLoopAgent(obj) {
|
|
27
|
+
return typeof obj === "object" && obj !== null && LOOP_AGENT_SIGNATURE_SYMBOL in obj && obj[LOOP_AGENT_SIGNATURE_SYMBOL] === true;
|
|
28
|
+
}
|
|
29
|
+
class LoopAgent extends (_b = BaseAgent, _a = LOOP_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
25
30
|
constructor(config) {
|
|
26
|
-
var
|
|
31
|
+
var _a2;
|
|
27
32
|
super(config);
|
|
28
|
-
|
|
33
|
+
/**
|
|
34
|
+
* A unique symbol to identify ADK loop agent class.
|
|
35
|
+
*/
|
|
36
|
+
this[_a] = true;
|
|
37
|
+
this.maxIterations = (_a2 = config.maxIterations) != null ? _a2 : Number.MAX_SAFE_INTEGER;
|
|
29
38
|
}
|
|
30
39
|
runAsyncImpl(context) {
|
|
31
40
|
return __asyncGenerator(this, null, function* () {
|
|
@@ -60,12 +69,14 @@ class LoopAgent extends BaseAgent {
|
|
|
60
69
|
return;
|
|
61
70
|
});
|
|
62
71
|
}
|
|
63
|
-
|
|
72
|
+
// eslint-disable-next-line require-yield
|
|
73
|
+
runLiveImpl(_context) {
|
|
64
74
|
return __asyncGenerator(this, null, function* () {
|
|
65
75
|
throw new Error("This is not supported yet for LoopAgent.");
|
|
66
76
|
});
|
|
67
77
|
}
|
|
68
78
|
}
|
|
69
79
|
export {
|
|
70
|
-
LoopAgent
|
|
80
|
+
LoopAgent,
|
|
81
|
+
isLoopAgent
|
|
71
82
|
};
|
|
@@ -20,15 +20,25 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
|
|
|
20
20
|
* Copyright 2025 Google LLC
|
|
21
21
|
* SPDX-License-Identifier: Apache-2.0
|
|
22
22
|
*/
|
|
23
|
+
var _a, _b;
|
|
23
24
|
import { BaseAgent } from "./base_agent.js";
|
|
24
25
|
import { InvocationContext } from "./invocation_context.js";
|
|
25
|
-
|
|
26
|
+
const PARALLEL_AGENT_SIGNATURE_SYMBOL = Symbol.for("google.adk.parallelAgent");
|
|
27
|
+
function isParallelAgent(obj) {
|
|
28
|
+
return typeof obj === "object" && obj !== null && PARALLEL_AGENT_SIGNATURE_SYMBOL in obj && obj[PARALLEL_AGENT_SIGNATURE_SYMBOL] === true;
|
|
29
|
+
}
|
|
30
|
+
class ParallelAgent extends (_b = BaseAgent, _a = PARALLEL_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
31
|
+
constructor() {
|
|
32
|
+
super(...arguments);
|
|
33
|
+
/**
|
|
34
|
+
* A unique symbol to identify ADK parallel agent class.
|
|
35
|
+
*/
|
|
36
|
+
this[_a] = true;
|
|
37
|
+
}
|
|
26
38
|
runAsyncImpl(context) {
|
|
27
39
|
return __asyncGenerator(this, null, function* () {
|
|
28
40
|
const agentRuns = this.subAgents.map(
|
|
29
|
-
(subAgent) => subAgent.runAsync(
|
|
30
|
-
createBranchCtxForSubAgent(this, subAgent, context)
|
|
31
|
-
)
|
|
41
|
+
(subAgent) => subAgent.runAsync(createBranchCtxForSubAgent(this, subAgent, context))
|
|
32
42
|
);
|
|
33
43
|
try {
|
|
34
44
|
for (var iter = __forAwait(mergeAgentRuns(agentRuns)), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
@@ -47,7 +57,8 @@ class ParallelAgent extends BaseAgent {
|
|
|
47
57
|
}
|
|
48
58
|
});
|
|
49
59
|
}
|
|
50
|
-
|
|
60
|
+
// eslint-disable-next-line require-yield
|
|
61
|
+
runLiveImpl(_context) {
|
|
51
62
|
return __asyncGenerator(this, null, function* () {
|
|
52
63
|
throw new Error("This is not supported yet for ParallelAgent.");
|
|
53
64
|
});
|
|
@@ -79,5 +90,6 @@ function mergeAgentRuns(agentRuns) {
|
|
|
79
90
|
});
|
|
80
91
|
}
|
|
81
92
|
export {
|
|
82
|
-
ParallelAgent
|
|
93
|
+
ParallelAgent,
|
|
94
|
+
isParallelAgent
|
|
83
95
|
};
|
|
@@ -20,12 +20,26 @@ var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")])
|
|
|
20
20
|
* Copyright 2025 Google LLC
|
|
21
21
|
* SPDX-License-Identifier: Apache-2.0
|
|
22
22
|
*/
|
|
23
|
+
var _a, _b;
|
|
23
24
|
import { FunctionTool } from "../tools/function_tool.js";
|
|
24
25
|
import { BaseAgent } from "./base_agent.js";
|
|
25
|
-
import {
|
|
26
|
+
import { isLlmAgent } from "./llm_agent.js";
|
|
26
27
|
import { ReadonlyContext } from "./readonly_context.js";
|
|
27
28
|
const TASK_COMPLETED_TOOL_NAME = "task_completed";
|
|
28
|
-
|
|
29
|
+
const SEQUENTIAL_AGENT_SIGNATURE_SYMBOL = Symbol.for(
|
|
30
|
+
"google.adk.sequentialAgent"
|
|
31
|
+
);
|
|
32
|
+
function isSequentialAgent(obj) {
|
|
33
|
+
return typeof obj === "object" && obj !== null && SEQUENTIAL_AGENT_SIGNATURE_SYMBOL in obj && obj[SEQUENTIAL_AGENT_SIGNATURE_SYMBOL] === true;
|
|
34
|
+
}
|
|
35
|
+
class SequentialAgent extends (_b = BaseAgent, _a = SEQUENTIAL_AGENT_SIGNATURE_SYMBOL, _b) {
|
|
36
|
+
constructor() {
|
|
37
|
+
super(...arguments);
|
|
38
|
+
/**
|
|
39
|
+
* A unique symbol to identify ADK sequential agent class.
|
|
40
|
+
*/
|
|
41
|
+
this[_a] = true;
|
|
42
|
+
}
|
|
29
43
|
runAsyncImpl(context) {
|
|
30
44
|
return __asyncGenerator(this, null, function* () {
|
|
31
45
|
for (const subAgent of this.subAgents) {
|
|
@@ -56,20 +70,26 @@ class SequentialAgent extends BaseAgent {
|
|
|
56
70
|
* the model can call this function to signal that it's finished the task and
|
|
57
71
|
* we can move on to the next agent.
|
|
58
72
|
*
|
|
59
|
-
* @param context
|
|
73
|
+
* @param context The invocation context of the agent.
|
|
60
74
|
*/
|
|
61
75
|
runLiveImpl(context) {
|
|
62
76
|
return __asyncGenerator(this, null, function* () {
|
|
63
77
|
for (const subAgent of this.subAgents) {
|
|
64
|
-
if (subAgent
|
|
65
|
-
const agentTools = yield new __await(subAgent.canonicalTools(
|
|
66
|
-
|
|
78
|
+
if (isLlmAgent(subAgent)) {
|
|
79
|
+
const agentTools = yield new __await(subAgent.canonicalTools(
|
|
80
|
+
new ReadonlyContext(context)
|
|
81
|
+
));
|
|
82
|
+
const taskCompletedToolAlreadyAdded = agentTools.some(
|
|
83
|
+
(tool) => tool.name === TASK_COMPLETED_TOOL_NAME
|
|
84
|
+
);
|
|
67
85
|
if (!taskCompletedToolAlreadyAdded) {
|
|
68
|
-
subAgent.tools.push(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
86
|
+
subAgent.tools.push(
|
|
87
|
+
new FunctionTool({
|
|
88
|
+
name: TASK_COMPLETED_TOOL_NAME,
|
|
89
|
+
description: "Signals that the model has successfully completed the user's question or task.",
|
|
90
|
+
execute: () => "Task completion signaled."
|
|
91
|
+
})
|
|
92
|
+
);
|
|
73
93
|
subAgent.instruction += "If you finished the user's request according to its description, call the ".concat(TASK_COMPLETED_TOOL_NAME, " function to exit so the next agents can take over. When calling this function, do not generate any text other than the function call.");
|
|
74
94
|
}
|
|
75
95
|
}
|
|
@@ -95,5 +115,6 @@ class SequentialAgent extends BaseAgent {
|
|
|
95
115
|
}
|
|
96
116
|
}
|
|
97
117
|
export {
|
|
98
|
-
SequentialAgent
|
|
118
|
+
SequentialAgent,
|
|
119
|
+
isSequentialAgent
|
|
99
120
|
};
|
|
@@ -31,9 +31,11 @@ class GcsArtifactService {
|
|
|
31
31
|
async saveArtifact(request) {
|
|
32
32
|
const versions = await this.listVersions(request);
|
|
33
33
|
const version = versions.length > 0 ? Math.max(...versions) + 1 : 0;
|
|
34
|
-
const file = this.bucket.file(
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
const file = this.bucket.file(
|
|
35
|
+
getFileName(__spreadProps(__spreadValues({}, request), {
|
|
36
|
+
version
|
|
37
|
+
}))
|
|
38
|
+
);
|
|
37
39
|
if (request.artifact.inlineData) {
|
|
38
40
|
await file.save(JSON.stringify(request.artifact.inlineData.data), {
|
|
39
41
|
contentType: request.artifact.inlineData.mimeType
|
|
@@ -57,10 +59,15 @@ class GcsArtifactService {
|
|
|
57
59
|
}
|
|
58
60
|
version = Math.max(...versions);
|
|
59
61
|
}
|
|
60
|
-
const file = this.bucket.file(
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
const file = this.bucket.file(
|
|
63
|
+
getFileName(__spreadProps(__spreadValues({}, request), {
|
|
64
|
+
version
|
|
65
|
+
}))
|
|
66
|
+
);
|
|
67
|
+
const [[metadata], [rawDataBuffer]] = await Promise.all([
|
|
68
|
+
file.getMetadata(),
|
|
69
|
+
file.download()
|
|
70
|
+
]);
|
|
64
71
|
if (metadata.contentType === "text/plain") {
|
|
65
72
|
return createPartFromText(rawDataBuffer.toString("utf-8"));
|
|
66
73
|
}
|
|
@@ -73,10 +80,7 @@ class GcsArtifactService {
|
|
|
73
80
|
const fileNames = [];
|
|
74
81
|
const sessionPrefix = "".concat(request.appName, "/").concat(request.userId, "/").concat(request.sessionId, "/");
|
|
75
82
|
const usernamePrefix = "".concat(request.appName, "/").concat(request.userId, "/user/");
|
|
76
|
-
const [
|
|
77
|
-
[sessionFiles],
|
|
78
|
-
[userSessionFiles]
|
|
79
|
-
] = await Promise.all([
|
|
83
|
+
const [[sessionFiles], [userSessionFiles]] = await Promise.all([
|
|
80
84
|
this.bucket.getFiles({ prefix: sessionPrefix }),
|
|
81
85
|
this.bucket.getFiles({ prefix: usernamePrefix })
|
|
82
86
|
]);
|
|
@@ -90,12 +94,16 @@ class GcsArtifactService {
|
|
|
90
94
|
}
|
|
91
95
|
async deleteArtifact(request) {
|
|
92
96
|
const versions = await this.listVersions(request);
|
|
93
|
-
await Promise.all(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
await Promise.all(
|
|
98
|
+
versions.map((version) => {
|
|
99
|
+
const file = this.bucket.file(
|
|
100
|
+
getFileName(__spreadProps(__spreadValues({}, request), {
|
|
101
|
+
version
|
|
102
|
+
}))
|
|
103
|
+
);
|
|
104
|
+
return file.delete();
|
|
105
|
+
})
|
|
106
|
+
);
|
|
99
107
|
return;
|
|
100
108
|
}
|
|
101
109
|
async listVersions(request) {
|
|
@@ -39,7 +39,11 @@ class InMemoryArtifactService {
|
|
|
39
39
|
}
|
|
40
40
|
return Promise.resolve(versions[version]);
|
|
41
41
|
}
|
|
42
|
-
listArtifactKeys({
|
|
42
|
+
listArtifactKeys({
|
|
43
|
+
appName,
|
|
44
|
+
userId,
|
|
45
|
+
sessionId
|
|
46
|
+
}) {
|
|
43
47
|
const sessionPrefix = "".concat(appName, "/").concat(userId, "/").concat(sessionId, "/");
|
|
44
48
|
const usernamespacePrefix = "".concat(appName, "/").concat(userId, "/user/");
|
|
45
49
|
const filenames = [];
|
|
@@ -54,7 +58,12 @@ class InMemoryArtifactService {
|
|
|
54
58
|
}
|
|
55
59
|
return Promise.resolve(filenames.sort());
|
|
56
60
|
}
|
|
57
|
-
deleteArtifact({
|
|
61
|
+
deleteArtifact({
|
|
62
|
+
appName,
|
|
63
|
+
userId,
|
|
64
|
+
sessionId,
|
|
65
|
+
filename
|
|
66
|
+
}) {
|
|
58
67
|
const path = artifactPath(appName, userId, sessionId, filename);
|
|
59
68
|
if (!this.artifacts[path]) {
|
|
60
69
|
return Promise.resolve();
|
|
@@ -62,13 +71,18 @@ class InMemoryArtifactService {
|
|
|
62
71
|
delete this.artifacts[path];
|
|
63
72
|
return Promise.resolve();
|
|
64
73
|
}
|
|
65
|
-
listVersions({
|
|
74
|
+
listVersions({
|
|
75
|
+
appName,
|
|
76
|
+
userId,
|
|
77
|
+
sessionId,
|
|
78
|
+
filename
|
|
79
|
+
}) {
|
|
66
80
|
const path = artifactPath(appName, userId, sessionId, filename);
|
|
67
81
|
const artifacts = this.artifacts[path];
|
|
68
82
|
if (!artifacts) {
|
|
69
83
|
return Promise.resolve([]);
|
|
70
84
|
}
|
|
71
|
-
|
|
85
|
+
const versions = [];
|
|
72
86
|
for (let i = 0; i < artifacts.length; i++) {
|
|
73
87
|
versions.push(i);
|
|
74
88
|
}
|
|
@@ -37,7 +37,9 @@ class AuthHandler {
|
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
if (!this.authConfig.rawAuthCredential.oauth2.clientId || !this.authConfig.rawAuthCredential.oauth2.clientSecret) {
|
|
40
|
-
throw new Error(
|
|
40
|
+
throw new Error(
|
|
41
|
+
"Auth Scheme ".concat(authSchemeType, " requires both clientId and clientSecret in authCredential.oauth2.")
|
|
42
|
+
);
|
|
41
43
|
}
|
|
42
44
|
return {
|
|
43
45
|
credentialKey: this.authConfig.credentialKey,
|
|
@@ -3,8 +3,18 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
var _a;
|
|
7
|
+
const BASE_CODE_EXECUTOR_SIGNATURE_SYMBOL = Symbol.for(
|
|
8
|
+
"google.adk.baseCodeExecutor"
|
|
9
|
+
);
|
|
10
|
+
function isBaseCodeExecutor(obj) {
|
|
11
|
+
return typeof obj === "object" && obj !== null && BASE_CODE_EXECUTOR_SIGNATURE_SYMBOL in obj && obj[BASE_CODE_EXECUTOR_SIGNATURE_SYMBOL] === true;
|
|
12
|
+
}
|
|
13
|
+
_a = BASE_CODE_EXECUTOR_SIGNATURE_SYMBOL;
|
|
6
14
|
class BaseCodeExecutor {
|
|
7
15
|
constructor() {
|
|
16
|
+
/** A unique symbol to identify BaseCodeExecutor class. */
|
|
17
|
+
this[_a] = true;
|
|
8
18
|
/**
|
|
9
19
|
* If true, extract and process data files from the model request
|
|
10
20
|
* and attach them to the code executor.
|
|
@@ -42,5 +52,6 @@ class BaseCodeExecutor {
|
|
|
42
52
|
}
|
|
43
53
|
}
|
|
44
54
|
export {
|
|
45
|
-
BaseCodeExecutor
|
|
55
|
+
BaseCodeExecutor,
|
|
56
|
+
isBaseCodeExecutor
|
|
46
57
|
};
|
|
@@ -3,10 +3,22 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
var _a, _b;
|
|
6
7
|
import { isGemini2OrAbove } from "../utils/model_name.js";
|
|
7
8
|
import { BaseCodeExecutor } from "./base_code_executor.js";
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
const BUILT_IN_CODE_EXECUTOR_SIGNATURE_SYMBOL = Symbol.for(
|
|
10
|
+
"google.adk.builtInCodeExecutor"
|
|
11
|
+
);
|
|
12
|
+
function isBuiltInCodeExecutor(obj) {
|
|
13
|
+
return typeof obj === "object" && obj !== null && BUILT_IN_CODE_EXECUTOR_SIGNATURE_SYMBOL in obj && obj[BUILT_IN_CODE_EXECUTOR_SIGNATURE_SYMBOL] === true;
|
|
14
|
+
}
|
|
15
|
+
class BuiltInCodeExecutor extends (_b = BaseCodeExecutor, _a = BUILT_IN_CODE_EXECUTOR_SIGNATURE_SYMBOL, _b) {
|
|
16
|
+
constructor() {
|
|
17
|
+
super(...arguments);
|
|
18
|
+
/** A unique symbol to identify BuiltInCodeExecutor class. */
|
|
19
|
+
this[_a] = true;
|
|
20
|
+
}
|
|
21
|
+
executeCode(_params) {
|
|
10
22
|
return Promise.resolve({
|
|
11
23
|
stdout: "",
|
|
12
24
|
stderr: "",
|
|
@@ -20,9 +32,12 @@ class BuiltInCodeExecutor extends BaseCodeExecutor {
|
|
|
20
32
|
llmRequest.config.tools.push({ codeExecution: {} });
|
|
21
33
|
return;
|
|
22
34
|
}
|
|
23
|
-
throw new Error(
|
|
35
|
+
throw new Error(
|
|
36
|
+
"Gemini code execution tool is not supported for model ".concat(llmRequest.model)
|
|
37
|
+
);
|
|
24
38
|
}
|
|
25
39
|
}
|
|
26
40
|
export {
|
|
27
|
-
BuiltInCodeExecutor
|
|
41
|
+
BuiltInCodeExecutor,
|
|
42
|
+
isBuiltInCodeExecutor
|
|
28
43
|
};
|
|
@@ -142,7 +142,9 @@ class CodeExecutorContext {
|
|
|
142
142
|
if (!(CODE_EXECUTION_RESULTS_KEY in this.sessionState)) {
|
|
143
143
|
this.sessionState.set(CODE_EXECUTION_RESULTS_KEY, {});
|
|
144
144
|
}
|
|
145
|
-
const codeExecutionResults = this.sessionState.get(
|
|
145
|
+
const codeExecutionResults = this.sessionState.get(
|
|
146
|
+
CODE_EXECUTION_RESULTS_KEY
|
|
147
|
+
);
|
|
146
148
|
if (!(invocationId in codeExecutionResults)) {
|
|
147
149
|
codeExecutionResults[invocationId] = [];
|
|
148
150
|
}
|
|
@@ -154,12 +156,10 @@ class CodeExecutorContext {
|
|
|
154
156
|
});
|
|
155
157
|
}
|
|
156
158
|
/**
|
|
157
|
-
* Gets the code
|
|
158
|
-
* @param invocationId The session state to get the code executor context
|
|
159
|
-
* from.
|
|
159
|
+
* Gets the code execution context from the session state.
|
|
160
160
|
* @return The code execution context for the given invocation ID.
|
|
161
161
|
*/
|
|
162
|
-
getCodeExecutionContext(
|
|
162
|
+
getCodeExecutionContext() {
|
|
163
163
|
return this.sessionState.get(CONTEXT_KEY) || {};
|
|
164
164
|
}
|
|
165
165
|
}
|
package/dist/web/common.js
CHANGED
|
@@ -3,20 +3,39 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { ActiveStreamingTool } from "./agents/active_streaming_tool.js";
|
|
6
7
|
import { BaseAgent, isBaseAgent } from "./agents/base_agent.js";
|
|
8
|
+
import {
|
|
9
|
+
BaseLlmRequestProcessor,
|
|
10
|
+
BaseLlmResponseProcessor
|
|
11
|
+
} from "./agents/base_llm_processor.js";
|
|
7
12
|
import { CallbackContext } from "./agents/callback_context.js";
|
|
8
13
|
import { functionsExportedForTestingOnly } from "./agents/functions.js";
|
|
9
14
|
import { InvocationContext } from "./agents/invocation_context.js";
|
|
10
15
|
import { LiveRequestQueue } from "./agents/live_request_queue.js";
|
|
11
|
-
import { LlmAgent } from "./agents/llm_agent.js";
|
|
12
|
-
import { LoopAgent } from "./agents/loop_agent.js";
|
|
13
|
-
import { ParallelAgent } from "./agents/parallel_agent.js";
|
|
16
|
+
import { LlmAgent, isLlmAgent } from "./agents/llm_agent.js";
|
|
17
|
+
import { LoopAgent, isLoopAgent } from "./agents/loop_agent.js";
|
|
18
|
+
import { ParallelAgent, isParallelAgent } from "./agents/parallel_agent.js";
|
|
19
|
+
import { ReadonlyContext } from "./agents/readonly_context.js";
|
|
14
20
|
import { StreamingMode } from "./agents/run_config.js";
|
|
15
|
-
import { SequentialAgent } from "./agents/sequential_agent.js";
|
|
21
|
+
import { SequentialAgent, isSequentialAgent } from "./agents/sequential_agent.js";
|
|
16
22
|
import { InMemoryArtifactService } from "./artifacts/in_memory_artifact_service.js";
|
|
23
|
+
import { AuthCredentialTypes } from "./auth/auth_credential.js";
|
|
24
|
+
import { BaseCodeExecutor } from "./code_executors/base_code_executor.js";
|
|
17
25
|
import { BuiltInCodeExecutor } from "./code_executors/built_in_code_executor.js";
|
|
18
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
createEvent,
|
|
28
|
+
getFunctionCalls,
|
|
29
|
+
getFunctionResponses,
|
|
30
|
+
hasTrailingCodeExecutionResult,
|
|
31
|
+
isFinalResponse,
|
|
32
|
+
stringifyContent
|
|
33
|
+
} from "./events/event.js";
|
|
19
34
|
import { createEventActions } from "./events/event_actions.js";
|
|
35
|
+
import {
|
|
36
|
+
BaseExampleProvider,
|
|
37
|
+
isBaseExampleProvider
|
|
38
|
+
} from "./examples/base_example_provider.js";
|
|
20
39
|
import { InMemoryMemoryService } from "./memory/in_memory_memory_service.js";
|
|
21
40
|
import { BaseLlm, isBaseLlm } from "./models/base_llm.js";
|
|
22
41
|
import { Gemini } from "./models/google_llm.js";
|
|
@@ -24,32 +43,45 @@ import { LLMRegistry } from "./models/registry.js";
|
|
|
24
43
|
import { BasePlugin } from "./plugins/base_plugin.js";
|
|
25
44
|
import { LoggingPlugin } from "./plugins/logging_plugin.js";
|
|
26
45
|
import { PluginManager } from "./plugins/plugin_manager.js";
|
|
27
|
-
import {
|
|
46
|
+
import {
|
|
47
|
+
InMemoryPolicyEngine,
|
|
48
|
+
PolicyOutcome,
|
|
49
|
+
REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
|
|
50
|
+
SecurityPlugin,
|
|
51
|
+
getAskUserConfirmationFunctionCalls
|
|
52
|
+
} from "./plugins/security_plugin.js";
|
|
28
53
|
import { InMemoryRunner } from "./runner/in_memory_runner.js";
|
|
29
54
|
import { Runner } from "./runner/runner.js";
|
|
30
55
|
import { InMemorySessionService } from "./sessions/in_memory_session_service.js";
|
|
31
56
|
import { createSession } from "./sessions/session.js";
|
|
32
57
|
import { State } from "./sessions/state.js";
|
|
33
|
-
import { AgentTool } from "./tools/agent_tool.js";
|
|
34
|
-
import { BaseTool } from "./tools/base_tool.js";
|
|
58
|
+
import { AgentTool, isAgentTool } from "./tools/agent_tool.js";
|
|
59
|
+
import { BaseTool, isBaseTool } from "./tools/base_tool.js";
|
|
35
60
|
import { BaseToolset } from "./tools/base_toolset.js";
|
|
36
|
-
import { FunctionTool } from "./tools/function_tool.js";
|
|
37
|
-
import { GOOGLE_SEARCH } from "./tools/google_search_tool.js";
|
|
61
|
+
import { FunctionTool, isFunctionTool } from "./tools/function_tool.js";
|
|
62
|
+
import { GOOGLE_SEARCH, GoogleSearchTool } from "./tools/google_search_tool.js";
|
|
38
63
|
import { LongRunningFunctionTool } from "./tools/long_running_tool.js";
|
|
39
64
|
import { ToolConfirmation } from "./tools/tool_confirmation.js";
|
|
40
65
|
import { ToolContext } from "./tools/tool_context.js";
|
|
41
|
-
import { LogLevel, setLogLevel } from "./utils/logger.js";
|
|
66
|
+
import { LogLevel, getLogger, setLogLevel, setLogger } from "./utils/logger.js";
|
|
42
67
|
import { isGemini2OrAbove } from "./utils/model_name.js";
|
|
43
68
|
import { zodObjectToSchema } from "./utils/simple_zod_to_json.js";
|
|
69
|
+
import { GoogleLLMVariant } from "./utils/variant_utils.js";
|
|
44
70
|
import { version } from "./version.js";
|
|
45
71
|
export * from "./artifacts/base_artifact_service.js";
|
|
46
72
|
export * from "./memory/base_memory_service.js";
|
|
47
73
|
export * from "./sessions/base_session_service.js";
|
|
48
74
|
export * from "./tools/base_tool.js";
|
|
49
75
|
export {
|
|
76
|
+
ActiveStreamingTool,
|
|
50
77
|
AgentTool,
|
|
78
|
+
AuthCredentialTypes,
|
|
51
79
|
BaseAgent,
|
|
80
|
+
BaseCodeExecutor,
|
|
81
|
+
BaseExampleProvider,
|
|
52
82
|
BaseLlm,
|
|
83
|
+
BaseLlmRequestProcessor,
|
|
84
|
+
BaseLlmResponseProcessor,
|
|
53
85
|
BasePlugin,
|
|
54
86
|
BaseTool,
|
|
55
87
|
BaseToolset,
|
|
@@ -58,6 +90,8 @@ export {
|
|
|
58
90
|
FunctionTool,
|
|
59
91
|
GOOGLE_SEARCH,
|
|
60
92
|
Gemini,
|
|
93
|
+
GoogleLLMVariant,
|
|
94
|
+
GoogleSearchTool,
|
|
61
95
|
InMemoryArtifactService,
|
|
62
96
|
InMemoryMemoryService,
|
|
63
97
|
InMemoryPolicyEngine,
|
|
@@ -75,6 +109,7 @@ export {
|
|
|
75
109
|
PluginManager,
|
|
76
110
|
PolicyOutcome,
|
|
77
111
|
REQUEST_CONFIRMATION_FUNCTION_CALL_NAME,
|
|
112
|
+
ReadonlyContext,
|
|
78
113
|
Runner,
|
|
79
114
|
SecurityPlugin,
|
|
80
115
|
SequentialAgent,
|
|
@@ -89,12 +124,22 @@ export {
|
|
|
89
124
|
getAskUserConfirmationFunctionCalls,
|
|
90
125
|
getFunctionCalls,
|
|
91
126
|
getFunctionResponses,
|
|
127
|
+
getLogger,
|
|
92
128
|
hasTrailingCodeExecutionResult,
|
|
129
|
+
isAgentTool,
|
|
93
130
|
isBaseAgent,
|
|
131
|
+
isBaseExampleProvider,
|
|
94
132
|
isBaseLlm,
|
|
133
|
+
isBaseTool,
|
|
95
134
|
isFinalResponse,
|
|
135
|
+
isFunctionTool,
|
|
96
136
|
isGemini2OrAbove,
|
|
137
|
+
isLlmAgent,
|
|
138
|
+
isLoopAgent,
|
|
139
|
+
isParallelAgent,
|
|
140
|
+
isSequentialAgent,
|
|
97
141
|
setLogLevel,
|
|
142
|
+
setLogger,
|
|
98
143
|
stringifyContent,
|
|
99
144
|
version,
|
|
100
145
|
zodObjectToSchema
|
package/dist/web/events/event.js
CHANGED
|
@@ -84,9 +84,7 @@ const ASCII_LETTERS_AND_NUMBERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRS
|
|
|
84
84
|
function createNewEventId() {
|
|
85
85
|
let id = "";
|
|
86
86
|
for (let i = 0; i < 8; i++) {
|
|
87
|
-
id += ASCII_LETTERS_AND_NUMBERS[Math.floor(
|
|
88
|
-
Math.random() * ASCII_LETTERS_AND_NUMBERS.length
|
|
89
|
-
)];
|
|
87
|
+
id += ASCII_LETTERS_AND_NUMBERS[Math.floor(Math.random() * ASCII_LETTERS_AND_NUMBERS.length)];
|
|
90
88
|
}
|
|
91
89
|
return id;
|
|
92
90
|
}
|
|
@@ -3,8 +3,23 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
var _a;
|
|
7
|
+
const BASE_EXAMPLE_PROVIDER_SIGNATURE_SYMBOL = Symbol.for(
|
|
8
|
+
"google.adk.baseExampleProvider"
|
|
9
|
+
);
|
|
10
|
+
function isBaseExampleProvider(obj) {
|
|
11
|
+
return typeof obj === "object" && obj !== null && BASE_EXAMPLE_PROVIDER_SIGNATURE_SYMBOL in obj && obj[BASE_EXAMPLE_PROVIDER_SIGNATURE_SYMBOL] === true;
|
|
12
|
+
}
|
|
13
|
+
_a = BASE_EXAMPLE_PROVIDER_SIGNATURE_SYMBOL;
|
|
6
14
|
class BaseExampleProvider {
|
|
15
|
+
constructor() {
|
|
16
|
+
/**
|
|
17
|
+
* A unique symbol to identify ADK example provider classes.
|
|
18
|
+
*/
|
|
19
|
+
this[_a] = true;
|
|
20
|
+
}
|
|
7
21
|
}
|
|
8
22
|
export {
|
|
9
|
-
BaseExampleProvider
|
|
23
|
+
BaseExampleProvider,
|
|
24
|
+
isBaseExampleProvider
|
|
10
25
|
};
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
isBaseExampleProvider
|
|
8
|
+
} from "./base_example_provider.js";
|
|
7
9
|
const EXAMPLES_INTRO = "<EXAMPLES>\nBegin few-shot\nThe following are examples of user queries and model responses using the available tools.\n\n";
|
|
8
10
|
const EXAMPLES_END = "End few-shot\n<EXAMPLES>";
|
|
9
11
|
const EXAMPLE_START = "EXAMPLE {}:\nBegin example\n";
|
|
@@ -64,7 +66,7 @@ function buildExampleSi(examples, query, model) {
|
|
|
64
66
|
if (Array.isArray(examples)) {
|
|
65
67
|
return convertExamplesToText(examples, model);
|
|
66
68
|
}
|
|
67
|
-
if (examples
|
|
69
|
+
if (isBaseExampleProvider(examples)) {
|
|
68
70
|
return convertExamplesToText(examples.getExamples(query), model);
|
|
69
71
|
}
|
|
70
72
|
throw new Error("Invalid example configuration");
|