@iqai/adk 0.1.6 → 0.1.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
@@ -674,6 +674,8 @@ __export(agents_exports, {
674
674
  RunConfig: () => RunConfig,
675
675
  SequentialAgent: () => SequentialAgent,
676
676
  StreamingMode: () => StreamingMode,
677
+ createBranchContextForSubAgent: () => createBranchContextForSubAgent,
678
+ mergeAgentRun: () => mergeAgentRun,
677
679
  newInvocationContextId: () => newInvocationContextId
678
680
  });
679
681
 
@@ -8870,6 +8872,9 @@ var LangGraphAgent = class extends BaseAgent {
8870
8872
  }
8871
8873
  };
8872
8874
 
8875
+ // src/agents/agent-builder.ts
8876
+ import { generateId } from "ai";
8877
+
8873
8878
  // src/runners.ts
8874
8879
  import { SpanStatusCode } from "@opentelemetry/api";
8875
8880
 
@@ -9812,10 +9817,10 @@ var AgentBuilder = class _AgentBuilder {
9812
9817
  return this;
9813
9818
  }
9814
9819
  /**
9815
- * Configure session management
9820
+ * Configure session management with optional smart defaults
9816
9821
  * @param service Session service to use
9817
- * @param userId User identifier
9818
- * @param appName Application name
9822
+ * @param userId User identifier (optional, defaults to agent-based ID)
9823
+ * @param appName Application name (optional, defaults to agent-based name)
9819
9824
  * @param memoryService Optional memory service
9820
9825
  * @param artifactService Optional artifact service
9821
9826
  * @returns This builder instance for chaining
@@ -9823,17 +9828,18 @@ var AgentBuilder = class _AgentBuilder {
9823
9828
  withSession(service, userId, appName, memoryService, artifactService) {
9824
9829
  this.sessionConfig = {
9825
9830
  service,
9826
- userId,
9827
- appName,
9831
+ userId: userId || this.generateDefaultUserId(),
9832
+ appName: appName || this.generateDefaultAppName(),
9828
9833
  memoryService,
9829
9834
  artifactService
9830
9835
  };
9831
9836
  return this;
9832
9837
  }
9833
9838
  /**
9834
- * Configure with an in-memory session (for quick setup)
9835
- * @param appName Application name
9836
- * @param userId User identifier
9839
+ * Configure with an in-memory session with custom IDs
9840
+ * Note: In-memory sessions are created automatically by default, use this only if you need custom appName/userId
9841
+ * @param appName Application name (optional, defaults to agent-based name)
9842
+ * @param userId User identifier (optional, defaults to agent-based ID)
9837
9843
  * @returns This builder instance for chaining
9838
9844
  */
