@google/adk 0.2.4 → 0.2.5

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.
Files changed (92) hide show
  1. package/dist/cjs/agents/base_agent.js +9 -3
  2. package/dist/cjs/agents/invocation_context.js +3 -1
  3. package/dist/cjs/agents/llm_agent.js +129 -75
  4. package/dist/cjs/agents/loop_agent.js +16 -5
  5. package/dist/cjs/agents/parallel_agent.js +17 -3
  6. package/dist/cjs/agents/readonly_context.js +4 -1
  7. package/dist/cjs/agents/sequential_agent.js +34 -12
  8. package/dist/cjs/code_executors/base_code_executor.js +12 -2
  9. package/dist/cjs/code_executors/built_in_code_executor.js +15 -3
  10. package/dist/cjs/common.js +41 -0
  11. package/dist/cjs/examples/base_example_provider.js +18 -2
  12. package/dist/cjs/examples/example_util.js +1 -1
  13. package/dist/cjs/index.js +11 -11
  14. package/dist/cjs/index.js.map +4 -4
  15. package/dist/cjs/plugins/base_plugin.js +59 -49
  16. package/dist/cjs/plugins/security_plugin.js +4 -1
  17. package/dist/cjs/runner/runner.js +34 -24
  18. package/dist/cjs/tools/agent_tool.js +18 -9
  19. package/dist/cjs/tools/base_tool.js +16 -6
  20. package/dist/cjs/tools/function_tool.js +14 -5
  21. package/dist/cjs/tools/google_search_tool.js +8 -3
  22. package/dist/cjs/tools/tool_context.js +4 -9
  23. package/dist/cjs/utils/gemini_schema_util.js +1 -0
  24. package/dist/cjs/version.js +1 -1
  25. package/dist/esm/agents/base_agent.js +9 -3
  26. package/dist/esm/agents/invocation_context.js +3 -1
  27. package/dist/esm/agents/llm_agent.js +165 -83
  28. package/dist/esm/agents/loop_agent.js +14 -4
  29. package/dist/esm/agents/parallel_agent.js +15 -2
  30. package/dist/esm/agents/readonly_context.js +4 -1
  31. package/dist/esm/agents/sequential_agent.js +33 -12
  32. package/dist/esm/code_executors/base_code_executor.js +10 -1
  33. package/dist/esm/code_executors/built_in_code_executor.js +13 -2
  34. package/dist/esm/common.js +53 -10
  35. package/dist/esm/examples/base_example_provider.js +16 -1
  36. package/dist/esm/examples/example_util.js +4 -2
  37. package/dist/esm/index.js +11 -11
  38. package/dist/esm/index.js.map +4 -4
  39. package/dist/esm/plugins/base_plugin.js +59 -49
  40. package/dist/esm/plugins/security_plugin.js +4 -1
  41. package/dist/esm/runner/runner.js +43 -27
  42. package/dist/esm/tools/agent_tool.js +17 -9
  43. package/dist/esm/tools/base_tool.js +14 -5
  44. package/dist/esm/tools/function_tool.js +13 -7
  45. package/dist/esm/tools/google_search_tool.js +9 -3
  46. package/dist/esm/tools/tool_context.js +4 -9
  47. package/dist/esm/utils/gemini_schema_util.js +1 -0
  48. package/dist/esm/version.js +1 -1
  49. package/dist/types/agents/base_agent.d.ts +14 -3
  50. package/dist/types/agents/invocation_context.d.ts +4 -2
  51. package/dist/types/agents/llm_agent.d.ts +42 -30
  52. package/dist/types/agents/loop_agent.d.ts +16 -0
  53. package/dist/types/agents/parallel_agent.d.ts +16 -0
  54. package/dist/types/agents/sequential_agent.d.ts +17 -1
  55. package/dist/types/auth/auth_schemes.d.ts +5 -2
  56. package/dist/types/code_executors/base_code_executor.d.ts +14 -0
  57. package/dist/types/code_executors/built_in_code_executor.d.ts +19 -0
  58. package/dist/types/common.d.ts +38 -14
  59. package/dist/types/examples/base_example_provider.d.ts +16 -0
  60. package/dist/types/plugins/base_plugin.d.ts +50 -40
  61. package/dist/types/runner/runner.d.ts +17 -9
  62. package/dist/types/tools/agent_tool.d.ts +14 -0
  63. package/dist/types/tools/base_tool.d.ts +14 -0
  64. package/dist/types/tools/function_tool.d.ts +14 -1
  65. package/dist/types/tools/google_search_tool.d.ts +3 -4
  66. package/dist/types/tools/tool_context.d.ts +1 -1
  67. package/dist/types/version.d.ts +1 -1
  68. package/dist/web/agents/base_agent.js +9 -3
  69. package/dist/web/agents/invocation_context.js +3 -1
  70. package/dist/web/agents/llm_agent.js +165 -83
  71. package/dist/web/agents/loop_agent.js +14 -4
  72. package/dist/web/agents/parallel_agent.js +15 -2
  73. package/dist/web/agents/readonly_context.js +4 -1
  74. package/dist/web/agents/sequential_agent.js +33 -12
  75. package/dist/web/code_executors/base_code_executor.js +10 -1
  76. package/dist/web/code_executors/built_in_code_executor.js +13 -2
  77. package/dist/web/common.js +53 -10
  78. package/dist/web/examples/base_example_provider.js +16 -1
  79. package/dist/web/examples/example_util.js +4 -2
  80. package/dist/web/index.js +1 -1
  81. package/dist/web/index.js.map +4 -4
  82. package/dist/web/plugins/base_plugin.js +59 -49
  83. package/dist/web/plugins/security_plugin.js +4 -1
  84. package/dist/web/runner/runner.js +44 -28
  85. package/dist/web/tools/agent_tool.js +17 -9
  86. package/dist/web/tools/base_tool.js +14 -5
  87. package/dist/web/tools/function_tool.js +13 -7
  88. package/dist/web/tools/google_search_tool.js +9 -3
  89. package/dist/web/tools/tool_context.js +4 -9
  90. package/dist/web/utils/gemini_schema_util.js +1 -0
  91. package/dist/web/version.js +1 -1
  92. package/package.json +2 -2
