@iqai/adk 0.1.6 → 0.1.8

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,23 @@ 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
- }
9899
- }
9900
- return response;
9882
+ const { runner } = await this.build();
9883
+ return runner.ask(message);
9901
9884
  }
9902
9885
  /**
9903
9886
  * Create the appropriate agent type based on configuration
@@ -9920,7 +9903,7 @@ var AgentBuilder = class _AgentBuilder {
9920
9903
  });
9921
9904
  }
9922
9905
  case "sequential":
9923
- if (!this.config.subAgents) {
9906
+ if (!this.config.subAgents || !Array.isArray(this.config.subAgents) || this.config.subAgents.length === 0) {
9924
9907
  throw new Error("Sub-agents required for sequential agent");
9925
9908
  }
9926
9909
  return new SequentialAgent({
@@ -9929,7 +9912,7 @@ var AgentBuilder = class _AgentBuilder {
9929
9912
  subAgents: this.config.subAgents
9930
9913
  });
9931
9914
  case "parallel":
9932
- if (!this.config.subAgents) {
9915
+ if (!this.config.subAgents || !Array.isArray(this.config.subAgents) || this.config.subAgents.length === 0) {
9933
9916
  throw new Error("Sub-agents required for parallel agent");
9934
9917
  }
9935
9918
  return new ParallelAgent({
@@ -9938,7 +9921,7 @@ var AgentBuilder = class _AgentBuilder {
9938
9921
  subAgents: this.config.subAgents
9939
9922
  });
9940
9923
  case "loop":
9941
- if (!this.config.subAgents) {
9924
+ if (!this.config.subAgents || !Array.isArray(this.config.subAgents) || this.config.subAgents.length === 0) {
9942
9925
  throw new Error("Sub-agents required for loop agent");
9943
9926
  }
9944
9927
  return new LoopAgent({
@@ -9948,7 +9931,7 @@ var AgentBuilder = class _AgentBuilder {
9948
9931
  maxIterations: this.config.maxIterations || 3
9949
9932
  });
9950
9933
  case "langgraph":
9951
- if (!this.config.nodes || !this.config.rootNode) {
9934
+ if (!this.config.nodes || !Array.isArray(this.config.nodes) || this.config.nodes.length === 0 || !this.config.rootNode || typeof this.config.rootNode !== "string") {
9952
9935
  throw new Error("Nodes and root node required for LangGraph agent");
9953
9936
  }
9954
9937
  return new LangGraphAgent({
@@ -9959,6 +9942,57 @@ var AgentBuilder = class _AgentBuilder {
9959
9942
  });
9960
9943
  }
9961
9944
  }
9945
+ /**
9946
+ * Generate default user ID based on agent name and id
9947
+ * @returns Generated user ID
9948
+ */
9949
+ generateDefaultUserId() {
9950
+ const id = generateId();
9951
+ return `user-${this.config.name}-${id}`;
9952
+ }
9953
+ /**
9954
+ * Generate default app name based on agent name
9955
+ * @returns Generated app name
9956
+ */
9957
+ generateDefaultAppName() {
9958
+ return `app-${this.config.name}`;
9959
+ }
9960
+ /**
9961
+ * Create enhanced runner with simplified API
9962
+ * @param baseRunner The base runner instance
9963
+ * @param session The session instance
9964
+ * @returns Enhanced runner with simplified API
9965
+ */
9966
+ createEnhancedRunner(baseRunner, session) {
9967
+ const sessionConfig = this.sessionConfig;
9968
+ return {
9969
+ async ask(message) {
9970
+ const fullMessage = typeof message === "string" ? { parts: [{ text: message }] } : message;
9971
+ let response = "";
9972
+ if (!sessionConfig) {
9973
+ throw new Error("Session configuration is required");
9974
+ }
9975
+ for await (const event of baseRunner.runAsync({
9976
+ userId: sessionConfig.userId,
9977
+ sessionId: session.id,
9978
+ newMessage: fullMessage
9979
+ })) {
9980
+ if (event.content?.parts && Array.isArray(event.content.parts)) {
9981
+ const content = event.content.parts.map(
9982
+ (part) => (part && typeof part === "object" && "text" in part ? part.text : "") || ""
9983
+ ).join("");
9984
+ if (content) {
9985
+ response += content;
9986
+ }
9987
+ }
9988
+ }
9989
+ return response;
9990
+ },
9991
+ runAsync(params) {
9992
+ return baseRunner.runAsync(params);
9993
+ }
9994
+ };
9995
+ }
9962
9996
  };
9963
9997
 
9964
9998
  // src/memory/index.ts
@@ -11052,6 +11086,7 @@ export {
11052
11086
  UserInteractionTool,
11053
11087
  VERSION,
11054
11088
  VertexAiSessionService,
11089
+ _findFunctionCallEventIfLastEventIsFunctionResponse,
11055
11090
  adkToMcpToolType,
11056
11091
  requestProcessor8 as agentTransferRequestProcessor,
11057
11092
  requestProcessor2 as basicRequestProcessor,
@@ -11060,6 +11095,7 @@ export {
11060
11095
  responseProcessor as codeExecutionResponseProcessor,
11061
11096
  requestProcessor4 as contentRequestProcessor,
11062
11097
  createAuthToolArguments,
11098
+ createBranchContextForSubAgent,
11063
11099
  createDatabaseSessionService,
11064
11100
  createFunctionTool,
11065
11101
  createMysqlSessionService,
@@ -11079,6 +11115,7 @@ export {
11079
11115
  isEnhancedAuthConfig,
11080
11116
  jsonSchemaToDeclaration,
11081
11117
  mcpSchemaToParameters,
11118
+ mergeAgentRun,
11082
11119
  mergeParallelFunctionResponseEvents,
11083
11120
  newInvocationContextId,
11084
11121
  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.8",
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",