9839
9845
  withQuickSession(appName, userId) {
@@ -9847,6 +9853,9 @@ var AgentBuilder = class _AgentBuilder {
9847
9853
  const agent = this.createAgent();
9848
9854
  let runner;
9849
9855
  let session;
9856
+ if (!this.sessionConfig) {
9857
+ this.withQuickSession();
9858
+ }
9850
9859
  if (this.sessionConfig) {
9851
9860
  session = await this.sessionConfig.service.createSession(
9852
9861
  this.sessionConfig.appName,
@@ -9855,49 +9864,26 @@ var AgentBuilder = class _AgentBuilder {
9855
9864
  const runnerConfig = {
9856
9865
  appName: this.sessionConfig.appName,
9857
9866
  agent,
9858
- sessionService: this.sessionConfig.service
9867
+ sessionService: this.sessionConfig.service,
9868
+ memoryService: this.sessionConfig.memoryService,
9869
+ artifactService: this.sessionConfig.artifactService
9859
9870
  };
9860
- if (this.sessionConfig.memoryService) {
9861
- runnerConfig.memoryService = this.sessionConfig.memoryService;
9862
- }
9863
- if (this.sessionConfig.artifactService) {
9864
- runnerConfig.artifactService = this.sessionConfig.artifactService;
9865
- }
9866
- runner = new Runner(runnerConfig);
9871
+ const baseRunner = new Runner(runnerConfig);
9872
+ runner = this.createEnhancedRunner(baseRunner, session);
9867
9873
  }
9868
9874
  return { agent, runner, session };
9869
9875
  }
9870
9876
  /**
9871
9877
  * Quick execution helper - build and run a message
9872
- * @param message Message to send to the agent
9878
+ * @param message Message to send to the agent (string or full message object)
9873
9879
  * @returns Agent response
9874
9880
  */
9875
9881
  async ask(message) {
9876
- if (!this.sessionConfig) {
9877
- const userId = `user-${this.config.name}`;
9878
- const appName = `session-${this.config.name}`;
9879
- this.withQuickSession(appName, userId);
9880
- }
9881
- const { runner, session } = await this.build();
9882
- if (!runner || !session) {
9883
- throw new Error("Failed to create runner and session");
9884
- }
9885
- let response = "";
9886
- for await (const event of runner.runAsync({
9887
- userId: this.sessionConfig.userId,
9888
- sessionId: session.id,
9889
- newMessage: {
9890
- parts: [{ text: message }]
9891
- }
9892
- })) {
9893
- if (event.content?.parts) {
9894
- const content = event.content.parts.map((part) => part.text || "").join("");
9895
- if (content) {
9896
- response += content;
9897
- }
9898
- }
9882
+ const { runner } = await this.build();
9883
+ if (!runner) {
9884
+ throw new Error("Failed to create runner");
9899
9885
  }
9900
- return response;
9886
+ return runner.ask(message);
9901
9887
  }
9902
9888
  /**
9903
9889
  * Create the appropriate agent type based on configuration
@@ -9920,7 +9906,7 @@ var AgentBuilder = class _AgentBuilder {
9920
9906
  });
9921
9907
  }
9922
9908
  case "sequential":
9923
- if (!this.config.subAgents) {
9909
+ if (!this.config.subAgents || !Array.isArray(this.config.subAgents) || this.config.subAgents.length === 0) {
9924
9910
  throw new Error("Sub-agents required for sequential agent");
9925
9911
  }
9926
9912
  return new SequentialAgent({
@@ -9929,7 +9915,7 @@ var AgentBuilder = class _AgentBuilder {
9929
9915
  subAgents: this.config.subAgents
9930
9916
  });
9931
9917
  case "parallel":
9932
- if (!this.config.subAgents) {
9918
+ if (!this.config.subAgents || !Array.isArray(this.config.subAgents) || this.config.subAgents.length === 0) {
9933
9919
  throw new Error("Sub-agents required for parallel agent");
9934
9920
  }
9935
9921
  return new ParallelAgent({
@@ -9938,7 +9924,7 @@ var AgentBuilder = class _AgentBuilder {
9938
9924
  subAgents: this.config.subAgents
9939
9925
  });
9940
9926
  case "loop":
9941
- if (!this.config.subAgents) {
9927
+ if (!this.config.subAgents || !Array.isArray(this.config.subAgents) || this.config.subAgents.length === 0) {
9942
9928
  throw new Error("Sub-agents required for loop agent");
9943
9929
  }
9944
9930
  return new LoopAgent({
@@ -9948,7 +9934,7 @@ var AgentBuilder = class _AgentBuilder {
9948
9934
  maxIterations: this.config.maxIterations || 3
9949
9935
  });
9950
9936
  case "langgraph":
9951
- if (!this.config.nodes || !this.config.rootNode) {
9937
+ if (!this.config.nodes || !Array.isArray(this.config.nodes) || this.config.nodes.length === 0 || !this.config.rootNode || typeof this.config.rootNode !== "string") {
9952
9938
  throw new Error("Nodes and root node required for LangGraph agent");
9953
9939
  }
9954
9940
  return new LangGraphAgent({
@@ -9959,6 +9945,57 @@ var AgentBuilder = class _AgentBuilder {
9959
9945
  });
9960
9946
  }
9961
9947
  }
9948
+ /**
9949
+ * Generate default user ID based on agent name and id
9950
+ * @returns Generated user ID
9951
+ */
9952
+ generateDefaultUserId() {
9953
+ const id = generateId();
9954
+ return `user-${this.config.name}-${id}`;
9955
+ }
9956
+ /**
9957
+ * Generate default app name based on agent name
9958
+ * @returns Generated app name
9959
+ */
9960
+ generateDefaultAppName() {
9961
+ return `app-${this.config.name}`;
9962
+ }
9963
+ /**
9964
+ * Create enhanced runner with simplified API
9965
+ * @param baseRunner The base runner instance
9966
+ * @param session The session instance
9967
+ * @returns Enhanced runner with simplified API
9968
+ */
9969
+ createEnhancedRunner(baseRunner, session) {
9970
+ const sessionConfig = this.sessionConfig;
9971
+ return {
9972
+ async ask(message) {
9973
+ const fullMessage = typeof message === "string" ? { parts: [{ text: message }] } : message;
9974
+ let response = "";
9975
+ if (!sessionConfig) {
9976
+ throw new Error("Session configuration is required");
9977
+ }
9978
+ for await (const event of baseRunner.runAsync({
9979
+ userId: sessionConfig.userId,
9980
+ sessionId: session.id,
9981
+ newMessage: fullMessage
9982
+ })) {
9983
+ if (event.content?.parts && Array.isArray(event.content.parts)) {
9984
+ const content = event.content.parts.map(
9985
+ (part) => (part && typeof part === "object" && "text" in part ? part.text : "") || ""
9986
+ ).join("");
9987
+ if (content) {
9988
+ response += content;
9989
+ }
9990
+ }
9991
+ }
9992
+ return response;
9993
+ },
9994
+ runAsync(params) {
9995
+ return baseRunner.runAsync(params);
9996
+ }
9997
+ };
9998
+ }
9962
9999
  };
9963
10000
 
9964
10001
  // src/memory/index.ts
@@ -11052,6 +11089,7 @@ export {
11052
11089
  UserInteractionTool,
11053
11090
  VERSION,
11054
11091
  VertexAiSessionService,
11092
+ _findFunctionCallEventIfLastEventIsFunctionResponse,
11055
11093
  adkToMcpToolType,
11056
11094
  requestProcessor8 as agentTransferRequestProcessor,
11057
11095
  requestProcessor2 as basicRequestProcessor,
@@ -11060,6 +11098,7 @@ export {
11060
11098
  responseProcessor as codeExecutionResponseProcessor,
11061
11099
  requestProcessor4 as contentRequestProcessor,
11062
11100
  createAuthToolArguments,
11101
+ createBranchContextForSubAgent,
11063
11102
  createDatabaseSessionService,
11064
11103
  createFunctionTool,
11065
11104
  createMysqlSessionService,
@@ -11079,6 +11118,7 @@ export {
11079
11118
  isEnhancedAuthConfig,
11080
11119
  jsonSchemaToDeclaration,
11081
11120
  mcpSchemaToParameters,
11121
+ mergeAgentRun,
11082
11122
  mergeParallelFunctionResponseEvents,
11083
11123
  newInvocationContextId,
11084
11124
  requestProcessor7 as nlPlanningRequestProcessor,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iqai/adk",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Agent Development Kit for TypeScript with multi-provider LLM support",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",