@@ -3,12 +3,26 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
+ var _a, _b;
6
7
  import { FunctionTool } from "../tools/function_tool.js";
7
8
  import { BaseAgent } from "./base_agent.js";
8
- import { LlmAgent } from "./llm_agent.js";
9
+ import { isLlmAgent } from "./llm_agent.js";
9
10
  import { ReadonlyContext } from "./readonly_context.js";
10
11
  const TASK_COMPLETED_TOOL_NAME = "task_completed";
11
- class SequentialAgent extends BaseAgent {
12
+ const SEQUENTIAL_AGENT_SIGNATURE_SYMBOL = Symbol.for(
13
+ "google.adk.sequentialAgent"
14
+ );
15
+ function isSequentialAgent(obj) {
16
+ return typeof obj === "object" && obj !== null && SEQUENTIAL_AGENT_SIGNATURE_SYMBOL in obj && obj[SEQUENTIAL_AGENT_SIGNATURE_SYMBOL] === true;
17
+ }
18
+ class SequentialAgent extends (_b = BaseAgent, _a = SEQUENTIAL_AGENT_SIGNATURE_SYMBOL, _b) {
19
+ constructor() {
20
+ super(...arguments);
21
+ /**
22
+ * A unique symbol to identify ADK sequential agent class.
23
+ */
24
+ this[_a] = true;
25
+ }
12
26
  async *runAsyncImpl(context) {
13
27
  for (const subAgent of this.subAgents) {
14
28
  for await (const event of subAgent.runAsync(context)) {
@@ -25,19 +39,25 @@ class SequentialAgent extends BaseAgent {
25
39
  * the model can call this function to signal that it's finished the task and
26
40
  * we can move on to the next agent.
27
41
  *
28
- * @param context: The invocation context of the agent.
42
+ * @param context The invocation context of the agent.
29
43
  */
30
44
  async *runLiveImpl(context) {
31
45
  for (const subAgent of this.subAgents) {
32
- if (subAgent instanceof LlmAgent) {
33
- const agentTools = await subAgent.canonicalTools(new ReadonlyContext(context));
34
- const taskCompletedToolAlreadyAdded = agentTools.some((tool) => tool.name === TASK_COMPLETED_TOOL_NAME);
46
+ if (isLlmAgent(subAgent)) {
47
+ const agentTools = await subAgent.canonicalTools(
48
+ new ReadonlyContext(context)
49
+ );
50
+ const taskCompletedToolAlreadyAdded = agentTools.some(
51
+ (tool) => tool.name === TASK_COMPLETED_TOOL_NAME
52
+ );
35
53
  if (!taskCompletedToolAlreadyAdded) {
36
- subAgent.tools.push(new FunctionTool({
37
- name: TASK_COMPLETED_TOOL_NAME,
38
- description: `Signals that the model has successfully completed the user's question or task.`,
39
- execute: () => "Task completion signaled."
40
- }));
54
+ subAgent.tools.push(
55
+ new FunctionTool({
56
+ name: TASK_COMPLETED_TOOL_NAME,
57
+ description: `Signals that the model has successfully completed the user's question or task.`,
58
+ execute: () => "Task completion signaled."
59
+ })
60
+ );
41
61
  subAgent.instruction += `If you finished the user's request according to its description, call the ${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.`;
42
62
  }
43
63
  }
@@ -50,5 +70,6 @@ class SequentialAgent extends BaseAgent {
50
70
  }
51
71
  }
52
72
  export {
53
- SequentialAgent
73
+ SequentialAgent,
74
+ isSequentialAgent
54
75
  };
@@ -3,8 +3,16 @@
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("google.adk.baseCodeExecutor");
8
+ function isBaseCodeExecutor(obj) {
9
+ return typeof obj === "object" && obj !== null && BASE_CODE_EXECUTOR_SIGNATURE_SYMBOL in obj && obj[BASE_CODE_EXECUTOR_SIGNATURE_SYMBOL] === true;
10
+ }
11
+ _a = BASE_CODE_EXECUTOR_SIGNATURE_SYMBOL;
6
12
  class BaseCodeExecutor {
7
13
  constructor() {
14
+ /** A unique symbol to identify BaseCodeExecutor class. */
15
+ this[_a] = true;
8
16
  /**
9
17
  * If true, extract and process data files from the model request
10
18
  * and attach them to the code executor.
@@ -42,5 +50,6 @@ class BaseCodeExecutor {
42
50
  }
43
51
  }
44
52
  export {
45
- BaseCodeExecutor
53
+ BaseCodeExecutor,
54
+ isBaseCodeExecutor
46
55
  };
@@ -3,9 +3,19 @@
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
- class BuiltInCodeExecutor extends BaseCodeExecutor {
9
+ const BUILT_IN_CODE_EXECUTOR_SIGNATURE_SYMBOL = Symbol.for("google.adk.builtInCodeExecutor");
10
+ function isBuiltInCodeExecutor(obj) {
11
+ return typeof obj === "object" && obj !== null && BUILT_IN_CODE_EXECUTOR_SIGNATURE_SYMBOL in obj && obj[BUILT_IN_CODE_EXECUTOR_SIGNATURE_SYMBOL] === true;
12
+ }
13
+ class BuiltInCodeExecutor extends (_b = BaseCodeExecutor, _a = BUILT_IN_CODE_EXECUTOR_SIGNATURE_SYMBOL, _b) {
14
+ constructor() {
15
+ super(...arguments);
16
+ /** A unique symbol to identify BuiltInCodeExecutor class. */
17
+ this[_a] = true;
18
+ }
9
19
  executeCode(params) {
10
20
  return Promise.resolve({
11
21
  stdout: "",
@@ -24,5 +34,6 @@ class BuiltInCodeExecutor extends BaseCodeExecutor {
24
34
  }
25
35
  }
26
36
  export {
27
- BuiltInCodeExecutor
37
+ BuiltInCodeExecutor,
38
+ isBuiltInCodeExecutor
28
39
  };
@@ -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 { createEvent, getFunctionCalls, getFunctionResponses, hasTrailingCodeExecutionResult, isFinalResponse, stringifyContent } from "./events/event.js";
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 { getAskUserConfirmationFunctionCalls, InMemoryPolicyEngine, PolicyOutcome, REQUEST_CONFIRMATION_FUNCTION_CALL_NAME, SecurityPlugin } from "./plugins/security_plugin.js";
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
66
  import { LogLevel, setLogLevel } 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,
@@ -90,10 +125,18 @@ export {
90
125
  getFunctionCalls,
91
126
  getFunctionResponses,
92
127
  hasTrailingCodeExecutionResult,
128
+ isAgentTool,
93
129
  isBaseAgent,
130
+ isBaseExampleProvider,
94
131
  isBaseLlm,
132
+ isBaseTool,
95
133
  isFinalResponse,
134
+ isFunctionTool,
96
135
  isGemini2OrAbove,
136
+ isLlmAgent,
137
+ isLoopAgent,
138
+ isParallelAgent,
139
+ isSequentialAgent,
97
140
  setLogLevel,
98
141
  stringifyContent,
99
142
  version,
@@ -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 { BaseExampleProvider } from "./base_example_provider.js";
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";
@@ -65,7 +67,7 @@ function buildExampleSi(examples, query, model) {
65
67
  if (Array.isArray(examples)) {
66
68
  return convertExamplesToText(examples, model);
67
69
  }
68
- if (examples instanceof BaseExampleProvider) {
70
+ if (isBaseExampleProvider(examples)) {
69
71
  return convertExamplesToText(examples.getExamples(query), model);
70
72
  }
71
73
  throw new Error("Invalid example configuration");