@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.
Files changed (191) hide show
  1. package/dist/cjs/agents/base_agent.js +52 -24
  2. package/dist/cjs/agents/callback_context.js +4 -1
  3. package/dist/cjs/agents/content_processor_utils.js +15 -7
  4. package/dist/cjs/agents/functions.js +79 -29
  5. package/dist/cjs/agents/invocation_context.js +3 -1
  6. package/dist/cjs/agents/llm_agent.js +188 -108
  7. package/dist/cjs/agents/loop_agent.js +18 -6
  8. package/dist/cjs/agents/parallel_agent.js +20 -7
  9. package/dist/cjs/agents/readonly_context.js +4 -1
  10. package/dist/cjs/agents/sequential_agent.js +34 -12
  11. package/dist/cjs/artifacts/gcs_artifact_service.js +28 -20
  12. package/dist/cjs/artifacts/in_memory_artifact_service.js +18 -4
  13. package/dist/cjs/auth/auth_handler.js +3 -1
  14. package/dist/cjs/code_executors/base_code_executor.js +14 -2
  15. package/dist/cjs/code_executors/built_in_code_executor.js +21 -5
  16. package/dist/cjs/code_executors/code_executor_context.js +5 -5
  17. package/dist/cjs/common.js +45 -0
  18. package/dist/cjs/events/event.js +1 -3
  19. package/dist/cjs/examples/base_example_provider.js +18 -2
  20. package/dist/cjs/examples/example_util.js +1 -1
  21. package/dist/cjs/index.js +19 -19
  22. package/dist/cjs/index.js.map +4 -4
  23. package/dist/cjs/memory/in_memory_memory_service.js +3 -1
  24. package/dist/cjs/models/base_llm.js +8 -4
  25. package/dist/cjs/models/gemini_llm_connection.js +1 -0
  26. package/dist/cjs/models/google_llm.js +3 -3
  27. package/dist/cjs/plugins/base_plugin.js +71 -49
  28. package/dist/cjs/plugins/logging_plugin.js +50 -13
  29. package/dist/cjs/plugins/plugin_manager.js +56 -24
  30. package/dist/cjs/plugins/security_plugin.js +5 -2
  31. package/dist/cjs/runner/runner.js +126 -101
  32. package/dist/cjs/sessions/in_memory_session_service.js +38 -14
  33. package/dist/cjs/telemetry/google_cloud.js +7 -9
  34. package/dist/cjs/telemetry/setup.js +15 -7
  35. package/dist/cjs/telemetry/tracing.js +37 -15
  36. package/dist/cjs/tools/agent_tool.js +26 -13
  37. package/dist/cjs/tools/base_tool.js +19 -7
  38. package/dist/cjs/tools/forwarding_artifact_service.js +1 -1
  39. package/dist/cjs/tools/function_tool.js +15 -7
  40. package/dist/cjs/tools/google_search_tool.js +8 -4
  41. package/dist/cjs/tools/mcp/mcp_session_manager.js +16 -10
  42. package/dist/cjs/tools/mcp/mcp_tool.js +1 -3
  43. package/dist/cjs/tools/mcp/mcp_toolset.js +1 -1
  44. package/dist/cjs/tools/tool_context.js +4 -9
  45. package/dist/cjs/utils/env_aware_utils.js +1 -1
  46. package/dist/cjs/utils/gemini_schema_util.js +10 -4
  47. package/dist/cjs/utils/logger.js +47 -3
  48. package/dist/cjs/utils/simple_zod_to_json.js +100 -141
  49. package/dist/cjs/utils/variant_utils.js +1 -1
  50. package/dist/cjs/version.js +1 -1
  51. package/dist/esm/agents/base_agent.js +57 -25
  52. package/dist/esm/agents/callback_context.js +4 -1
  53. package/dist/esm/agents/content_processor_utils.js +25 -9
  54. package/dist/esm/agents/functions.js +83 -29
  55. package/dist/esm/agents/invocation_context.js +3 -1
  56. package/dist/esm/agents/llm_agent.js +228 -116
  57. package/dist/esm/agents/loop_agent.js +16 -5
  58. package/dist/esm/agents/parallel_agent.js +18 -6
  59. package/dist/esm/agents/readonly_context.js +4 -1
  60. package/dist/esm/agents/sequential_agent.js +33 -12
  61. package/dist/esm/artifacts/gcs_artifact_service.js +28 -20
  62. package/dist/esm/artifacts/in_memory_artifact_service.js +18 -4
  63. package/dist/esm/auth/auth_handler.js +3 -1
  64. package/dist/esm/code_executors/base_code_executor.js +12 -1
  65. package/dist/esm/code_executors/built_in_code_executor.js +19 -4
  66. package/dist/esm/code_executors/code_executor_context.js +5 -5
  67. package/dist/esm/common.js +56 -11
  68. package/dist/esm/events/event.js +1 -3
  69. package/dist/esm/examples/base_example_provider.js +16 -1
  70. package/dist/esm/examples/example_util.js +4 -2
  71. package/dist/esm/index.js +19 -19
  72. package/dist/esm/index.js.map +4 -4
  73. package/dist/esm/memory/in_memory_memory_service.js +3 -1
  74. package/dist/esm/models/base_llm.js +8 -4
  75. package/dist/esm/models/gemini_llm_connection.js +1 -0
  76. package/dist/esm/models/google_llm.js +8 -4
  77. package/dist/esm/plugins/base_plugin.js +71 -49
  78. package/dist/esm/plugins/logging_plugin.js +55 -14
  79. package/dist/esm/plugins/plugin_manager.js +56 -24
  80. package/dist/esm/plugins/security_plugin.js +5 -2
  81. package/dist/esm/runner/runner.js +139 -105
  82. package/dist/esm/sessions/in_memory_session_service.js +41 -15
  83. package/dist/esm/telemetry/google_cloud.js +7 -9
  84. package/dist/esm/telemetry/setup.js +23 -9
  85. package/dist/esm/telemetry/tracing.js +37 -15
  86. package/dist/esm/tools/agent_tool.js +25 -13
  87. package/dist/esm/tools/base_tool.js +17 -6
  88. package/dist/esm/tools/forwarding_artifact_service.js +1 -1
  89. package/dist/esm/tools/function_tool.js +13 -8
  90. package/dist/esm/tools/google_search_tool.js +6 -3
  91. package/dist/esm/tools/long_running_tool.js +3 -1
  92. package/dist/esm/tools/mcp/mcp_session_manager.js +22 -12
  93. package/dist/esm/tools/mcp/mcp_tool.js +1 -3
  94. package/dist/esm/tools/mcp/mcp_toolset.js +1 -1
  95. package/dist/esm/tools/tool_context.js +4 -9
  96. package/dist/esm/utils/env_aware_utils.js +1 -1
  97. package/dist/esm/utils/gemini_schema_util.js +10 -4
  98. package/dist/esm/utils/logger.js +43 -2
  99. package/dist/esm/utils/simple_zod_to_json.js +102 -141
  100. package/dist/esm/utils/variant_utils.js +1 -1
  101. package/dist/esm/version.js +1 -1
  102. package/dist/types/agents/base_agent.d.ts +16 -4
  103. package/dist/types/agents/callback_context.d.ts +1 -1
  104. package/dist/types/agents/invocation_context.d.ts +4 -2
  105. package/dist/types/agents/llm_agent.d.ts +43 -31
  106. package/dist/types/agents/loop_agent.d.ts +17 -1
  107. package/dist/types/agents/parallel_agent.d.ts +17 -1
  108. package/dist/types/agents/sequential_agent.d.ts +17 -1
  109. package/dist/types/artifacts/in_memory_artifact_service.d.ts +3 -3
  110. package/dist/types/auth/auth_schemes.d.ts +5 -2
  111. package/dist/types/code_executors/base_code_executor.d.ts +14 -0
  112. package/dist/types/code_executors/built_in_code_executor.d.ts +20 -1
  113. package/dist/types/code_executors/code_executor_context.d.ts +2 -4
  114. package/dist/types/common.d.ts +40 -15
  115. package/dist/types/examples/base_example_provider.d.ts +16 -0
  116. package/dist/types/index.d.ts +3 -3
  117. package/dist/types/models/base_llm_connection.d.ts +1 -1
  118. package/dist/types/models/llm_response.d.ts +1 -1
  119. package/dist/types/plugins/base_plugin.d.ts +50 -40
  120. package/dist/types/plugins/logging_plugin.d.ts +12 -12
  121. package/dist/types/plugins/plugin_manager.d.ts +12 -12
  122. package/dist/types/plugins/security_plugin.d.ts +1 -1
  123. package/dist/types/runner/runner.d.ts +18 -10
  124. package/dist/types/sessions/in_memory_session_service.d.ts +5 -5
  125. package/dist/types/telemetry/setup.d.ts +1 -1
  126. package/dist/types/telemetry/tracing.d.ts +7 -6
  127. package/dist/types/tools/agent_tool.d.ts +15 -1
  128. package/dist/types/tools/base_tool.d.ts +15 -1
  129. package/dist/types/tools/base_toolset.d.ts +2 -1
  130. package/dist/types/tools/forwarding_artifact_service.d.ts +2 -2
  131. package/dist/types/tools/function_tool.d.ts +18 -4
  132. package/dist/types/tools/google_search_tool.d.ts +5 -6
  133. package/dist/types/tools/mcp/mcp_session_manager.d.ts +10 -3
  134. package/dist/types/tools/mcp/mcp_toolset.d.ts +1 -2
  135. package/dist/types/tools/tool_context.d.ts +1 -1
  136. package/dist/types/utils/gemini_schema_util.d.ts +4 -12
  137. package/dist/types/utils/logger.d.ts +11 -10
  138. package/dist/types/utils/simple_zod_to_json.d.ts +5 -4
  139. package/dist/types/version.d.ts +1 -1
  140. package/dist/web/agents/base_agent.js +103 -36
  141. package/dist/web/agents/callback_context.js +4 -1
  142. package/dist/web/agents/content_processor_utils.js +25 -9
  143. package/dist/web/agents/functions.js +83 -29
  144. package/dist/web/agents/invocation_context.js +3 -1
  145. package/dist/web/agents/llm_agent.js +282 -137
  146. package/dist/web/agents/loop_agent.js +16 -5
  147. package/dist/web/agents/parallel_agent.js +18 -6
  148. package/dist/web/agents/readonly_context.js +4 -1
  149. package/dist/web/agents/sequential_agent.js +33 -12
  150. package/dist/web/artifacts/gcs_artifact_service.js +25 -17
  151. package/dist/web/artifacts/in_memory_artifact_service.js +18 -4
  152. package/dist/web/auth/auth_handler.js +3 -1
  153. package/dist/web/code_executors/base_code_executor.js +12 -1
  154. package/dist/web/code_executors/built_in_code_executor.js +19 -4
  155. package/dist/web/code_executors/code_executor_context.js +5 -5
  156. package/dist/web/common.js +56 -11
  157. package/dist/web/events/event.js +1 -3
  158. package/dist/web/examples/base_example_provider.js +16 -1
  159. package/dist/web/examples/example_util.js +4 -2
  160. package/dist/web/index.js +1 -1
  161. package/dist/web/index.js.map +4 -4
  162. package/dist/web/memory/in_memory_memory_service.js +3 -1
  163. package/dist/web/models/base_llm.js +8 -4
  164. package/dist/web/models/gemini_llm_connection.js +1 -0
  165. package/dist/web/models/google_llm.js +8 -4
  166. package/dist/web/plugins/base_plugin.js +71 -49
  167. package/dist/web/plugins/logging_plugin.js +55 -14
  168. package/dist/web/plugins/plugin_manager.js +56 -24
  169. package/dist/web/plugins/security_plugin.js +5 -2
  170. package/dist/web/runner/runner.js +186 -119
  171. package/dist/web/sessions/in_memory_session_service.js +41 -15
  172. package/dist/web/telemetry/google_cloud.js +7 -9
  173. package/dist/web/telemetry/setup.js +23 -9
  174. package/dist/web/telemetry/tracing.js +37 -15
  175. package/dist/web/tools/agent_tool.js +25 -13
  176. package/dist/web/tools/base_tool.js +17 -6
  177. package/dist/web/tools/forwarding_artifact_service.js +1 -1
  178. package/dist/web/tools/function_tool.js +13 -8
  179. package/dist/web/tools/google_search_tool.js +6 -3
  180. package/dist/web/tools/long_running_tool.js +3 -1
  181. package/dist/web/tools/mcp/mcp_session_manager.js +22 -12
  182. package/dist/web/tools/mcp/mcp_tool.js +1 -3
  183. package/dist/web/tools/mcp/mcp_toolset.js +1 -1
  184. package/dist/web/tools/tool_context.js +4 -9
  185. package/dist/web/utils/env_aware_utils.js +1 -1
  186. package/dist/web/utils/gemini_schema_util.js +10 -4
  187. package/dist/web/utils/logger.js +43 -2
  188. package/dist/web/utils/simple_zod_to_json.js +102 -155
  189. package/dist/web/utils/variant_utils.js +1 -1
  190. package/dist/web/version.js +1 -1
  191. package/package.json +5 -3
