@iqai/adk 0.5.6 → 0.5.7

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/index.mjs CHANGED
@@ -533,7 +533,7 @@ var init_base_tool = __esm({
533
533
  });
534
534
 
535
535
  // src/tools/function/function-utils.ts
536
- import { Type as Type2 } from "@google/genai";
536
+ import { Type as Type10 } from "@google/genai";
537
537
  function buildFunctionDeclaration(func, options = {}) {
538
538
  const funcStr = func.toString();
539
539
  const name = options.name || func.name;
@@ -554,10 +554,10 @@ function buildFunctionDeclaration(func, options = {}) {
554
554
  function extractParametersSchema(func, ignoreParams = []) {
555
555
  const funcStr = func.toString();
556
556
  const paramMatch = funcStr.match(/\(([^)]*)\)/);
557
- if (!paramMatch) return { type: Type2.OBJECT, properties: {} };
557
+ if (!paramMatch) return { type: Type10.OBJECT, properties: {} };
558
558
  const paramList = paramMatch[1].split(",").map((param) => param.trim()).filter((param) => param !== "");
559
559
  if (paramList.length === 0 || paramList.length === 1 && paramList[0] === "") {
560
- return { type: Type2.OBJECT, properties: {} };
560
+ return { type: Type10.OBJECT, properties: {} };
561
561
  }
562
562
  const jsDocParams = extractJSDocParams(funcStr);
563
563
  const jsDocTypes = extractJSDocTypes(funcStr);
@@ -597,7 +597,7 @@ function extractParametersSchema(func, ignoreParams = []) {
597
597
  }
598
598
  }
599
599
  const schema = {
600
- type: Type2.OBJECT,
600
+ type: Type10.OBJECT,
601
601
  properties
602
602
  };
603
603
  if (required.length > 0) {
@@ -4666,245 +4666,26 @@ var AgentTool = class extends BaseTool {
4666
4666
  }
4667
4667
  };
4668
4668
 
4669
- // src/tools/tool-context.ts
4670
- var ToolContext = class extends CallbackContext {
4671
- /**
4672
- * The function call id of the current tool call. This id was
4673
- * returned in the function call event from LLM to identify a function call.
4674
- * If LLM didn't return this id, ADK will assign one to it. This id is used
4675
- * to map function call response to the original function call.
4676
- */
4677
- functionCallId;
4678
- /**
4679
- * Constructor for ToolContext
4680
- */
4681
- constructor(invocationContext, options = {}) {
4682
- super(invocationContext, { eventActions: options.eventActions });
4683
- this.functionCallId = options.functionCallId;
4684
- }
4685
- /**
4686
- * Gets the event actions of the current tool call
4687
- */
4688
- get actions() {
4689
- return this.eventActions;
4690
- }
4691
- /**
4692
- * Lists the filenames of the artifacts attached to the current session
4693
- */
4694
- async listArtifacts() {
4695
- if (!this._invocationContext.artifactService) {
4696
- throw new Error("Artifact service is not initialized.");
4697
- }
4698
- return await this._invocationContext.artifactService.listArtifactKeys({
4699
- appName: this._invocationContext.appName,
4700
- userId: this._invocationContext.userId,
4701
- sessionId: this._invocationContext.session.id
4702
- });
4703
- }
4704
- /**
4705
- * Searches the memory of the current user
4706
- */
4707
- async searchMemory(query) {
4708
- if (!this._invocationContext.memoryService) {
4709
- throw new Error("Memory service is not available.");
4710
- }
4711
- return await this._invocationContext.memoryService.searchMemory({
4712
- query,
4713
- appName: this._invocationContext.appName,
4714
- userId: this._invocationContext.userId
4715
- });
4716
- }
4717
- };
4718
-
4719
- // src/tools/index.ts
4720
- init_function_tool();
4721
-
4722
- // src/tools/function/index.ts
4723
- init_function_tool();
4724
- init_function_utils();
4725
- function createFunctionTool(func, options) {
4726
- const { FunctionTool: FunctionTool2 } = (init_function_tool(), __toCommonJS(function_tool_exports));
4727
- return new FunctionTool2(func, options);
4728
- }
4729
-
4730
- // src/tools/index.ts
4731
- init_function_utils();
4732
-
4733
- // src/tools/common/google-search.ts
4669
+ // src/tools/common/exit-loop-tool.ts
4734
4670
  init_logger();
4735
4671
  init_base_tool();
4736
- import { Type as Type3 } from "@google/genai";
4737
- var GoogleSearch = class extends BaseTool {
4738
- logger = new Logger({ name: "GoogleSearch" });
4739
- /**
4740
- * Constructor for GoogleSearch
4741
- */
4742
- constructor() {
4743
- super({
4744
- name: "google_search",
4745
- description: "Search the web using Google"
4746
- });
4747
- }
4748
- /**
4749
- * Get the function declaration for the tool
4750
- */
4751
- getDeclaration() {
4752
- return {
4753
- name: this.name,
4754
- description: this.description,
4755
- parameters: {
4756
- type: Type3.OBJECT,
4757
- properties: {
4758
- query: {
4759
- type: Type3.STRING,
4760
- description: "The search query to execute"
4761
- },
4762
- num_results: {
4763
- type: Type3.INTEGER,
4764
- description: "Number of results to return (max 10)",
4765
- default: 5
4766
- }
4767
- },
4768
- required: ["query"]
4769
- }
4770
- };
4771
- }
4672
+ var ExitLoopTool = class extends BaseTool {
4673
+ logger = new Logger({ name: "ExitLoopTool" });
4772
4674
  /**
4773
- * Execute the search
4774
- * This is a simplified implementation that doesn't actually search, just returns mock results
4675
+ * Constructor for ExitLoopTool
4775
4676
  */
4776
- async runAsync(args, _context) {
4777
- this.logger.debug(
4778
- `[GoogleSearch] Executing Google search for: ${args.query}`
4779
- );
4780
- return {
4781
- results: [
4782
- {
4783
- title: `Result 1 for ${args.query}`,
4784
- link: "https://example.com/1",
4785
- snippet: `This is a sample result for the query "${args.query}".`
4786
- },
4787
- {
4788
- title: `Result 2 for ${args.query}`,
4789
- link: "https://example.com/2",
4790
- snippet: `Another sample result for "${args.query}".`
4791
- }
4792
- ]
4793
- };
4794
- }
4795
- };
4796
-
4797
- // src/tools/common/http-request-tool.ts
4798
- init_base_tool();
4799
- import { Type as Type4 } from "@google/genai";
4800
- var HttpRequestTool = class extends BaseTool {
4801
4677
  constructor() {
4802
4678
  super({
4803
- name: "http_request",
4804
- description: "Make HTTP requests to external APIs and web services"
4679
+ name: "exit_loop",
4680
+ description: "Exits the loop. Call this function only when you are instructed to do so."
4805
4681
  });
4806
4682
  }
4807
4683
  /**
4808
- * Get the function declaration for the tool
4809
- */
4810
- getDeclaration() {
4811
- return {
4812
- name: this.name,
4813
- description: this.description,
4814
- parameters: {
4815
- type: Type4.OBJECT,
4816
- properties: {
4817
- url: {
4818
- type: Type4.STRING,
4819
- description: "The URL to send the request to"
4820
- },
4821
- method: {
4822
- type: Type4.STRING,
4823
- description: "The HTTP method to use (GET, POST, PUT, DELETE, etc.)",
4824
- enum: ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"],
4825
- default: "GET"
4826
- },
4827
- headers: {
4828
- type: Type4.OBJECT,
4829
- description: "Request headers to include"
4830
- },
4831
- body: {
4832
- type: Type4.STRING,
4833
- description: "Request body content (as string, typically JSON)"
4834
- },
4835
- params: {
4836
- type: Type4.OBJECT,
4837
- description: "URL query parameters to include"
4838
- },
4839
- timeout: {
4840
- type: Type4.INTEGER,
4841
- description: "Request timeout in milliseconds",
4842
- default: 1e4
4843
- }
4844
- },
4845
- required: ["url"]
4846
- }
4847
- };
4848
- }
4849
- /**
4850
- * Execute the HTTP request
4851
- */
4852
- async runAsync(args, _context) {
4853
- try {
4854
- const {
4855
- url,
4856
- method = "GET",
4857
- headers = {},
4858
- body,
4859
- params,
4860
- timeout = 1e4
4861
- } = args;
4862
- const urlObj = new URL(url);
4863
- if (params) {
4864
- Object.entries(params).forEach(([key, value]) => {
4865
- urlObj.searchParams.append(key, value);
4866
- });
4867
- }
4868
- const requestHeaders = { ...headers };
4869
- if (body && !requestHeaders["Content-Type"] && this.isValidJson(body)) {
4870
- requestHeaders["Content-Type"] = "application/json";
4871
- }
4872
- const options = {
4873
- method,
4874
- headers: requestHeaders,
4875
- body,
4876
- signal: AbortSignal.timeout(timeout)
4877
- };
4878
- const response = await fetch(urlObj.toString(), options);
4879
- const responseHeaders = {};
4880
- response.headers.forEach((value, key) => {
4881
- responseHeaders[key] = value;
4882
- });
4883
- const responseBody = await response.text();
4884
- return {
4885
- statusCode: response.status,
4886
- headers: responseHeaders,
4887
- body: responseBody
4888
- };
4889
- } catch (error) {
4890
- return {
4891
- statusCode: 0,
4892
- headers: {},
4893
- body: "",
4894
- error: error instanceof Error ? error.message : String(error)
4895
- };
4896
- }
4897
- }
4898
- /**
4899
- * Check if a string is valid JSON
4684
+ * Execute the exit loop action
4900
4685
  */
4901
- isValidJson(str) {
4902
- try {
4903
- JSON.parse(str);
4904
- return true;
4905
- } catch (e) {
4906
- return false;
4907
- }
4686
+ async runAsync(_args, context4) {
4687
+ this.logger.debug("Executing exit loop tool");
4688
+ context4.actions.escalate = true;
4908
4689
  }
4909
4690
  };
4910
4691
 
@@ -4912,7 +4693,7 @@ var HttpRequestTool = class extends BaseTool {
4912
4693
  init_base_tool();
4913
4694
  import fs from "fs/promises";
4914
4695
  import path from "path";
4915
- import { Type as Type5 } from "@google/genai";
4696
+ import { Type as Type2 } from "@google/genai";
4916
4697
  var FileOperationsTool = class extends BaseTool {
4917
4698
  basePath;
4918
4699
  constructor(options) {
@@ -4930,10 +4711,10 @@ var FileOperationsTool = class extends BaseTool {
4930
4711
  name: this.name,
4931
4712
  description: this.description,
4932
4713
  parameters: {
4933
- type: Type5.OBJECT,
4714
+ type: Type2.OBJECT,
4934
4715
  properties: {
4935
4716
  operation: {
4936
- type: Type5.STRING,
4717
+ type: Type2.STRING,
4937
4718
  description: "The file operation to perform",
4938
4719
  enum: [
4939
4720
  "read",
@@ -4946,15 +4727,15 @@ var FileOperationsTool = class extends BaseTool {
4946
4727
  ]
4947
4728
  },
4948
4729
  filepath: {
4949
- type: Type5.STRING,
4730
+ type: Type2.STRING,
4950
4731
  description: "Path to the file or directory (relative to the base path)"
4951
4732
  },
4952
4733
  content: {
4953
- type: Type5.STRING,
4734
+ type: Type2.STRING,
4954
4735
  description: "Content to write to the file (for write and append operations)"
4955
4736
  },
4956
4737
  encoding: {
4957
- type: Type5.STRING,
4738
+ type: Type2.STRING,
4958
4739
  description: "File encoding to use",
4959
4740
  default: "utf8"
4960
4741
  }
@@ -5158,115 +4939,15 @@ var FileOperationsTool = class extends BaseTool {
5158
4939
  }
5159
4940
  };
5160
4941
 
5161
- // src/tools/common/user-interaction-tool.ts
4942
+ // src/tools/common/get-user-choice-tool.ts
4943
+ init_logger();
5162
4944
  init_base_tool();
5163
- import { Type as Type6 } from "@google/genai";
5164
- var UserInteractionTool = class extends BaseTool {
5165
- constructor() {
5166
- super({
5167
- name: "user_interaction",
5168
- description: "Prompt the user for input during agent execution",
5169
- isLongRunning: true
5170
- });
5171
- }
5172
- /**
5173
- * Get the function declaration for the tool
5174
- */
5175
- getDeclaration() {
5176
- return {
5177
- name: this.name,
5178
- description: this.description,
5179
- parameters: {
5180
- type: Type6.OBJECT,
5181
- properties: {
5182
- prompt: {
5183
- type: Type6.STRING,
5184
- description: "The prompt message to display to the user"
5185
- },
5186
- options: {
5187
- type: Type6.ARRAY,
5188
- description: "Optional array of choices to present to the user",
5189
- items: {
5190
- type: Type6.STRING
5191
- }
5192
- },
5193
- defaultValue: {
5194
- type: Type6.STRING,
5195
- description: "Optional default value for the input field"
5196
- }
5197
- },
5198
- required: ["prompt"]
5199
- }
5200
- };
5201
- }
5202
- /**
5203
- * Execute the user interaction
5204
- */
5205
- async runAsync(args, context4) {
5206
- try {
5207
- const actions = context4.actions;
5208
- if (!actions || !actions.promptUser) {
5209
- return {
5210
- success: false,
5211
- error: "User interaction is not supported in the current environment"
5212
- };
5213
- }
5214
- if (actions.skipSummarization) {
5215
- actions.skipSummarization(true);
5216
- }
5217
- const promptOptions = args.options && args.options.length > 0 ? {
5218
- choices: args.options
5219
- } : void 0;
5220
- const response = await actions.promptUser({
5221
- prompt: args.prompt,
5222
- defaultValue: args.defaultValue,
5223
- options: promptOptions
5224
- });
5225
- return {
5226
- success: true,
5227
- userInput: response
5228
- };
5229
- } catch (error) {
5230
- return {
5231
- success: false,
5232
- error: error instanceof Error ? error.message : String(error)
5233
- };
5234
- }
5235
- }
5236
- };
5237
-
5238
- // src/tools/common/exit-loop-tool.ts
5239
- init_logger();
5240
- init_base_tool();
5241
- var ExitLoopTool = class extends BaseTool {
5242
- logger = new Logger({ name: "ExitLoopTool" });
5243
- /**
5244
- * Constructor for ExitLoopTool
5245
- */
5246
- constructor() {
5247
- super({
5248
- name: "exit_loop",
5249
- description: "Exits the loop. Call this function only when you are instructed to do so."
5250
- });
5251
- }
5252
- /**
5253
- * Execute the exit loop action
5254
- */
5255
- async runAsync(_args, context4) {
5256
- this.logger.debug("Executing exit loop tool");
5257
- context4.actions.escalate = true;
5258
- }
5259
- };
5260
-
5261
- // src/tools/common/get-user-choice-tool.ts
5262
- init_logger();
5263
- init_base_tool();
5264
- import { Type as Type7 } from "@google/genai";
5265
- var GetUserChoiceTool = class extends BaseTool {
5266
- logger = new Logger({ name: "GetUserChoiceTool" });
5267
- /**
5268
- * Constructor for GetUserChoiceTool
5269
- */
4945
+ import { Type as Type3 } from "@google/genai";
4946
+ var GetUserChoiceTool = class extends BaseTool {
4947
+ logger = new Logger({ name: "GetUserChoiceTool" });
4948
+ /**
4949
+ * Constructor for GetUserChoiceTool
4950
+ */
5270
4951
  constructor() {
5271
4952
  super({
5272
4953
  name: "get_user_choice",
@@ -5282,17 +4963,17 @@ var GetUserChoiceTool = class extends BaseTool {
5282
4963
  name: this.name,
5283
4964
  description: this.description,
5284
4965
  parameters: {
5285
- type: Type7.OBJECT,
4966
+ type: Type3.OBJECT,
5286
4967
  properties: {
5287
4968
  options: {
5288
- type: Type7.ARRAY,
4969
+ type: Type3.ARRAY,
5289
4970
  description: "List of options for the user to choose from",
5290
4971
  items: {
5291
- type: Type7.STRING
4972
+ type: Type3.STRING
5292
4973
  }
5293
4974
  },
5294
4975
  question: {
5295
- type: Type7.STRING,
4976
+ type: Type3.STRING,
5296
4977
  description: "The question or prompt to show the user before presenting options"
5297
4978
  }
5298
4979
  },
@@ -5317,19 +4998,19 @@ var GetUserChoiceTool = class extends BaseTool {
5317
4998
  }
5318
4999
  };
5319
5000
 
5320
- // src/tools/common/transfer-to-agent-tool.ts
5001
+ // src/tools/common/google-search.ts
5321
5002
  init_logger();
5322
5003
  init_base_tool();
5323
- import { Type as Type8 } from "@google/genai";
5324
- var TransferToAgentTool = class extends BaseTool {
5325
- logger = new Logger({ name: "TransferToAgentTool" });
5004
+ import { Type as Type4 } from "@google/genai";
5005
+ var GoogleSearch = class extends BaseTool {
5006
+ logger = new Logger({ name: "GoogleSearch" });
5326
5007
  /**
5327
- * Constructor for TransferToAgentTool
5008
+ * Constructor for GoogleSearch
5328
5009
  */
5329
5010
  constructor() {
5330
5011
  super({
5331
- name: "transfer_to_agent",
5332
- description: "Transfer the question to another agent when it's more suitable to answer the user's question according to the agent's description. Use this function when you determine that another agent in the system would be better equipped to handle the user's request based on their specialized capabilities and expertise areas."
5012
+ name: "google_search",
5013
+ description: "Search the web using Google"
5333
5014
  });
5334
5015
  }
5335
5016
  /**
@@ -5340,39 +5021,55 @@ var TransferToAgentTool = class extends BaseTool {
5340
5021
  name: this.name,
5341
5022
  description: this.description,
5342
5023
  parameters: {
5343
- type: Type8.OBJECT,
5024
+ type: Type4.OBJECT,
5344
5025
  properties: {
5345
- agent_name: {
5346
- type: Type8.STRING,
5347
- description: "The name of the agent to transfer control to"
5026
+ query: {
5027
+ type: Type4.STRING,
5028
+ description: "The search query to execute"
5029
+ },
5030
+ num_results: {
5031
+ type: Type4.INTEGER,
5032
+ description: "Number of results to return (max 10)",
5033
+ default: 5
5348
5034
  }
5349
5035
  },
5350
- required: ["agent_name"]
5036
+ required: ["query"]
5351
5037
  }
5352
5038
  };
5353
5039
  }
5354
5040
  /**
5355
- * Execute the transfer to agent action
5041
+ * Execute the search
5042
+ * This is a simplified implementation that doesn't actually search, just returns mock results
5356
5043
  */
5357
- async runAsync(args, context4) {
5358
- this.logger.debug(`Executing transfer to agent: ${args.agent_name}`);
5359
- context4.actions.transferToAgent = args.agent_name;
5044
+ async runAsync(args, _context) {
5045
+ this.logger.debug(
5046
+ `[GoogleSearch] Executing Google search for: ${args.query}`
5047
+ );
5048
+ return {
5049
+ results: [
5050
+ {
5051
+ title: `Result 1 for ${args.query}`,
5052
+ link: "https://example.com/1",
5053
+ snippet: `This is a sample result for the query "${args.query}".`
5054
+ },
5055
+ {
5056
+ title: `Result 2 for ${args.query}`,
5057
+ link: "https://example.com/2",
5058
+ snippet: `Another sample result for "${args.query}".`
5059
+ }
5060
+ ]
5061
+ };
5360
5062
  }
5361
5063
  };
5362
5064
 
5363
- // src/tools/common/load-memory-tool.ts
5364
- init_logger();
5065
+ // src/tools/common/http-request-tool.ts
5365
5066
  init_base_tool();
5366
- import { Type as Type9 } from "@google/genai";
5367
- var LoadMemoryTool = class extends BaseTool {
5368
- logger = new Logger({ name: "LoadMemoryTool" });
5369
- /**
5370
- * Constructor for LoadMemoryTool
5371
- */
5067
+ import { Type as Type5 } from "@google/genai";
5068
+ var HttpRequestTool = class extends BaseTool {
5372
5069
  constructor() {
5373
5070
  super({
5374
- name: "load_memory",
5375
- description: "Loads the memory for the current user based on a query."
5071
+ name: "http_request",
5072
+ description: "Make HTTP requests to external APIs and web services"
5376
5073
  });
5377
5074
  }
5378
5075
  /**
@@ -5383,41 +5080,105 @@ var LoadMemoryTool = class extends BaseTool {
5383
5080
  name: this.name,
5384
5081
  description: this.description,
5385
5082
  parameters: {
5386
- type: Type9.OBJECT,
5083
+ type: Type5.OBJECT,
5387
5084
  properties: {
5388
- query: {
5389
- type: Type9.STRING,
5390
- description: "The query to load memories for"
5085
+ url: {
5086
+ type: Type5.STRING,
5087
+ description: "The URL to send the request to"
5088
+ },
5089
+ method: {
5090
+ type: Type5.STRING,
5091
+ description: "The HTTP method to use (GET, POST, PUT, DELETE, etc.)",
5092
+ enum: ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"],
5093
+ default: "GET"
5094
+ },
5095
+ headers: {
5096
+ type: Type5.OBJECT,
5097
+ description: "Request headers to include"
5098
+ },
5099
+ body: {
5100
+ type: Type5.STRING,
5101
+ description: "Request body content (as string, typically JSON)"
5102
+ },
5103
+ params: {
5104
+ type: Type5.OBJECT,
5105
+ description: "URL query parameters to include"
5106
+ },
5107
+ timeout: {
5108
+ type: Type5.INTEGER,
5109
+ description: "Request timeout in milliseconds",
5110
+ default: 1e4
5391
5111
  }
5392
5112
  },
5393
- required: ["query"]
5113
+ required: ["url"]
5394
5114
  }
5395
5115
  };
5396
5116
  }
5397
5117
  /**
5398
- * Execute the memory loading action
5118
+ * Execute the HTTP request
5399
5119
  */
5400
- async runAsync(args, context4) {
5401
- this.logger.debug(`Executing load_memory with query: ${args.query}`);
5120
+ async runAsync(args, _context) {
5402
5121
  try {
5403
- const searchResult = await context4.searchMemory(args.query);
5122
+ const {
5123
+ url,
5124
+ method = "GET",
5125
+ headers = {},
5126
+ body,
5127
+ params,
5128
+ timeout = 1e4
5129
+ } = args;
5130
+ const urlObj = new URL(url);
5131
+ if (params) {
5132
+ Object.entries(params).forEach(([key, value]) => {
5133
+ urlObj.searchParams.append(key, value);
5134
+ });
5135
+ }
5136
+ const requestHeaders = { ...headers };
5137
+ if (body && !requestHeaders["Content-Type"] && this.isValidJson(body)) {
5138
+ requestHeaders["Content-Type"] = "application/json";
5139
+ }
5140
+ const options = {
5141
+ method,
5142
+ headers: requestHeaders,
5143
+ body,
5144
+ signal: AbortSignal.timeout(timeout)
5145
+ };
5146
+ const response = await fetch(urlObj.toString(), options);
5147
+ const responseHeaders = {};
5148
+ response.headers.forEach((value, key) => {
5149
+ responseHeaders[key] = value;
5150
+ });
5151
+ const responseBody = await response.text();
5404
5152
  return {
5405
- memories: searchResult.memories || [],
5406
- count: searchResult.memories?.length || 0
5153
+ statusCode: response.status,
5154
+ headers: responseHeaders,
5155
+ body: responseBody
5407
5156
  };
5408
5157
  } catch (error) {
5409
- console.error("Error searching memory:", error);
5410
5158
  return {
5411
- error: "Memory search failed",
5412
- message: error instanceof Error ? error.message : String(error)
5159
+ statusCode: 0,
5160
+ headers: {},
5161
+ body: "",
5162
+ error: error instanceof Error ? error.message : String(error)
5413
5163
  };
5414
5164
  }
5415
5165
  }
5166
+ /**
5167
+ * Check if a string is valid JSON
5168
+ */
5169
+ isValidJson(str) {
5170
+ try {
5171
+ JSON.parse(str);
5172
+ return true;
5173
+ } catch (e) {
5174
+ return false;
5175
+ }
5176
+ }
5416
5177
  };
5417
5178
 
5418
5179
  // src/tools/common/load-artifacts-tool.ts
5419
5180
  init_base_tool();
5420
- import { Type as Type10 } from "@google/genai";
5181
+ import { Type as Type6 } from "@google/genai";
5421
5182
  var LoadArtifactsTool = class extends BaseTool {
5422
5183
  constructor() {
5423
5184
  super({
@@ -5433,12 +5194,12 @@ var LoadArtifactsTool = class extends BaseTool {
5433
5194
  name: this.name,
5434
5195
  description: this.description,
5435
5196
  parameters: {
5436
- type: Type10.OBJECT,
5197
+ type: Type6.OBJECT,
5437
5198
  properties: {
5438
5199
  artifact_names: {
5439
- type: Type10.ARRAY,
5200
+ type: Type6.ARRAY,
5440
5201
  items: {
5441
- type: Type10.STRING
5202
+ type: Type6.STRING
5442
5203
  },
5443
5204
  description: "List of artifact names to load"
5444
5205
  }
@@ -5528,10 +5289,197 @@ than the function call.
5528
5289
  }
5529
5290
  };
5530
5291
 
5292
+ // src/tools/common/load-memory-tool.ts
5293
+ init_logger();
5294
+ init_base_tool();
5295
+ import { Type as Type7 } from "@google/genai";
5296
+ var LoadMemoryTool = class extends BaseTool {
5297
+ logger = new Logger({ name: "LoadMemoryTool" });
5298
+ /**
5299
+ * Constructor for LoadMemoryTool
5300
+ */
5301
+ constructor() {
5302
+ super({
5303
+ name: "load_memory",
5304
+ description: "Loads the memory for the current user based on a query."
5305
+ });
5306
+ }
5307
+ /**
5308
+ * Get the function declaration for the tool
5309
+ */
5310
+ getDeclaration() {
5311
+ return {
5312
+ name: this.name,
5313
+ description: this.description,
5314
+ parameters: {
5315
+ type: Type7.OBJECT,
5316
+ properties: {
5317
+ query: {
5318
+ type: Type7.STRING,
5319
+ description: "The query to load memories for"
5320
+ }
5321
+ },
5322
+ required: ["query"]
5323
+ }
5324
+ };
5325
+ }
5326
+ /**
5327
+ * Execute the memory loading action
5328
+ */
5329
+ async runAsync(args, context4) {
5330
+ this.logger.debug(`Executing load_memory with query: ${args.query}`);
5331
+ try {
5332
+ const searchResult = await context4.searchMemory(args.query);
5333
+ return {
5334
+ memories: searchResult.memories || [],
5335
+ count: searchResult.memories?.length || 0
5336
+ };
5337
+ } catch (error) {
5338
+ console.error("Error searching memory:", error);
5339
+ return {
5340
+ error: "Memory search failed",
5341
+ message: error instanceof Error ? error.message : String(error)
5342
+ };
5343
+ }
5344
+ }
5345
+ };
5346
+
5347
+ // src/tools/common/transfer-to-agent-tool.ts
5348
+ init_logger();
5349
+ init_base_tool();
5350
+ import { Type as Type8 } from "@google/genai";
5351
+ var TransferToAgentTool = class extends BaseTool {
5352
+ logger = new Logger({ name: "TransferToAgentTool" });
5353
+ /**
5354
+ * Constructor for TransferToAgentTool
5355
+ */
5356
+ constructor() {
5357
+ super({
5358
+ name: "transfer_to_agent",
5359
+ description: "Transfer the question to another agent when it's more suitable to answer the user's question according to the agent's description. Use this function when you determine that another agent in the system would be better equipped to handle the user's request based on their specialized capabilities and expertise areas."
5360
+ });
5361
+ }
5362
+ /**
5363
+ * Get the function declaration for the tool
5364
+ */
5365
+ getDeclaration() {
5366
+ return {
5367
+ name: this.name,
5368
+ description: this.description,
5369
+ parameters: {
5370
+ type: Type8.OBJECT,
5371
+ properties: {
5372
+ agent_name: {
5373
+ type: Type8.STRING,
5374
+ description: "The name of the agent to transfer control to"
5375
+ }
5376
+ },
5377
+ required: ["agent_name"]
5378
+ }
5379
+ };
5380
+ }
5381
+ /**
5382
+ * Execute the transfer to agent action
5383
+ */
5384
+ async runAsync(args, context4) {
5385
+ this.logger.debug(`Executing transfer to agent: ${args.agent_name}`);
5386
+ context4.actions.transferToAgent = args.agent_name;
5387
+ }
5388
+ };
5389
+
5390
+ // src/tools/common/user-interaction-tool.ts
5391
+ init_base_tool();
5392
+ import { Type as Type9 } from "@google/genai";
5393
+ var UserInteractionTool = class extends BaseTool {
5394
+ constructor() {
5395
+ super({
5396
+ name: "user_interaction",
5397
+ description: "Prompt the user for input during agent execution",
5398
+ isLongRunning: true
5399
+ });
5400
+ }
5401
+ /**
5402
+ * Get the function declaration for the tool
5403
+ */
5404
+ getDeclaration() {
5405
+ return {
5406
+ name: this.name,
5407
+ description: this.description,
5408
+ parameters: {
5409
+ type: Type9.OBJECT,
5410
+ properties: {
5411
+ prompt: {
5412
+ type: Type9.STRING,
5413
+ description: "The prompt message to display to the user"
5414
+ },
5415
+ options: {
5416
+ type: Type9.ARRAY,
5417
+ description: "Optional array of choices to present to the user",
5418
+ items: {
5419
+ type: Type9.STRING
5420
+ }
5421
+ },
5422
+ defaultValue: {
5423
+ type: Type9.STRING,
5424
+ description: "Optional default value for the input field"
5425
+ }
5426
+ },
5427
+ required: ["prompt"]
5428
+ }
5429
+ };
5430
+ }
5431
+ /**
5432
+ * Execute the user interaction
5433
+ */
5434
+ async runAsync(args, context4) {
5435
+ try {
5436
+ const actions = context4.actions;
5437
+ if (!actions || !actions.promptUser) {
5438
+ return {
5439
+ success: false,
5440
+ error: "User interaction is not supported in the current environment"
5441
+ };
5442
+ }
5443
+ if (actions.skipSummarization) {
5444
+ actions.skipSummarization(true);
5445
+ }
5446
+ const promptOptions = args.options && args.options.length > 0 ? {
5447
+ choices: args.options
5448
+ } : void 0;
5449
+ const response = await actions.promptUser({
5450
+ prompt: args.prompt,
5451
+ defaultValue: args.defaultValue,
5452
+ options: promptOptions
5453
+ });
5454
+ return {
5455
+ success: true,
5456
+ userInput: response
5457
+ };
5458
+ } catch (error) {
5459
+ return {
5460
+ success: false,
5461
+ error: error instanceof Error ? error.message : String(error)
5462
+ };
5463
+ }
5464
+ }
5465
+ };
5466
+
5467
+ // src/tools/function/index.ts
5468
+ init_function_tool();
5469
+ init_function_utils();
5470
+ function createFunctionTool(func, options) {
5471
+ const { FunctionTool: FunctionTool2 } = (init_function_tool(), __toCommonJS(function_tool_exports));
5472
+ return new FunctionTool2(func, options);
5473
+ }
5474
+
5475
+ // src/tools/index.ts
5476
+ init_function_tool();
5477
+ init_function_utils();
5478
+
5531
5479
  // src/tools/mcp/client.ts
5532
5480
  init_logger();
5533
5481
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
5534
- import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
5482
+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
5535
5483
  import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
5536
5484
  import { CreateMessageRequestSchema as CreateMessageRequestSchema2 } from "@modelcontextprotocol/sdk/types.js";
5537
5485
 
@@ -5683,7 +5631,7 @@ var McpSamplingHandler = class {
5683
5631
  parts: adkParts
5684
5632
  };
5685
5633
  this.logger.debug(
5686
- `Converted MCP message - role: ${mcpMessage.role} -> ${adkRole}, content type: ${mcpMessage.content.type}`
5634
+ `Converted MCP message - role: ${mcpMessage.role} -> ${adkRole}, content type: ${Array.isArray(mcpMessage.content) ? "array" : mcpMessage.content?.type ?? "unknown"}`
5687
5635
  );
5688
5636
  return adkContent;
5689
5637
  }
@@ -5691,29 +5639,54 @@ var McpSamplingHandler = class {
5691
5639
  * Convert MCP message content to ADK parts format
5692
5640
  */
5693
5641
  convertMcpContentToADKParts(mcpContent) {
5694
- if (mcpContent.type === "text") {
5695
- const textContent = mcpContent.text || "";
5696
- return [{ text: textContent }];
5642
+ const safeText = (value) => typeof value === "string" ? value : "";
5643
+ if (Array.isArray(mcpContent)) {
5644
+ return mcpContent.flatMap((c) => this.convertMcpContentToADKParts(c));
5697
5645
  }
5698
- if (mcpContent.type === "image") {
5699
- const parts = [];
5700
- if (mcpContent.text && typeof mcpContent.text === "string") {
5701
- parts.push({ text: mcpContent.text });
5646
+ switch (mcpContent.type) {
5647
+ case "text": {
5648
+ return [{ text: safeText(mcpContent.text) }];
5702
5649
  }
5703
- if (mcpContent.data && typeof mcpContent.data === "string") {
5704
- const mimeType = mcpContent.mimeType || "image/jpeg";
5650
+ case "image":
5651
+ case "audio": {
5652
+ const parts = [];
5653
+ if ("text" in mcpContent) {
5654
+ const t = safeText(mcpContent.text);
5655
+ if (t) parts.push({ text: t });
5656
+ }
5657
+ const hasData = typeof mcpContent.data === "string" && mcpContent.data.length > 0;
5658
+ if (!hasData) {
5659
+ this.logger.warn(
5660
+ `Missing or invalid 'data' for ${mcpContent.type} content.`
5661
+ );
5662
+ return [
5663
+ ...parts,
5664
+ {
5665
+ text: `[${mcpContent.type.toUpperCase()} CONTENT MISSING DATA]`
5666
+ }
5667
+ ];
5668
+ }
5705
5669
  parts.push({
5706
5670
  inlineData: {
5707
5671
  data: mcpContent.data,
5708
- mimeType
5672
+ mimeType: safeText(mcpContent.mimeType) || (mcpContent.type === "image" ? "image/jpeg" : "audio/mpeg")
5709
5673
  }
5710
5674
  });
5675
+ return parts;
5676
+ }
5677
+ case "tool_use": {
5678
+ return [{ text: `[Tool Use: ${safeText(mcpContent.name)}]` }];
5679
+ }
5680
+ case "tool_result": {
5681
+ return [{ text: `[Tool Result: ${safeText(mcpContent.toolUseId)}]` }];
5682
+ }
5683
+ default: {
5684
+ this.logger.warn(
5685
+ `Unknown MCP content type: ${safeText(mcpContent.type)}`
5686
+ );
5687
+ return [{ text: "[Unknown content type]" }];
5711
5688
  }
5712
- return parts.length > 0 ? parts : [{ text: "" }];
5713
5689
  }
5714
- this.logger.warn(`Unknown MCP content type: ${mcpContent.type}`);
5715
- const fallbackText = typeof mcpContent.data === "string" ? mcpContent.data : "";
5716
- return [{ text: fallbackText }];
5717
5690
  }
5718
5691
  /**
5719
5692
  * Convert ADK response to MCP response format
@@ -5825,9 +5798,6 @@ var McpClientService = class {
5825
5798
  },
5826
5799
  {
5827
5800
  capabilities: {
5828
- prompts: {},
5829
- resources: {},
5830
- tools: {},
5831
5801
  sampling: {}
5832
5802
  // Enable sampling capability
5833
5803
  }
@@ -5880,7 +5850,7 @@ var McpClientService = class {
5880
5850
  ...this.config.transport.headers || {},
5881
5851
  ...this.config.headers || {}
5882
5852
  };
5883
- return new SSEClientTransport(
5853
+ return new StreamableHTTPClientTransport(
5884
5854
  new URL(this.config.transport.serverUrl),
5885
5855
  {
5886
5856
  requestInit: {
@@ -5930,7 +5900,7 @@ var McpClientService = class {
5930
5900
  if (typeof this.client.close === "function") {
5931
5901
  await this.client.close();
5932
5902
  }
5933
- } catch (err) {
5903
+ } catch (_err) {
5934
5904
  }
5935
5905
  }
5936
5906
  if (this.transport && typeof this.transport.close === "function") {
@@ -6216,7 +6186,7 @@ function mcpSchemaToParameters(mcpTool) {
6216
6186
  let schema;
6217
6187
  if (mcpTool.inputSchema) {
6218
6188
  schema = mcpTool.inputSchema;
6219
- } else if (mcpTool.parameters) {
6189
+ } else if ("parameters" in mcpTool && mcpTool.parameters) {
6220
6190
  schema = mcpTool.parameters;
6221
6191
  }
6222
6192
  if (!schema) {
@@ -6254,7 +6224,12 @@ var McpToolAdapter = class extends BaseTool {
6254
6224
  toolHandler;
6255
6225
  logger = new Logger({ name: "McpToolAdapter" });
6256
6226
  constructor(mcpTool, client, handler) {
6257
- const metadata = mcpTool.metadata || {};
6227
+ let metadata = {};
6228
+ if ("metadata" in mcpTool && typeof mcpTool.metadata === "object") {
6229
+ metadata = mcpTool.metadata;
6230
+ } else if (mcpTool._meta && typeof mcpTool._meta === "object") {
6231
+ metadata = mcpTool._meta;
6232
+ }
6258
6233
  super({
6259
6234
  name: mcpTool.name || `mcp_${Date.now()}`,
6260
6235
  description: mcpTool.description || "MCP Tool",
@@ -6288,7 +6263,7 @@ var McpToolAdapter = class extends BaseTool {
6288
6263
  async runAsync(args, _context) {
6289
6264
  this.logger.debug(`Executing MCP tool ${this.name} with args:`, args);
6290
6265
  try {
6291
- if (typeof this.mcpTool.execute === "function") {
6266
+ if ("execute" in this.mcpTool && typeof this.mcpTool.execute === "function") {
6292
6267
  return await this.mcpTool.execute(args);
6293
6268
  }
6294
6269
  if (this.clientService) {
@@ -6687,6 +6662,56 @@ async function getMcpTools(config, toolFilter) {
6687
6662
  }
6688
6663
  }
6689
6664
 
6665
+ // src/tools/tool-context.ts
6666
+ var ToolContext = class extends CallbackContext {
6667
+ /**
6668
+ * The function call id of the current tool call. This id was
6669
+ * returned in the function call event from LLM to identify a function call.
6670
+ * If LLM didn't return this id, ADK will assign one to it. This id is used
6671
+ * to map function call response to the original function call.
6672
+ */
6673
+ functionCallId;
6674
+ /**
6675
+ * Constructor for ToolContext
6676
+ */
6677
+ constructor(invocationContext, options = {}) {
6678
+ super(invocationContext, { eventActions: options.eventActions });
6679
+ this.functionCallId = options.functionCallId;
6680
+ }
6681
+ /**
6682
+ * Gets the event actions of the current tool call
6683
+ */
6684
+ get actions() {
6685
+ return this.eventActions;
6686
+ }
6687
+ /**
6688
+ * Lists the filenames of the artifacts attached to the current session
6689
+ */
6690
+ async listArtifacts() {
6691
+ if (!this._invocationContext.artifactService) {
6692
+ throw new Error("Artifact service is not initialized.");
6693
+ }
6694
+ return await this._invocationContext.artifactService.listArtifactKeys({
6695
+ appName: this._invocationContext.appName,
6696
+ userId: this._invocationContext.userId,
6697
+ sessionId: this._invocationContext.session.id
6698
+ });
6699
+ }
6700
+ /**
6701
+ * Searches the memory of the current user
6702
+ */
6703
+ async searchMemory(query) {
6704
+ if (!this._invocationContext.memoryService) {
6705
+ throw new Error("Memory service is not available.");
6706
+ }
6707
+ return await this._invocationContext.memoryService.searchMemory({
6708
+ query,
6709
+ appName: this._invocationContext.appName,
6710
+ userId: this._invocationContext.userId
6711
+ });
6712
+ }
6713
+ };
6714
+
6690
6715
  // src/flows/llm-flows/functions.ts
6691
6716
  import { context as context2, trace as trace2 } from "@opentelemetry/api";
6692
6717
  var AF_FUNCTION_CALL_ID_PREFIX = "adk-";