@@ -4,155 +4,116 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
  import { Type } from "@google/genai";
7
- import { z } from "zod";
8
- function isZodObject(obj) {
9
- var _a;
10
- return obj !== null && typeof obj === "object" && ((_a = obj._def) == null ? void 0 : _a.typeName) === "ZodObject";
7
+ import {
8
+ zodToJsonSchema as toJSONSchemaV3
9
+ } from "zod-to-json-schema";
10
+ import { toJSONSchema as toJSONSchemaV4 } from "zod/v4";
11
+ function isZodSchema(obj) {
12
+ return obj !== null && typeof obj === "object" && "parse" in obj && typeof obj.parse === "function" && "safeParse" in obj && typeof obj.safeParse === "function";
13
+ }
14
+ function isZodV3Schema(obj) {
15
+ return isZodSchema(obj) && !("_zod" in obj);
16
+ }
17
+ function isZodV4Schema(obj) {
18
+ return isZodSchema(obj) && "_zod" in obj;
11
19
  }
12
- function parseZodType(zodType) {
13
- const def = zodType._def;
14
- if (!def) {
15
- return {};
20
+ function getZodTypeName(schema) {
21
+ var _a, _b;
22
+ const schemaAny = schema;
23
+ if ((_a = schemaAny._def) == null ? void 0 : _a.typeName) {
24
+ return schemaAny._def.typeName;
16
25
  }
17
- const description = def.description;
18
- const result = {};
19
- if (description) result.description = description;
20
- const returnResult = (result2) => {
21
- if (result2.description === void 0) {
22
- delete result2.description;
23
- }
24
- return result2;
25
- };
26
- switch (def.typeName) {
27
- case z.ZodFirstPartyTypeKind.ZodString:
28
- result.type = Type.STRING;
29
- for (const check of def.checks || []) {
30
- if (check.kind === "min")
31
- result.minLength = check.value.toString();
32
- else if (check.kind === "max")
33
- result.maxLength = check.value.toString();
34
- else if (check.kind === "email")
35
- result.format = "email";
36
- else if (check.kind === "uuid")
37
- result.format = "uuid";
38
- else if (check.kind === "url")
39
- result.format = "uri";
40
- else if (check.kind === "regex")
41
- result.pattern = check.regex.source;
42
- }
43
- return returnResult(result);
44
- case z.ZodFirstPartyTypeKind.ZodNumber:
45
- result.type = Type.NUMBER;
46
- for (const check of def.checks || []) {
47
- if (check.kind === "min")
48
- result.minimum = check.value;
49
- else if (check.kind === "max")
50
- result.maximum = check.value;
51
- else if (check.kind === "int")
52
- result.type = Type.INTEGER;
53
- }
54
- return returnResult(result);
55
- case z.ZodFirstPartyTypeKind.ZodBoolean:
56
- result.type = Type.BOOLEAN;
57
- return returnResult(result);
58
- case z.ZodFirstPartyTypeKind.ZodArray:
59
- result.type = Type.ARRAY;
60
- result.items = parseZodType(def.type);
61
- if (def.minLength) result.minItems = def.minLength.value.toString();
62
- if (def.maxLength) result.maxItems = def.maxLength.value.toString();
63
- return returnResult(result);
64
- case z.ZodFirstPartyTypeKind.ZodObject: {
65
- const nestedSchema = zodObjectToSchema(zodType);
66
- return nestedSchema;
67
- }
68
- case z.ZodFirstPartyTypeKind.ZodLiteral:
69
- const literalType = typeof def.value;
70
- result.enum = [def.value.toString()];
71
- if (literalType === "string") {
72
- result.type = Type.STRING;
73
- } else if (literalType === "number") {
74
- result.type = Type.NUMBER;
75
- } else if (literalType === "boolean") {
76
- result.type = Type.BOOLEAN;
77
- } else if (def.value === null) {
78
- result.type = Type.NULL;
79
- } else {
80
- throw new Error(`Unsupported ZodLiteral value type: ${literalType}`);
81
- }
82
- return returnResult(result);
83
- case z.ZodFirstPartyTypeKind.ZodEnum:
84
- result.type = Type.STRING;
85
- result.enum = def.values;
86
- return returnResult(result);
87
- case z.ZodFirstPartyTypeKind.ZodNativeEnum:
88
- result.type = Type.STRING;
89
- result.enum = Object.values(def.values);
90
- return returnResult(result);
91
- case z.ZodFirstPartyTypeKind.ZodUnion:
92
- result.anyOf = def.options.map(parseZodType);
93
- return returnResult(result);
94
- case z.ZodFirstPartyTypeKind.ZodOptional:
95
- return parseZodType(def.innerType);
96
- case z.ZodFirstPartyTypeKind.ZodNullable:
97
- const nullableInner = parseZodType(def.innerType);
98
- return nullableInner ? returnResult({
99
- anyOf: [nullableInner, { type: Type.NULL }],
100
- ...description && { description }
101
- }) : returnResult({ type: Type.NULL, ...description && { description } });
102
- case z.ZodFirstPartyTypeKind.ZodDefault:
103
- const defaultInner = parseZodType(def.innerType);
104
- if (defaultInner) defaultInner.default = def.defaultValue();
105
- return defaultInner;
106
- case z.ZodFirstPartyTypeKind.ZodBranded:
107
- return parseZodType(def.type);
108
- case z.ZodFirstPartyTypeKind.ZodReadonly:
109
- return parseZodType(def.innerType);
110
- case z.ZodFirstPartyTypeKind.ZodNull:
111
- result.type = Type.NULL;
112
- return returnResult(result);
113
- case z.ZodFirstPartyTypeKind.ZodAny:
114
- case z.ZodFirstPartyTypeKind.ZodUnknown:
115
- return returnResult({ ...description && { description } });
116
- default:
117
- throw new Error(`Unsupported Zod type: ${def.typeName}`);
26
+ const zod4Type = (_b = schemaAny._def) == null ? void 0 : _b.type;
27
+ if (typeof zod4Type === "string" && zod4Type) {
28
+ return "Zod" + zod4Type.charAt(0).toUpperCase() + zod4Type.slice(1);
118
29
  }
30
+ return void 0;
31
+ }
32
+ function isZodObject(obj) {
33
+ return isZodSchema(obj) && getZodTypeName(obj) === "ZodObject";
119
34
  }
120
35
  function zodObjectToSchema(schema) {
121
- if (schema._def.typeName !== z.ZodFirstPartyTypeKind.ZodObject) {
122
- throw new Error("Expected a ZodObject");
36
+ if (!isZodObject(schema)) {
37
+ throw new Error("Expected a Zod Object");
123
38
  }
124
- const shape = schema.shape;
125
- const properties = {};
126
- const required = [];
127
- for (const key in shape) {
128
- const fieldSchema = shape[key];
129
- const parsedField = parseZodType(fieldSchema);
130
- if (parsedField) {
131
- properties[key] = parsedField;
132
- }
133
- let currentSchema = fieldSchema;
134
- let isOptional = false;
135
- while (currentSchema._def.typeName === z.ZodFirstPartyTypeKind.ZodOptional || currentSchema._def.typeName === z.ZodFirstPartyTypeKind.ZodDefault) {
136
- isOptional = true;
137
- currentSchema = currentSchema._def.innerType;
138
- }
139
- if (!isOptional) {
140
- required.push(key);
141
- }
39
+ if (isZodV4Schema(schema)) {
40
+ return toJSONSchemaV4(schema, {
41
+ target: "openapi-3.0",
42
+ io: "input",
43
+ override: (ctx) => {
44
+ var _a;
45
+ const { jsonSchema } = ctx;
46
+ if (jsonSchema.additionalProperties !== void 0) {
47
+ delete jsonSchema.additionalProperties;
48
+ }
49
+ if (jsonSchema.readOnly !== void 0) {
50
+ delete jsonSchema.readOnly;
51
+ }
52
+ if (jsonSchema.maxItems !== void 0) {
53
+ jsonSchema.maxItems = jsonSchema.maxItems.toString();
54
+ }
55
+ if (jsonSchema.format === "email" || jsonSchema.format === "uuid") {
56
+ delete jsonSchema.pattern;
57
+ }
58
+ if (jsonSchema.minItems !== void 0) {
59
+ jsonSchema.minItems = jsonSchema.minItems.toString();
60
+ }
61
+ if (jsonSchema.minLength !== void 0) {
62
+ jsonSchema.minLength = jsonSchema.minLength.toString();
63
+ }
64
+ if (jsonSchema.maxLength !== void 0) {
65
+ jsonSchema.maxLength = jsonSchema.maxLength.toString();
66
+ }
67
+ if (((_a = jsonSchema.enum) == null ? void 0 : _a.length) === 1 && jsonSchema.enum[0] === null) {
68
+ jsonSchema.type = Type.NULL;
69
+ delete jsonSchema.enum;
70
+ }
71
+ if (jsonSchema.type !== void 0) {
72
+ jsonSchema.type = jsonSchema.type.toUpperCase();
73
+ }
74
+ }
75
+ });
142
76
  }
143
- const catchall = schema._def.catchall;
144
- let additionalProperties = false;
145
- if (catchall && catchall._def.typeName !== z.ZodFirstPartyTypeKind.ZodNever) {
146
- additionalProperties = parseZodType(catchall) || true;
147
- } else {
148
- additionalProperties = schema._def.unknownKeys === "passthrough";
77
+ if (isZodV3Schema(schema)) {
78
+ return toJSONSchemaV3(schema, {
79
+ target: "openApi3",
80
+ emailStrategy: "format:email",
81
+ postProcess: (jsonSchema) => {
82
+ var _a, _b, _c, _d, _e, _f, _g;
83
+ if (!jsonSchema) {
84
+ return;
85
+ }
86
+ if (jsonSchema.additionalProperties !== void 0) {
87
+ delete jsonSchema.additionalProperties;
88
+ }
89
+ if (jsonSchema.maxItems !== void 0) {
90
+ jsonSchema.maxItems = (_a = jsonSchema.maxItems) == null ? void 0 : _a.toString();
91
+ }
92
+ if (jsonSchema.minItems !== void 0) {
93
+ jsonSchema.minItems = (_b = jsonSchema.minItems) == null ? void 0 : _b.toString();
94
+ }
95
+ if (jsonSchema.minLength !== void 0) {
96
+ jsonSchema.minLength = (_c = jsonSchema.minLength) == null ? void 0 : _c.toString();
97
+ }
98
+ if (jsonSchema.maxLength !== void 0) {
99
+ jsonSchema.maxLength = (_d = jsonSchema.maxLength) == null ? void 0 : _d.toString();
100
+ }
101
+ if (((_e = jsonSchema.enum) == null ? void 0 : _e.length) === 1 && jsonSchema.enum[0] === "null") {
102
+ jsonSchema.type = Type.NULL;
103
+ delete jsonSchema.enum;
104
+ }
105
+ if (jsonSchema.type === "integer" && jsonSchema.format !== "int64") {
106
+ (_f = jsonSchema.minimum) != null ? _f : jsonSchema.minimum = Number.MIN_SAFE_INTEGER;
107
+ (_g = jsonSchema.maximum) != null ? _g : jsonSchema.maximum = Number.MAX_SAFE_INTEGER;
108
+ }
109
+ if (jsonSchema.type !== void 0) {
110
+ jsonSchema.type = jsonSchema.type.toUpperCase();
111
+ }
112
+ return jsonSchema;
113
+ }
114
+ });
149
115
  }
150
- return {
151
- type: Type.OBJECT,
152
- properties,
153
- required: required.length > 0 ? required : [],
154
- ...schema._def.description ? { description: schema._def.description } : {}
155
- };
116
+ throw new Error("Unsupported Zod schema version.");
156
117
  }
157
118
  export {
158
119
  isZodObject,
@@ -16,7 +16,7 @@ function getBooleanEnvVar(envVar) {
16
16
  return false;
17
17
  }
18
18
  const envVarValue = (process.env[envVar] || "").toLowerCase();
19
- return ["true", "1"].includes(envVar.toLowerCase());
19
+ return ["true", "1"].includes(envVarValue);
20
20
  }
21
21
  export {
22
22
  GoogleLLMVariant,
@@ -3,7 +3,7 @@
3
3
  * Copyright 2025 Google LLC
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
- const version = "0.2.4";
6
+ const version = "0.3.0";
7
7
  export {
8
8
  version
9
9
  };
@@ -7,9 +7,20 @@ import { Content } from '@google/genai';
7
7
  import { Event } from '../events/event.js';
8
8
  import { CallbackContext } from './callback_context.js';
9
9
  import { InvocationContext } from './invocation_context.js';
10
- type SingleAgentCallback = (context: CallbackContext) => Promise<Content | undefined> | (Content | undefined);
11
- type BeforeAgentCallback = SingleAgentCallback | SingleAgentCallback[];
12
- type AfterAgentCallback = SingleAgentCallback | SingleAgentCallback[];
10
+ /**
11
+ * A single callback function for an agent.
12
+ */
13
+ export type SingleAgentCallback = (context: CallbackContext) => Promise<Content | undefined> | (Content | undefined);
14
+ /**
15
+ * Type for before agent callbacks, which can be a single callback or
16
+ * an array of callbacks.
17
+ */
18
+ export type BeforeAgentCallback = SingleAgentCallback | SingleAgentCallback[];
19
+ /**
20
+ * Type for after agent callbacks, which can be a single callback or
21
+ * an array of callbacks.
22
+ */
23
+ export type AfterAgentCallback = SingleAgentCallback | SingleAgentCallback[];
13
24
  /**
14
25
  * The config of a base agent.
15
26
  */
@@ -55,8 +66,9 @@ export declare abstract class BaseAgent {
55
66
  readonly description?: string;
56
67
  /**
57
68
  * Root agent of this agent.
69
+ * Computed dynamically by traversing up the parent chain.
58
70
  */
59
- readonly rootAgent: BaseAgent;
71
+ get rootAgent(): BaseAgent;
60
72
  /**
61
73
  * The parent agent of this agent.
62
74
  *
@@ -14,7 +14,7 @@ import { ReadonlyContext } from './readonly_context.js';
14
14
  export declare class CallbackContext extends ReadonlyContext {
15
15
  private readonly _state;
16
16
  readonly eventActions: EventActions;
17
- constructor({ invocationContext, eventActions }: {
17
+ constructor({ invocationContext, eventActions, }: {
18
18
  invocationContext: InvocationContext;
19
19
  eventActions?: EventActions;
20
20
  });
@@ -15,7 +15,10 @@ import { BaseAgent } from './base_agent.js';
15
15
  import { LiveRequestQueue } from './live_request_queue.js';
16
16
  import { RunConfig } from './run_config.js';
17
17
  import { TranscriptionEntry } from './transcription_entry.js';
18
- interface InvocationContextParams {
18
+ /**
19
+ * The parameters for creating an invocation context.
20
+ */
21
+ export interface InvocationContextParams {
19
22
  artifactService?: BaseArtifactService;
20
23
  sessionService?: BaseSessionService;
21
24
  memoryService?: BaseMemoryService;
@@ -152,4 +155,3 @@ export declare class InvocationContext {
152
155
  incrementLlmCallCount(): void;
153
156
  }
154
157
  export declare function newInvocationContextId(): string;
155
- export {};
@@ -24,8 +24,8 @@ export type InstructionProvider = (context: ReadonlyContext) => string | Promise
24
24
  /**
25
25
  * A callback that runs before a request is sent to the model.
26
26
  *
27
- * @param context The current callback context.
28
- * @param request The raw model request. Callback can mutate the request.
27
+ * @param params.context The current callback context.
28
+ * @param params.request The raw model request. Callback can mutate the request.
29
29
  * @returns The content to return to the user. When present, the model call
30
30
  * will be skipped and the provided content will be returned to user.
31
31
  */
@@ -43,8 +43,8 @@ export type BeforeModelCallback = SingleBeforeModelCallback | SingleBeforeModelC
43
43
  /**
44
44
  * A callback that runs after a response is received from the model.
45
45
  *
46
- * @param context The current callback context.
47
- * @param response The actual model response.
46
+ * @param params.context The current callback context.
47
+ * @param params.response The actual model response.
48
48
  * @returns The content to return to the user. When present, the actual model
49
49
  * response will be ignored and the provided content will be returned to
50
50
  * user.
@@ -60,24 +60,20 @@ export type SingleAfterModelCallback = (params: {
60
60
  order they are listed until a callback does not return None.
61
61
  */
62
62
  export type AfterModelCallback = SingleAfterModelCallback | SingleAfterModelCallback[];
63
- /** A generic dictionary type. */
64
- export type Dict = {
65
- [key: string]: unknown;
66
- };
67
63
  /**
68
64
  * A callback that runs before a tool is called.
69
65
  *
70
- * @param tool The tool to be called.
71
- * @param args The arguments to the tool.
72
- * @param tool_context: ToolContext,
66
+ * @param params.tool The tool to be called.
67
+ * @param params.args The arguments to the tool.
68
+ * @param params.context ToolContext for the tool call.
73
69
  * @returns The tool response. When present, the returned tool response will
74
70
  * be used and the framework will skip calling the actual tool.
75
71
  */
76
72
  export type SingleBeforeToolCallback = (params: {
77
73
  tool: BaseTool;
78
- args: Dict;
74
+ args: Record<string, unknown>;
79
75
  context: ToolContext;
80
- }) => Dict | undefined | Promise<Dict | undefined>;
76
+ }) => Record<string, unknown> | undefined | Promise<Record<string, unknown> | undefined>;
81
77
  /**
82
78
  * A single callback or a list of callbacks.
83
79
  *
@@ -88,18 +84,18 @@ export type BeforeToolCallback = SingleBeforeToolCallback | SingleBeforeToolCall
88
84
  /**
89
85
  * A callback that runs after a tool is called.
90
86
  *
91
- * @param tool The tool to be called.
92
- * @param args The arguments to the tool.
93
- * @param tool_context: ToolContext,
94
- * @param tool_response: The response from the tool.
95
- * @returns When present, the returned dict will be used as tool result.
87
+ * @param params.tool The tool to be called.
88
+ * @param params.args The arguments to the tool.
89
+ * @param params.context ToolContext for the tool call.
90
+ * @param params.response The response from the tool.
91
+ * @returns When present, the returned record will be used as tool result.
96
92
  */
97
93
  export type SingleAfterToolCallback = (params: {
98
94
  tool: BaseTool;
99
- args: Dict;
95
+ args: Record<string, unknown>;
100
96
  context: ToolContext;
101
- response: Dict;
102
- }) => Dict | undefined | Promise<Dict | undefined>;
97
+ response: Record<string, unknown>;
98
+ }) => Record<string, unknown> | undefined | Promise<Record<string, unknown> | undefined>;
103
99
  /**
104
100
  * A single callback or a list of callbacks.
105
101
  *
@@ -111,6 +107,9 @@ export type AfterToolCallback = SingleAfterToolCallback | SingleAfterToolCallbac
111
107
  export type ExamplesUnion = Example[] | BaseExampleProvider;
112
108
  /** A union of tool types that can be provided to an agent. */
113
109
  export type ToolUnion = BaseTool | BaseToolset;
110
+ /**
111
+ * The configuration options for creating an LLM-based agent.
112
+ */
114
113
  export interface LlmAgentConfig extends BaseAgentConfig {
115
114
  /**
116
115
  * The model to use for the agent.
@@ -208,7 +207,7 @@ export interface LlmAgentConfig extends BaseAgentConfig {
208
207
  }
209
208
  declare class RequestConfirmationLlmRequestProcessor extends BaseLlmRequestProcessor {
210
209
  /** Handles tool confirmation information to build the LLM request. */
211
- runAsync(invocationContext: InvocationContext, llmRequest: LlmRequest): AsyncGenerator<Event, void, void>;
210
+ runAsync(invocationContext: InvocationContext): AsyncGenerator<Event, void, void>;
212
211
  }
213
212
  export declare const REQUEST_CONFIRMATION_LLM_REQUEST_PROCESSOR: RequestConfirmationLlmRequestProcessor;
214
213
  /**
@@ -228,10 +227,23 @@ declare class CodeExecutionResponseProcessor implements BaseLlmResponseProcessor
228
227
  * The exported response processor instance.
229
228
  */
230
229
  export declare const responseProcessor: CodeExecutionResponseProcessor;
230
+ /**
231
+ * A unique symbol to identify ADK agent classes.
232
+ * Defined once and shared by all LlmAgent instances.
233
+ */
234
+ declare const LLM_AGENT_SIGNATURE_SYMBOL: unique symbol;
235
+ /**
236
+ * Type guard to check if an object is an instance of LlmAgent.
237
+ * @param obj The object to check.
238
+ * @returns True if the object is an instance of LlmAgent, false otherwise.
239
+ */
240
+ export declare function isLlmAgent(obj: unknown): obj is LlmAgent;
231
241
  /**
232
242
  * An agent that uses a large language model to generate responses.
233
243
  */
234
244
  export declare class LlmAgent extends BaseAgent {
245
+ /** A unique symbol to identify ADK LLM agent class. */
246
+ readonly [LLM_AGENT_SIGNATURE_SYMBOL] = true;
235
247
  model?: string | BaseLlm;
236
248
  instruction: string | InstructionProvider;
237
249
  globalInstruction: string | InstructionProvider;
@@ -258,30 +270,30 @@ export declare class LlmAgent extends BaseAgent {
258
270
  */
259
271
  get canonicalModel(): BaseLlm;
260
272
  /**
261
- * The resolved self.instruction field to construct instruction for this
273
+ * The resolved instruction field to construct instruction for this
262
274
  * agent.
263
275
  *
264
276
  * This method is only for use by Agent Development Kit.
265
277
  * @param context The context to retrieve the session state.
266
- * @returns The resolved self.instruction field.
278
+ * @returns The resolved instruction field.
267
279
  */
268
280
  canonicalInstruction(context: ReadonlyContext): Promise<{
269
281
  instruction: string;
270
282
  requireStateInjection: boolean;
271
283
  }>;
272
284
  /**
273
- * The resolved self.instruction field to construct global instruction.
285
+ * The resolved globalInstruction field to construct global instruction.
274
286
  *
275
287
  * This method is only for use by Agent Development Kit.
276
288
  * @param context The context to retrieve the session state.
277
- * @returns The resolved self.global_instruction field.
289
+ * @returns The resolved globalInstruction field.
278
290
  */
279
291
  canonicalGlobalInstruction(context: ReadonlyContext): Promise<{
280
292
  instruction: string;
281
293
  requireStateInjection: boolean;
282
294
  }>;
283
295
  /**
284
- * The resolved self.tools field as a list of BaseTool based on the context.
296
+ * The resolved tools field as a list of BaseTool based on the context.
285
297
  *
286
298
  * This method is only for use by Agent Development Kit.
287
299
  */
@@ -294,28 +306,28 @@ export declare class LlmAgent extends BaseAgent {
294
306
  */
295
307
  private static normalizeCallbackArray;
296
308
  /**
297
- * The resolved self.before_model_callback field as a list of
309
+ * The resolved beforeModelCallback field as a list of
298
310
  * SingleBeforeModelCallback.
299
311
  *
300
312
  * This method is only for use by Agent Development Kit.
301
313
  */
302
314
  get canonicalBeforeModelCallbacks(): SingleBeforeModelCallback[];
303
315
  /**
304
- * The resolved self.after_model_callback field as a list of
316
+ * The resolved afterModelCallback field as a list of
305
317
  * SingleAfterModelCallback.
306
318
  *
307
319
  * This method is only for use by Agent Development Kit.
308
320
  */
309
321
  get canonicalAfterModelCallbacks(): SingleAfterModelCallback[];
310
322
  /**
311
- * The resolved self.before_tool_callback field as a list of
323
+ * The resolved beforeToolCallback field as a list of
312
324
  * BeforeToolCallback.
313
325
  *
314
326
  * This method is only for use by Agent Development Kit.
315
327
  */
316
328
  get canonicalBeforeToolCallbacks(): SingleBeforeToolCallback[];
317
329
  /**
318
- * The resolved self.after_tool_callback field as a list of AfterToolCallback.
330
+ * The resolved afterToolCallback field as a list of AfterToolCallback.
319
331
  *
320
332
  * This method is only for use by Agent Development Kit.
321
333
  */
@@ -17,6 +17,17 @@ export interface LoopAgentConfig extends BaseAgentConfig {
17
17
  */
18
18
  maxIterations?: number;
19
19
  }
20
+ /**
21
+ * A unique symbol to identify ADK agent classes.
22
+ * Defined once and shared by all LoopAgent instances.
23
+ */
24
+ declare const LOOP_AGENT_SIGNATURE_SYMBOL: unique symbol;
25
+ /**
26
+ * Type guard to check if an object is an instance of LoopAgent.
27
+ * @param obj The object to check.
28
+ * @returns True if the object is an instance of LoopAgent, false otherwise.
29
+ */
30
+ export declare function isLoopAgent(obj: unknown): obj is LoopAgent;
20
31
  /**
21
32
  * A shell agent that run its sub-agents in a loop.
22
33
  *
@@ -24,8 +35,13 @@ export interface LoopAgentConfig extends BaseAgentConfig {
24
35
  * reached, the loop agent will stop.
25
36
  */
26
37
  export declare class LoopAgent extends BaseAgent {
38
+ /**
39
+ * A unique symbol to identify ADK loop agent class.
40
+ */
41
+ readonly [LOOP_AGENT_SIGNATURE_SYMBOL] = true;
27
42
  private readonly maxIterations;
28
43
  constructor(config: LoopAgentConfig);
29
44
  protected runAsyncImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
30
- protected runLiveImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
45
+ protected runLiveImpl(_context: InvocationContext): AsyncGenerator<Event, void, void>;
31
46
  }
47
+ export {};
@@ -6,6 +6,17 @@
6
6
  import { Event } from '../events/event.js';
7
7
  import { BaseAgent } from './base_agent.js';
8
8
  import { InvocationContext } from './invocation_context.js';
9
+ /**
10
+ * A unique symbol to identify ADK agent classes.
11
+ * Defined once and shared by all ParallelAgent instances.
12
+ */
13
+ declare const PARALLEL_AGENT_SIGNATURE_SYMBOL: unique symbol;
14
+ /**
15
+ * Type guard to check if an object is an instance of ParallelAgent.
16
+ * @param obj The object to check.
17
+ * @returns True if the object is an instance of ParallelAgent, false otherwise.
18
+ */
19
+ export declare function isParallelAgent(obj: unknown): obj is ParallelAgent;
9
20
  /**
10
21
  * A shell agent that run its sub-agents in parallel in isolated manner.
11
22
  *
@@ -16,6 +27,11 @@ import { InvocationContext } from './invocation_context.js';
16
27
  * - Generating multiple responses for review by a subsequent evaluation agent.
17
28
  */
18
29
  export declare class ParallelAgent extends BaseAgent {
30
+ /**
31
+ * A unique symbol to identify ADK parallel agent class.
32
+ */
33
+ readonly [PARALLEL_AGENT_SIGNATURE_SYMBOL] = true;
19
34
  protected runAsyncImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
20
- protected runLiveImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
35
+ protected runLiveImpl(_context: InvocationContext): AsyncGenerator<Event, void, void>;
21
36
  }
37
+ export {};
@@ -6,10 +6,25 @@
6
6
  import { Event } from '../events/event.js';
7
7
  import { BaseAgent } from './base_agent.js';
8
8
  import { InvocationContext } from './invocation_context.js';
9
+ /**
10
+ * A unique symbol to identify ADK agent classes.
11
+ * Defined once and shared by all SequentialAgent instances.
12
+ */
13
+ declare const SEQUENTIAL_AGENT_SIGNATURE_SYMBOL: unique symbol;
14
+ /**
15
+ * Type guard to check if an object is an instance of SequentialAgent.
16
+ * @param obj The object to check.
17
+ * @returns True if the object is an instance of SequentialAgent, false otherwise.
18
+ */
19
+ export declare function isSequentialAgent(obj: unknown): obj is SequentialAgent;
9
20
  /**
10
21
  * A shell agent that runs its sub-agents in a sequential order.
11
22
  */
12
23
  export declare class SequentialAgent extends BaseAgent {
24
+ /**
25
+ * A unique symbol to identify ADK sequential agent class.
26
+ */
27
+ readonly [SEQUENTIAL_AGENT_SIGNATURE_SYMBOL] = true;
13
28
  protected runAsyncImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
14
29
  /**
15
30
  * Implementation for live SequentialAgent.
@@ -20,7 +35,8 @@ export declare class SequentialAgent extends BaseAgent {
20
35
  * the model can call this function to signal that it's finished the task and
21
36
  * we can move on to the next agent.
22
37
  *
23
- * @param context: The invocation context of the agent.
38
+ * @param context The invocation context of the agent.
24
39
  */
25
40
  protected runLiveImpl(context: InvocationContext): AsyncGenerator<Event, void, void>;
26
41
  }
42
+ export {};
@@ -12,7 +12,7 @@ export declare class InMemoryArtifactService implements BaseArtifactService {
12
12
  private readonly artifacts;
13
13
  saveArtifact({ appName, userId, sessionId, filename, artifact, }: SaveArtifactRequest): Promise<number>;
14
14
  loadArtifact({ appName, userId, sessionId, filename, version, }: LoadArtifactRequest): Promise<Part | undefined>;
15
- listArtifactKeys({ appName, userId, sessionId }: ListArtifactKeysRequest): Promise<string[]>;
16
- deleteArtifact({ appName, userId, sessionId, filename }: DeleteArtifactRequest): Promise<void>;
17
- listVersions({ appName, userId, sessionId, filename }: ListVersionsRequest): Promise<number[]>;
15
+ listArtifactKeys({ appName, userId, sessionId, }: ListArtifactKeysRequest): Promise<string[]>;
16
+ deleteArtifact({ appName, userId, sessionId, filename, }: DeleteArtifactRequest): Promise<void>;
17
+ listVersions({ appName, userId, sessionId, filename, }: ListVersionsRequest): Promise<number[]>;
18
18
  }
@@ -5,8 +5,11 @@
5
5
  */
6
6
  import { OpenAPIV3 } from 'openapi-types';
7
7
  type Oauth2Flow = OpenAPIV3.OAuth2SecurityScheme['flows'];
8
- export interface OpenIdConnectWithConfig extends OpenAPIV3
9
- .OpenIdSecurityScheme {
8
+ /**
9
+ * OpenIdConnectWithConfig extends OpenIdSecurityScheme with additional
10
+ * configuration options.
11
+ */
12
+ export interface OpenIdConnectWithConfig extends OpenAPIV3.OpenIdSecurityScheme {
10
13
  authorizationEndpoint: string;
11
14
  tokenEndpoint: string;
12
15
  userinfoEndpoint?: string;