@inkeep/agents-run-api 0.31.6 → 0.31.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.cjs CHANGED
@@ -2982,7 +2982,16 @@ var _ArtifactService = class _ArtifactService {
2982
2982
  );
2983
2983
  return null;
2984
2984
  }
2985
- const artifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
2985
+ let artifacts = [];
2986
+ artifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
2987
+ scopes: { tenantId: this.context.tenantId, projectId: this.context.projectId },
2988
+ artifactId,
2989
+ toolCallId
2990
+ });
2991
+ if (artifacts.length > 0) {
2992
+ return this.formatArtifactSummaryData(artifacts[0], artifactId, toolCallId);
2993
+ }
2994
+ artifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
2986
2995
  scopes: { tenantId: this.context.tenantId, projectId: this.context.projectId },
2987
2996
  artifactId,
2988
2997
  taskId: this.context.taskId
@@ -3028,7 +3037,16 @@ var _ArtifactService = class _ArtifactService {
3028
3037
  );
3029
3038
  return null;
3030
3039
  }
3031
- const artifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
3040
+ let artifacts = [];
3041
+ artifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
3042
+ scopes: { tenantId: this.context.tenantId, projectId: this.context.projectId },
3043
+ artifactId,
3044
+ toolCallId
3045
+ });
3046
+ if (artifacts.length > 0) {
3047
+ return this.formatArtifactFullData(artifacts[0], artifactId, toolCallId);
3048
+ }
3049
+ artifacts = await agentsCore.getLedgerArtifacts(dbClient_default)({
3032
3050
  scopes: { tenantId: this.context.tenantId, projectId: this.context.projectId },
3033
3051
  artifactId,
3034
3052
  taskId: this.context.taskId
@@ -4996,15 +5014,8 @@ Make it specific and relevant.`;
4996
5014
  );
4997
5015
  result = object;
4998
5016
  }
4999
- const artifactService = new ArtifactService({
5000
- tenantId: artifactData.tenantId,
5001
- projectId: artifactData.projectId,
5002
- contextId: artifactData.contextId,
5003
- taskId: artifactData.taskId,
5004
- sessionId: this.sessionId
5005
- });
5006
5017
  try {
5007
- await artifactService.saveArtifact({
5018
+ await this.artifactService.saveArtifact({
5008
5019
  artifactId: artifactData.artifactId,
5009
5020
  name: result.name,
5010
5021
  description: result.description,
@@ -5033,14 +5044,14 @@ Make it specific and relevant.`;
5033
5044
  if (!mainSaveSucceeded) {
5034
5045
  try {
5035
5046
  if (artifactData.tenantId && artifactData.projectId) {
5036
- const artifactService2 = new ArtifactService({
5047
+ const artifactService = new ArtifactService({
5037
5048
  tenantId: artifactData.tenantId,
5038
5049
  projectId: artifactData.projectId,
5039
5050
  contextId: artifactData.contextId || "unknown",
5040
5051
  taskId: artifactData.taskId,
5041
5052
  sessionId: this.sessionId
5042
5053
  });
5043
- await artifactService2.saveArtifact({
5054
+ await artifactService.saveArtifact({
5044
5055
  artifactId: artifactData.artifactId,
5045
5056
  name: `Artifact ${artifactData.artifactId.substring(0, 8)}`,
5046
5057
  description: `${artifactData.artifactType || "Data"} from ${artifactData.metadata?.toolName || "tool results"}`,
@@ -6928,24 +6939,95 @@ init_dbClient();
6928
6939
  init_logger();
6929
6940
  var logger14 = agentsCore.getLogger("relationships Tools");
6930
6941
  var generateTransferToolDescription = (config) => {
6931
- return `Hand off the conversation to agent ${config.id}.
6942
+ let toolsSection = "";
6943
+ let transferSection = "";
6944
+ if (config.transferRelations && config.transferRelations.length > 0) {
6945
+ const transferList = config.transferRelations.map(
6946
+ (transfer) => ` - ${transfer.name || transfer.id}: ${transfer.description || "No description available"}`
6947
+ ).join("\n");
6948
+ transferSection = `
6949
+
6950
+ Can Transfer To:
6951
+ ${transferList}`;
6952
+ }
6953
+ let delegateSection = "";
6954
+ if (config.delegateRelations && config.delegateRelations.length > 0) {
6955
+ const delegateList = config.delegateRelations.map(
6956
+ (delegate) => ` - ${delegate.config.name || delegate.config.id}: ${delegate.config.description || "No description available"} (${delegate.type})`
6957
+ ).join("\n");
6958
+ delegateSection = `
6959
+
6960
+ Can Delegate To:
6961
+ ${delegateList}`;
6962
+ }
6963
+ if (config.tools && config.tools.length > 0) {
6964
+ const toolDescriptions = config.tools.map((tool3) => {
6965
+ const toolsList = tool3.availableTools?.map((t) => ` - ${t.name}: ${t.description || "No description available"}`).join("\n") || "";
6966
+ return `MCP Server: ${tool3.name}
6967
+ ${toolsList}`;
6968
+ }).join("\n\n");
6969
+ toolsSection = `
6970
+
6971
+ Available Tools & Capabilities:
6972
+ ${toolDescriptions}`;
6973
+ }
6974
+ const finalDescription = `Hand off the conversation to agent ${config.id}.
6932
6975
 
6933
6976
  Agent Information:
6934
6977
  - ID: ${config.id}
6935
6978
  - Name: ${config.name ?? "No name provided"}
6936
- - Description: ${config.description ?? "No description provided"}
6979
+ - Description: ${config.description ?? "No description provided"}${toolsSection}${transferSection}${delegateSection}
6937
6980
 
6938
6981
  Hand off the conversation to agent ${config.id} when the user's request would be better handled by this specialized agent.`;
6982
+ return finalDescription;
6939
6983
  };
6940
- var generateDelegateToolDescription = (config) => {
6941
- return `Delegate a specific task to another agent.
6984
+ var generateDelegateToolDescription = (delegateRelation) => {
6985
+ const config = delegateRelation.config;
6986
+ let toolsSection = "";
6987
+ let transferSection = "";
6988
+ let delegateSection = "";
6989
+ if (delegateRelation.type === "internal" && "tools" in config) {
6990
+ const agentConfig = config;
6991
+ if (agentConfig.tools && agentConfig.tools.length > 0) {
6992
+ const toolDescriptions = agentConfig.tools.map((tool3) => {
6993
+ const toolsList = tool3.availableTools?.map((t) => ` - ${t.name}: ${t.description || "No description available"}`).join("\n") || "";
6994
+ return `MCP Server: ${tool3.name}
6995
+ ${toolsList}`;
6996
+ }).join("\n\n");
6997
+ toolsSection = `
6998
+
6999
+ Available Tools & Capabilities:
7000
+ ${toolDescriptions}`;
7001
+ }
7002
+ if (agentConfig.transferRelations && agentConfig.transferRelations.length > 0) {
7003
+ const transferList = agentConfig.transferRelations.map(
7004
+ (transfer) => ` - ${transfer.name || transfer.id}: ${transfer.description || "No description available"}`
7005
+ ).join("\n");
7006
+ transferSection = `
7007
+
7008
+ Can Transfer To:
7009
+ ${transferList}`;
7010
+ }
7011
+ if (agentConfig.delegateRelations && agentConfig.delegateRelations.length > 0) {
7012
+ const delegateList = agentConfig.delegateRelations.map(
7013
+ (delegate) => ` - ${delegate.config.name || delegate.config.id}: ${delegate.config.description || "No description available"} (${delegate.type})`
7014
+ ).join("\n");
7015
+ delegateSection = `
7016
+
7017
+ Can Delegate To:
7018
+ ${delegateList}`;
7019
+ }
7020
+ }
7021
+ const finalDescription = `Delegate a specific task to another agent.
6942
7022
 
6943
7023
  Agent Information:
6944
7024
  - ID: ${config.id}
6945
7025
  - Name: ${config.name}
6946
7026
  - Description: ${config.description || "No description provided"}
7027
+ - Type: ${delegateRelation.type}${toolsSection}${transferSection}${delegateSection}
6947
7028
 
6948
7029
  Delegate a specific task to agent ${config.id} when it seems like the agent can do relevant work.`;
7030
+ return finalDescription;
6949
7031
  };
6950
7032
  var createTransferToAgentTool = ({
6951
7033
  transferConfig,
@@ -6953,8 +7035,9 @@ var createTransferToAgentTool = ({
6953
7035
  subAgent,
6954
7036
  streamRequestId
6955
7037
  }) => {
7038
+ const toolDescription = generateTransferToolDescription(transferConfig);
6956
7039
  return ai.tool({
6957
- description: generateTransferToolDescription(transferConfig),
7040
+ description: toolDescription,
6958
7041
  inputSchema: z6__default.default.object({}),
6959
7042
  execute: async () => {
6960
7043
  const activeSpan = api.trace.getActiveSpan();
@@ -7009,7 +7092,7 @@ function createDelegateToAgentTool({
7009
7092
  credentialStoreRegistry
7010
7093
  }) {
7011
7094
  return ai.tool({
7012
- description: generateDelegateToolDescription(delegateConfig.config),
7095
+ description: generateDelegateToolDescription(delegateConfig),
7013
7096
  inputSchema: z6__default.default.object({ message: z6__default.default.string() }),
7014
7097
  execute: async (input, context) => {
7015
7098
  const delegationId = `del_${agentsCore.generateId()}`;
@@ -7266,7 +7349,7 @@ var system_prompt_default = `<system_message>
7266
7349
  - You ARE the user's assistant - there are no other agents, specialists, or experts
7267
7350
  - NEVER say you are connecting them to anyone or anything
7268
7351
  - Continue conversations as if you personally have been handling them the entire time
7269
- - Answer questions directly without any transition phrases or transfer language
7352
+ - Answer questions directly without any transition phrases or transfer language except when transferring to another agent or delegating to another agent
7270
7353
  {{TRANSFER_INSTRUCTIONS}}
7271
7354
  {{DELEGATION_INSTRUCTIONS}}
7272
7355
  </security>
@@ -7274,7 +7357,7 @@ var system_prompt_default = `<system_message>
7274
7357
  <interaction_guidelines>
7275
7358
  - Be helpful, accurate, and professional
7276
7359
  - Use tools when appropriate to provide better assistance
7277
- - Explain your reasoning when using tools
7360
+ - Use tools directly without announcing or explaining what you're doing ("Let me search...", "I'll look for...", etc.)
7278
7361
  - Save important tool results as artifacts when they contain structured data that should be preserved and referenced
7279
7362
  - Ask for clarification when requests are ambiguous
7280
7363
 
@@ -7292,11 +7375,6 @@ var system_prompt_default = `<system_message>
7292
7375
  - NEVER mention delegation occurred: just present the results
7293
7376
  - If delegation returns artifacts, reference them as if you created them
7294
7377
 
7295
- \u{1F6A8} TRANSFER TOOL RULES - CRITICAL:
7296
- - When calling transfer_to_* tools, call the tool IMMEDIATELY without any explanatory text
7297
- - Do NOT explain the transfer, do NOT say "I'll hand this off", do NOT provide reasoning
7298
- - Just call the transfer tool directly when you determine it's needed
7299
- - The tool call is sufficient - no additional text should be generated
7300
7378
  </interaction_guidelines>
7301
7379
 
7302
7380
  {{THINKING_PREPARATION_INSTRUCTIONS}}
@@ -7515,9 +7593,24 @@ var Phase1Config = class _Phase1Config {
7515
7593
  if (!hasTransferRelations) {
7516
7594
  return "";
7517
7595
  }
7518
- return `- You have transfer_to_* tools that seamlessly continue the conversation
7519
- - NEVER announce transfers - just call the tool when needed
7520
- - The conversation continues naturally without any transfer language`;
7596
+ return `You are part of a single unified assistant composed of specialized agents. To the user, you must always appear as one continuous, confident voice.
7597
+
7598
+ You have transfer_to_* tools that seamlessly continue the conversation. When you determine another agent should handle a request: ONLY call the appropriate transfer_to_* tool. Do not provide any substantive answer, limitation, or explanation before transferring. NEVER announce, describe, or apologize for a transfer.
7599
+
7600
+ Do NOT stream any text when transferring - call the transfer tool IMMEDIATELY. Do NOT acknowledge the request, do NOT say "Looking into that...", "Let me search...", "I'll help you find...", or provide ANY explanatory text. Place all reasoning or handoff details inside the transfer tool call, not in the user message. The tool call is sufficient - no additional text should be generated.
7601
+
7602
+ CRITICAL: When you receive a user message that ends with "Please continue from where this conversation was left off" - this indicates you are continuing a conversation that another agent started. You should:
7603
+ - Review the conversation history to see what was already communicated to the user
7604
+ - Continue seamlessly from where the previous response left off
7605
+ - Do NOT repeat what was already said in the conversation history
7606
+ - Do NOT announce what you're about to do ("Let me search...", "I'll look for...", etc.)
7607
+ - Proceed directly with the appropriate tool or action
7608
+ - Act as if you have been handling the conversation from the beginning
7609
+
7610
+ When receiving any transfer, act as if you have been engaged from the start. Continue the same tone, context, and style. Never reference other agents, tools, or roles.
7611
+
7612
+ Your goal: preserve the illusion of a single, seamless, intelligent assistant. All user-facing behavior must feel like one continuous conversation, regardless of internal transfers.
7613
+ `;
7521
7614
  }
7522
7615
  generateDelegationInstructions(hasDelegateRelations) {
7523
7616
  if (!hasDelegateRelations) {
@@ -9517,6 +9610,9 @@ var Agent = class {
9517
9610
  try {
9518
9611
  this.streamRequestId = streamRequestId;
9519
9612
  this.streamHelper = streamRequestId ? getStreamHelper(streamRequestId) : void 0;
9613
+ if (streamRequestId && this.artifactComponents.length > 0) {
9614
+ agentSessionManager.updateArtifactComponents(streamRequestId, this.artifactComponents);
9615
+ }
9520
9616
  const conversationId = runtimeContext?.metadata?.conversationId;
9521
9617
  if (conversationId) {
9522
9618
  this.setConversationId(conversationId);
@@ -10264,9 +10360,14 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
10264
10360
  const models = "models" in config.agentSchema ? config.agentSchema.models : void 0;
10265
10361
  const stopWhen = "stopWhen" in config.agentSchema ? config.agentSchema.stopWhen : void 0;
10266
10362
  const toolsForAgentResult = await Promise.all(
10267
- toolsForAgent.data.map(
10268
- async (item) => await agentsCore.dbResultToMcpTool(item.tool, dbClient_default, credentialStoreRegistry)
10269
- )
10363
+ toolsForAgent.data.map(async (item) => {
10364
+ const mcpTool = await agentsCore.dbResultToMcpTool(item.tool, dbClient_default, credentialStoreRegistry);
10365
+ if (item.selectedTools && item.selectedTools.length > 0) {
10366
+ const selectedToolsSet = new Set(item.selectedTools);
10367
+ mcpTool.availableTools = mcpTool.availableTools?.filter((tool3) => selectedToolsSet.has(tool3.name)) || [];
10368
+ }
10369
+ return mcpTool;
10370
+ })
10270
10371
  ) ?? [];
10271
10372
  const agent = new Agent(
10272
10373
  {
@@ -10295,20 +10396,112 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
10295
10396
  subAgentRelations: [],
10296
10397
  transferRelations: []
10297
10398
  })),
10298
- transferRelations: enhancedInternalRelations.filter((relation) => relation.relationType === "transfer").map((relation) => ({
10299
- baseUrl: config.baseUrl,
10300
- apiKey: config.apiKey,
10301
- id: relation.id,
10302
- tenantId: config.tenantId,
10303
- projectId: config.projectId,
10304
- agentId: config.agentId,
10305
- name: relation.name,
10306
- description: relation.description,
10307
- prompt: "",
10308
- delegateRelations: [],
10309
- subAgentRelations: [],
10310
- transferRelations: []
10311
- })),
10399
+ transferRelations: await Promise.all(
10400
+ enhancedInternalRelations.filter((relation) => relation.relationType === "transfer").map(async (relation) => {
10401
+ const targetToolsForAgent = await agentsCore.getToolsForAgent(dbClient_default)({
10402
+ scopes: {
10403
+ tenantId: config.tenantId,
10404
+ projectId: config.projectId,
10405
+ agentId: config.agentId,
10406
+ subAgentId: relation.id
10407
+ }
10408
+ });
10409
+ let targetTransferRelations = { data: [] };
10410
+ let targetDelegateRelations = { data: [] };
10411
+ try {
10412
+ const [transferRel, delegateRel] = await Promise.all([
10413
+ agentsCore.getRelatedAgentsForAgent(dbClient_default)({
10414
+ scopes: {
10415
+ tenantId: config.tenantId,
10416
+ projectId: config.projectId,
10417
+ agentId: config.agentId
10418
+ },
10419
+ subAgentId: relation.id
10420
+ }),
10421
+ agentsCore.getExternalAgentsForSubAgent(dbClient_default)({
10422
+ scopes: {
10423
+ tenantId: config.tenantId,
10424
+ projectId: config.projectId,
10425
+ agentId: config.agentId,
10426
+ subAgentId: relation.id
10427
+ }
10428
+ })
10429
+ ]);
10430
+ targetTransferRelations = transferRel;
10431
+ targetDelegateRelations = delegateRel;
10432
+ } catch (err) {
10433
+ logger20.info(
10434
+ {
10435
+ agentId: relation.id,
10436
+ error: err?.message || "Unknown error"
10437
+ },
10438
+ "Could not fetch relations for target agent (likely external/team agent), using basic info only"
10439
+ );
10440
+ }
10441
+ const targetAgentTools = await Promise.all(
10442
+ targetToolsForAgent.data.map(async (item) => {
10443
+ const mcpTool = await agentsCore.dbResultToMcpTool(
10444
+ item.tool,
10445
+ dbClient_default,
10446
+ credentialStoreRegistry
10447
+ );
10448
+ if (item.selectedTools && item.selectedTools.length > 0) {
10449
+ const selectedToolsSet = new Set(item.selectedTools);
10450
+ mcpTool.availableTools = mcpTool.availableTools?.filter(
10451
+ (tool3) => selectedToolsSet.has(tool3.name)
10452
+ ) || [];
10453
+ }
10454
+ return mcpTool;
10455
+ })
10456
+ ) ?? [];
10457
+ const targetTransferRelationsConfig = targetTransferRelations.data.filter((rel) => rel.relationType === "transfer").map((rel) => ({
10458
+ baseUrl: config.baseUrl,
10459
+ apiKey: config.apiKey,
10460
+ id: rel.id,
10461
+ tenantId: config.tenantId,
10462
+ projectId: config.projectId,
10463
+ agentId: config.agentId,
10464
+ name: rel.name,
10465
+ description: rel.description,
10466
+ prompt: "",
10467
+ delegateRelations: [],
10468
+ subAgentRelations: [],
10469
+ transferRelations: []
10470
+ // Note: Not including tools for nested relations to avoid infinite recursion
10471
+ }));
10472
+ const targetDelegateRelationsConfig = targetDelegateRelations.data.map(
10473
+ (rel) => ({
10474
+ type: "external",
10475
+ config: {
10476
+ id: rel.externalAgent.id,
10477
+ name: rel.externalAgent.name,
10478
+ description: rel.externalAgent.description || "",
10479
+ baseUrl: rel.externalAgent.baseUrl,
10480
+ headers: rel.headers,
10481
+ credentialReferenceId: rel.externalAgent.credentialReferenceId,
10482
+ relationId: rel.id,
10483
+ relationType: "delegate"
10484
+ }
10485
+ })
10486
+ );
10487
+ return {
10488
+ baseUrl: config.baseUrl,
10489
+ apiKey: config.apiKey,
10490
+ id: relation.id,
10491
+ tenantId: config.tenantId,
10492
+ projectId: config.projectId,
10493
+ agentId: config.agentId,
10494
+ name: relation.name,
10495
+ description: relation.description,
10496
+ prompt: "",
10497
+ delegateRelations: targetDelegateRelationsConfig,
10498
+ subAgentRelations: [],
10499
+ transferRelations: targetTransferRelationsConfig,
10500
+ tools: targetAgentTools
10501
+ // Include target agent's tools for transfer descriptions
10502
+ };
10503
+ })
10504
+ ),
10312
10505
  delegateRelations: [
10313
10506
  ...enhancedInternalRelations.filter((relation) => relation.relationType === "delegate").map((relation) => ({
10314
10507
  type: "internal",
@@ -10323,8 +10516,11 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
10323
10516
  description: relation.description,
10324
10517
  prompt: "",
10325
10518
  delegateRelations: [],
10519
+ // Simplified - no nested relations
10326
10520
  subAgentRelations: [],
10327
- transferRelations: []
10521
+ transferRelations: [],
10522
+ tools: []
10523
+ // Tools are defined in config files, not DB
10328
10524
  }
10329
10525
  })),
10330
10526
  ...externalRelations.data.map((relation) => ({
@@ -11781,7 +11977,27 @@ var ExecutionHandler = class {
11781
11977
  const firstArtifact = messageResponse.result.artifacts[0];
11782
11978
  const transferReason = firstArtifact?.parts[1]?.kind === "text" ? firstArtifact.parts[1].text : "Transfer initiated";
11783
11979
  logger24.info({ targetSubAgentId, transferReason, transferFromAgent }, "Transfer response");
11784
- currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
11980
+ await agentsCore.createMessage(dbClient_default)({
11981
+ id: agentsCore.generateId(),
11982
+ tenantId,
11983
+ projectId,
11984
+ conversationId,
11985
+ role: "agent",
11986
+ content: {
11987
+ text: transferReason,
11988
+ parts: [
11989
+ {
11990
+ kind: "text",
11991
+ text: transferReason
11992
+ }
11993
+ ]
11994
+ },
11995
+ visibility: "user-facing",
11996
+ messageType: "chat",
11997
+ fromSubAgentId: currentAgentId,
11998
+ taskId: task.id
11999
+ });
12000
+ currentMessage = currentMessage + "\n\nPlease continue this conversation seamlessly. The previous response in conversation history was from another internal agent, but you must continue as if YOU made that response. All responses must appear as one unified agent - do not repeat what was already communicated.";
11785
12001
  const { success, targetSubAgentId: newAgentId } = await executeTransfer({
11786
12002
  projectId,
11787
12003
  tenantId,
package/dist/index.js CHANGED
@@ -1534,7 +1534,16 @@ var _ArtifactService = class _ArtifactService {
1534
1534
  );
1535
1535
  return null;
1536
1536
  }
1537
- const artifacts = await getLedgerArtifacts(dbClient_default)({
1537
+ let artifacts = [];
1538
+ artifacts = await getLedgerArtifacts(dbClient_default)({
1539
+ scopes: { tenantId: this.context.tenantId, projectId: this.context.projectId },
1540
+ artifactId,
1541
+ toolCallId
1542
+ });
1543
+ if (artifacts.length > 0) {
1544
+ return this.formatArtifactSummaryData(artifacts[0], artifactId, toolCallId);
1545
+ }
1546
+ artifacts = await getLedgerArtifacts(dbClient_default)({
1538
1547
  scopes: { tenantId: this.context.tenantId, projectId: this.context.projectId },
1539
1548
  artifactId,
1540
1549
  taskId: this.context.taskId
@@ -1580,7 +1589,16 @@ var _ArtifactService = class _ArtifactService {
1580
1589
  );
1581
1590
  return null;
1582
1591
  }
1583
- const artifacts = await getLedgerArtifacts(dbClient_default)({
1592
+ let artifacts = [];
1593
+ artifacts = await getLedgerArtifacts(dbClient_default)({
1594
+ scopes: { tenantId: this.context.tenantId, projectId: this.context.projectId },
1595
+ artifactId,
1596
+ toolCallId
1597
+ });
1598
+ if (artifacts.length > 0) {
1599
+ return this.formatArtifactFullData(artifacts[0], artifactId, toolCallId);
1600
+ }
1601
+ artifacts = await getLedgerArtifacts(dbClient_default)({
1584
1602
  scopes: { tenantId: this.context.tenantId, projectId: this.context.projectId },
1585
1603
  artifactId,
1586
1604
  taskId: this.context.taskId
@@ -3548,15 +3566,8 @@ Make it specific and relevant.`;
3548
3566
  );
3549
3567
  result = object;
3550
3568
  }
3551
- const artifactService = new ArtifactService({
3552
- tenantId: artifactData.tenantId,
3553
- projectId: artifactData.projectId,
3554
- contextId: artifactData.contextId,
3555
- taskId: artifactData.taskId,
3556
- sessionId: this.sessionId
3557
- });
3558
3569
  try {
3559
- await artifactService.saveArtifact({
3570
+ await this.artifactService.saveArtifact({
3560
3571
  artifactId: artifactData.artifactId,
3561
3572
  name: result.name,
3562
3573
  description: result.description,
@@ -3585,14 +3596,14 @@ Make it specific and relevant.`;
3585
3596
  if (!mainSaveSucceeded) {
3586
3597
  try {
3587
3598
  if (artifactData.tenantId && artifactData.projectId) {
3588
- const artifactService2 = new ArtifactService({
3599
+ const artifactService = new ArtifactService({
3589
3600
  tenantId: artifactData.tenantId,
3590
3601
  projectId: artifactData.projectId,
3591
3602
  contextId: artifactData.contextId || "unknown",
3592
3603
  taskId: artifactData.taskId,
3593
3604
  sessionId: this.sessionId
3594
3605
  });
3595
- await artifactService2.saveArtifact({
3606
+ await artifactService.saveArtifact({
3596
3607
  artifactId: artifactData.artifactId,
3597
3608
  name: `Artifact ${artifactData.artifactId.substring(0, 8)}`,
3598
3609
  description: `${artifactData.artifactType || "Data"} from ${artifactData.metadata?.toolName || "tool results"}`,
@@ -5457,24 +5468,95 @@ var A2AClient = class {
5457
5468
  // src/agents/relationTools.ts
5458
5469
  var logger13 = getLogger("relationships Tools");
5459
5470
  var generateTransferToolDescription = (config) => {
5460
- return `Hand off the conversation to agent ${config.id}.
5471
+ let toolsSection = "";
5472
+ let transferSection = "";
5473
+ if (config.transferRelations && config.transferRelations.length > 0) {
5474
+ const transferList = config.transferRelations.map(
5475
+ (transfer) => ` - ${transfer.name || transfer.id}: ${transfer.description || "No description available"}`
5476
+ ).join("\n");
5477
+ transferSection = `
5478
+
5479
+ Can Transfer To:
5480
+ ${transferList}`;
5481
+ }
5482
+ let delegateSection = "";
5483
+ if (config.delegateRelations && config.delegateRelations.length > 0) {
5484
+ const delegateList = config.delegateRelations.map(
5485
+ (delegate) => ` - ${delegate.config.name || delegate.config.id}: ${delegate.config.description || "No description available"} (${delegate.type})`
5486
+ ).join("\n");
5487
+ delegateSection = `
5488
+
5489
+ Can Delegate To:
5490
+ ${delegateList}`;
5491
+ }
5492
+ if (config.tools && config.tools.length > 0) {
5493
+ const toolDescriptions = config.tools.map((tool3) => {
5494
+ const toolsList = tool3.availableTools?.map((t) => ` - ${t.name}: ${t.description || "No description available"}`).join("\n") || "";
5495
+ return `MCP Server: ${tool3.name}
5496
+ ${toolsList}`;
5497
+ }).join("\n\n");
5498
+ toolsSection = `
5499
+
5500
+ Available Tools & Capabilities:
5501
+ ${toolDescriptions}`;
5502
+ }
5503
+ const finalDescription = `Hand off the conversation to agent ${config.id}.
5461
5504
 
5462
5505
  Agent Information:
5463
5506
  - ID: ${config.id}
5464
5507
  - Name: ${config.name ?? "No name provided"}
5465
- - Description: ${config.description ?? "No description provided"}
5508
+ - Description: ${config.description ?? "No description provided"}${toolsSection}${transferSection}${delegateSection}
5466
5509
 
5467
5510
  Hand off the conversation to agent ${config.id} when the user's request would be better handled by this specialized agent.`;
5511
+ return finalDescription;
5468
5512
  };
5469
- var generateDelegateToolDescription = (config) => {
5470
- return `Delegate a specific task to another agent.
5513
+ var generateDelegateToolDescription = (delegateRelation) => {
5514
+ const config = delegateRelation.config;
5515
+ let toolsSection = "";
5516
+ let transferSection = "";
5517
+ let delegateSection = "";
5518
+ if (delegateRelation.type === "internal" && "tools" in config) {
5519
+ const agentConfig = config;
5520
+ if (agentConfig.tools && agentConfig.tools.length > 0) {
5521
+ const toolDescriptions = agentConfig.tools.map((tool3) => {
5522
+ const toolsList = tool3.availableTools?.map((t) => ` - ${t.name}: ${t.description || "No description available"}`).join("\n") || "";
5523
+ return `MCP Server: ${tool3.name}
5524
+ ${toolsList}`;
5525
+ }).join("\n\n");
5526
+ toolsSection = `
5527
+
5528
+ Available Tools & Capabilities:
5529
+ ${toolDescriptions}`;
5530
+ }
5531
+ if (agentConfig.transferRelations && agentConfig.transferRelations.length > 0) {
5532
+ const transferList = agentConfig.transferRelations.map(
5533
+ (transfer) => ` - ${transfer.name || transfer.id}: ${transfer.description || "No description available"}`
5534
+ ).join("\n");
5535
+ transferSection = `
5536
+
5537
+ Can Transfer To:
5538
+ ${transferList}`;
5539
+ }
5540
+ if (agentConfig.delegateRelations && agentConfig.delegateRelations.length > 0) {
5541
+ const delegateList = agentConfig.delegateRelations.map(
5542
+ (delegate) => ` - ${delegate.config.name || delegate.config.id}: ${delegate.config.description || "No description available"} (${delegate.type})`
5543
+ ).join("\n");
5544
+ delegateSection = `
5545
+
5546
+ Can Delegate To:
5547
+ ${delegateList}`;
5548
+ }
5549
+ }
5550
+ const finalDescription = `Delegate a specific task to another agent.
5471
5551
 
5472
5552
  Agent Information:
5473
5553
  - ID: ${config.id}
5474
5554
  - Name: ${config.name}
5475
5555
  - Description: ${config.description || "No description provided"}
5556
+ - Type: ${delegateRelation.type}${toolsSection}${transferSection}${delegateSection}
5476
5557
 
5477
5558
  Delegate a specific task to agent ${config.id} when it seems like the agent can do relevant work.`;
5559
+ return finalDescription;
5478
5560
  };
5479
5561
  var createTransferToAgentTool = ({
5480
5562
  transferConfig,
@@ -5482,8 +5564,9 @@ var createTransferToAgentTool = ({
5482
5564
  subAgent,
5483
5565
  streamRequestId
5484
5566
  }) => {
5567
+ const toolDescription = generateTransferToolDescription(transferConfig);
5485
5568
  return tool({
5486
- description: generateTransferToolDescription(transferConfig),
5569
+ description: toolDescription,
5487
5570
  inputSchema: z5.object({}),
5488
5571
  execute: async () => {
5489
5572
  const activeSpan = trace.getActiveSpan();
@@ -5538,7 +5621,7 @@ function createDelegateToAgentTool({
5538
5621
  credentialStoreRegistry
5539
5622
  }) {
5540
5623
  return tool({
5541
- description: generateDelegateToolDescription(delegateConfig.config),
5624
+ description: generateDelegateToolDescription(delegateConfig),
5542
5625
  inputSchema: z5.object({ message: z5.string() }),
5543
5626
  execute: async (input, context) => {
5544
5627
  const delegationId = `del_${generateId()}`;
@@ -5794,7 +5877,7 @@ var system_prompt_default = `<system_message>
5794
5877
  - You ARE the user's assistant - there are no other agents, specialists, or experts
5795
5878
  - NEVER say you are connecting them to anyone or anything
5796
5879
  - Continue conversations as if you personally have been handling them the entire time
5797
- - Answer questions directly without any transition phrases or transfer language
5880
+ - Answer questions directly without any transition phrases or transfer language except when transferring to another agent or delegating to another agent
5798
5881
  {{TRANSFER_INSTRUCTIONS}}
5799
5882
  {{DELEGATION_INSTRUCTIONS}}
5800
5883
  </security>
@@ -5802,7 +5885,7 @@ var system_prompt_default = `<system_message>
5802
5885
  <interaction_guidelines>
5803
5886
  - Be helpful, accurate, and professional
5804
5887
  - Use tools when appropriate to provide better assistance
5805
- - Explain your reasoning when using tools
5888
+ - Use tools directly without announcing or explaining what you're doing ("Let me search...", "I'll look for...", etc.)
5806
5889
  - Save important tool results as artifacts when they contain structured data that should be preserved and referenced
5807
5890
  - Ask for clarification when requests are ambiguous
5808
5891
 
@@ -5820,11 +5903,6 @@ var system_prompt_default = `<system_message>
5820
5903
  - NEVER mention delegation occurred: just present the results
5821
5904
  - If delegation returns artifacts, reference them as if you created them
5822
5905
 
5823
- \u{1F6A8} TRANSFER TOOL RULES - CRITICAL:
5824
- - When calling transfer_to_* tools, call the tool IMMEDIATELY without any explanatory text
5825
- - Do NOT explain the transfer, do NOT say "I'll hand this off", do NOT provide reasoning
5826
- - Just call the transfer tool directly when you determine it's needed
5827
- - The tool call is sufficient - no additional text should be generated
5828
5906
  </interaction_guidelines>
5829
5907
 
5830
5908
  {{THINKING_PREPARATION_INSTRUCTIONS}}
@@ -6042,9 +6120,24 @@ var Phase1Config = class _Phase1Config {
6042
6120
  if (!hasTransferRelations) {
6043
6121
  return "";
6044
6122
  }
6045
- return `- You have transfer_to_* tools that seamlessly continue the conversation
6046
- - NEVER announce transfers - just call the tool when needed
6047
- - The conversation continues naturally without any transfer language`;
6123
+ return `You are part of a single unified assistant composed of specialized agents. To the user, you must always appear as one continuous, confident voice.
6124
+
6125
+ You have transfer_to_* tools that seamlessly continue the conversation. When you determine another agent should handle a request: ONLY call the appropriate transfer_to_* tool. Do not provide any substantive answer, limitation, or explanation before transferring. NEVER announce, describe, or apologize for a transfer.
6126
+
6127
+ Do NOT stream any text when transferring - call the transfer tool IMMEDIATELY. Do NOT acknowledge the request, do NOT say "Looking into that...", "Let me search...", "I'll help you find...", or provide ANY explanatory text. Place all reasoning or handoff details inside the transfer tool call, not in the user message. The tool call is sufficient - no additional text should be generated.
6128
+
6129
+ CRITICAL: When you receive a user message that ends with "Please continue from where this conversation was left off" - this indicates you are continuing a conversation that another agent started. You should:
6130
+ - Review the conversation history to see what was already communicated to the user
6131
+ - Continue seamlessly from where the previous response left off
6132
+ - Do NOT repeat what was already said in the conversation history
6133
+ - Do NOT announce what you're about to do ("Let me search...", "I'll look for...", etc.)
6134
+ - Proceed directly with the appropriate tool or action
6135
+ - Act as if you have been handling the conversation from the beginning
6136
+
6137
+ When receiving any transfer, act as if you have been engaged from the start. Continue the same tone, context, and style. Never reference other agents, tools, or roles.
6138
+
6139
+ Your goal: preserve the illusion of a single, seamless, intelligent assistant. All user-facing behavior must feel like one continuous conversation, regardless of internal transfers.
6140
+ `;
6048
6141
  }
6049
6142
  generateDelegationInstructions(hasDelegateRelations) {
6050
6143
  if (!hasDelegateRelations) {
@@ -8044,6 +8137,9 @@ var Agent = class {
8044
8137
  try {
8045
8138
  this.streamRequestId = streamRequestId;
8046
8139
  this.streamHelper = streamRequestId ? getStreamHelper(streamRequestId) : void 0;
8140
+ if (streamRequestId && this.artifactComponents.length > 0) {
8141
+ agentSessionManager.updateArtifactComponents(streamRequestId, this.artifactComponents);
8142
+ }
8047
8143
  const conversationId = runtimeContext?.metadata?.conversationId;
8048
8144
  if (conversationId) {
8049
8145
  this.setConversationId(conversationId);
@@ -8791,9 +8887,14 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8791
8887
  const models = "models" in config.agentSchema ? config.agentSchema.models : void 0;
8792
8888
  const stopWhen = "stopWhen" in config.agentSchema ? config.agentSchema.stopWhen : void 0;
8793
8889
  const toolsForAgentResult = await Promise.all(
8794
- toolsForAgent.data.map(
8795
- async (item) => await dbResultToMcpTool(item.tool, dbClient_default, credentialStoreRegistry)
8796
- )
8890
+ toolsForAgent.data.map(async (item) => {
8891
+ const mcpTool = await dbResultToMcpTool(item.tool, dbClient_default, credentialStoreRegistry);
8892
+ if (item.selectedTools && item.selectedTools.length > 0) {
8893
+ const selectedToolsSet = new Set(item.selectedTools);
8894
+ mcpTool.availableTools = mcpTool.availableTools?.filter((tool3) => selectedToolsSet.has(tool3.name)) || [];
8895
+ }
8896
+ return mcpTool;
8897
+ })
8797
8898
  ) ?? [];
8798
8899
  const agent = new Agent(
8799
8900
  {
@@ -8822,20 +8923,112 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8822
8923
  subAgentRelations: [],
8823
8924
  transferRelations: []
8824
8925
  })),
8825
- transferRelations: enhancedInternalRelations.filter((relation) => relation.relationType === "transfer").map((relation) => ({
8826
- baseUrl: config.baseUrl,
8827
- apiKey: config.apiKey,
8828
- id: relation.id,
8829
- tenantId: config.tenantId,
8830
- projectId: config.projectId,
8831
- agentId: config.agentId,
8832
- name: relation.name,
8833
- description: relation.description,
8834
- prompt: "",
8835
- delegateRelations: [],
8836
- subAgentRelations: [],
8837
- transferRelations: []
8838
- })),
8926
+ transferRelations: await Promise.all(
8927
+ enhancedInternalRelations.filter((relation) => relation.relationType === "transfer").map(async (relation) => {
8928
+ const targetToolsForAgent = await getToolsForAgent(dbClient_default)({
8929
+ scopes: {
8930
+ tenantId: config.tenantId,
8931
+ projectId: config.projectId,
8932
+ agentId: config.agentId,
8933
+ subAgentId: relation.id
8934
+ }
8935
+ });
8936
+ let targetTransferRelations = { data: [] };
8937
+ let targetDelegateRelations = { data: [] };
8938
+ try {
8939
+ const [transferRel, delegateRel] = await Promise.all([
8940
+ getRelatedAgentsForAgent(dbClient_default)({
8941
+ scopes: {
8942
+ tenantId: config.tenantId,
8943
+ projectId: config.projectId,
8944
+ agentId: config.agentId
8945
+ },
8946
+ subAgentId: relation.id
8947
+ }),
8948
+ getExternalAgentsForSubAgent(dbClient_default)({
8949
+ scopes: {
8950
+ tenantId: config.tenantId,
8951
+ projectId: config.projectId,
8952
+ agentId: config.agentId,
8953
+ subAgentId: relation.id
8954
+ }
8955
+ })
8956
+ ]);
8957
+ targetTransferRelations = transferRel;
8958
+ targetDelegateRelations = delegateRel;
8959
+ } catch (err) {
8960
+ logger16.info(
8961
+ {
8962
+ agentId: relation.id,
8963
+ error: err?.message || "Unknown error"
8964
+ },
8965
+ "Could not fetch relations for target agent (likely external/team agent), using basic info only"
8966
+ );
8967
+ }
8968
+ const targetAgentTools = await Promise.all(
8969
+ targetToolsForAgent.data.map(async (item) => {
8970
+ const mcpTool = await dbResultToMcpTool(
8971
+ item.tool,
8972
+ dbClient_default,
8973
+ credentialStoreRegistry
8974
+ );
8975
+ if (item.selectedTools && item.selectedTools.length > 0) {
8976
+ const selectedToolsSet = new Set(item.selectedTools);
8977
+ mcpTool.availableTools = mcpTool.availableTools?.filter(
8978
+ (tool3) => selectedToolsSet.has(tool3.name)
8979
+ ) || [];
8980
+ }
8981
+ return mcpTool;
8982
+ })
8983
+ ) ?? [];
8984
+ const targetTransferRelationsConfig = targetTransferRelations.data.filter((rel) => rel.relationType === "transfer").map((rel) => ({
8985
+ baseUrl: config.baseUrl,
8986
+ apiKey: config.apiKey,
8987
+ id: rel.id,
8988
+ tenantId: config.tenantId,
8989
+ projectId: config.projectId,
8990
+ agentId: config.agentId,
8991
+ name: rel.name,
8992
+ description: rel.description,
8993
+ prompt: "",
8994
+ delegateRelations: [],
8995
+ subAgentRelations: [],
8996
+ transferRelations: []
8997
+ // Note: Not including tools for nested relations to avoid infinite recursion
8998
+ }));
8999
+ const targetDelegateRelationsConfig = targetDelegateRelations.data.map(
9000
+ (rel) => ({
9001
+ type: "external",
9002
+ config: {
9003
+ id: rel.externalAgent.id,
9004
+ name: rel.externalAgent.name,
9005
+ description: rel.externalAgent.description || "",
9006
+ baseUrl: rel.externalAgent.baseUrl,
9007
+ headers: rel.headers,
9008
+ credentialReferenceId: rel.externalAgent.credentialReferenceId,
9009
+ relationId: rel.id,
9010
+ relationType: "delegate"
9011
+ }
9012
+ })
9013
+ );
9014
+ return {
9015
+ baseUrl: config.baseUrl,
9016
+ apiKey: config.apiKey,
9017
+ id: relation.id,
9018
+ tenantId: config.tenantId,
9019
+ projectId: config.projectId,
9020
+ agentId: config.agentId,
9021
+ name: relation.name,
9022
+ description: relation.description,
9023
+ prompt: "",
9024
+ delegateRelations: targetDelegateRelationsConfig,
9025
+ subAgentRelations: [],
9026
+ transferRelations: targetTransferRelationsConfig,
9027
+ tools: targetAgentTools
9028
+ // Include target agent's tools for transfer descriptions
9029
+ };
9030
+ })
9031
+ ),
8839
9032
  delegateRelations: [
8840
9033
  ...enhancedInternalRelations.filter((relation) => relation.relationType === "delegate").map((relation) => ({
8841
9034
  type: "internal",
@@ -8850,8 +9043,11 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
8850
9043
  description: relation.description,
8851
9044
  prompt: "",
8852
9045
  delegateRelations: [],
9046
+ // Simplified - no nested relations
8853
9047
  subAgentRelations: [],
8854
- transferRelations: []
9048
+ transferRelations: [],
9049
+ tools: []
9050
+ // Tools are defined in config files, not DB
8855
9051
  }
8856
9052
  })),
8857
9053
  ...externalRelations.data.map((relation) => ({
@@ -10293,7 +10489,27 @@ var ExecutionHandler = class {
10293
10489
  const firstArtifact = messageResponse.result.artifacts[0];
10294
10490
  const transferReason = firstArtifact?.parts[1]?.kind === "text" ? firstArtifact.parts[1].text : "Transfer initiated";
10295
10491
  logger20.info({ targetSubAgentId, transferReason, transferFromAgent }, "Transfer response");
10296
- currentMessage = `<transfer_context> ${transferReason} </transfer_context>`;
10492
+ await createMessage(dbClient_default)({
10493
+ id: generateId(),
10494
+ tenantId,
10495
+ projectId,
10496
+ conversationId,
10497
+ role: "agent",
10498
+ content: {
10499
+ text: transferReason,
10500
+ parts: [
10501
+ {
10502
+ kind: "text",
10503
+ text: transferReason
10504
+ }
10505
+ ]
10506
+ },
10507
+ visibility: "user-facing",
10508
+ messageType: "chat",
10509
+ fromSubAgentId: currentAgentId,
10510
+ taskId: task.id
10511
+ });
10512
+ currentMessage = currentMessage + "\n\nPlease continue this conversation seamlessly. The previous response in conversation history was from another internal agent, but you must continue as if YOU made that response. All responses must appear as one unified agent - do not repeat what was already communicated.";
10297
10513
  const { success, targetSubAgentId: newAgentId } = await executeTransfer({
10298
10514
  projectId,
10299
10515
  tenantId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inkeep/agents-run-api",
3
- "version": "0.31.6",
3
+ "version": "0.31.7",
4
4
  "description": "Agents Run API for Inkeep Agent Framework - handles chat, agent execution, and streaming",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -53,7 +53,7 @@
53
53
  "traverse": "^0.6.11",
54
54
  "ts-pattern": "^5.7.1",
55
55
  "zod": "4.1.5",
56
- "@inkeep/agents-core": "^0.31.6"
56
+ "@inkeep/agents-core": "^0.31.7"
57
57
  },
58
58
  "optionalDependencies": {
59
59
  "keytar": "^7.9.0"
@@ -21,7 +21,7 @@
21
21
  - You ARE the user's assistant - there are no other agents, specialists, or experts
22
22
  - NEVER say you are connecting them to anyone or anything
23
23
  - Continue conversations as if you personally have been handling them the entire time
24
- - Answer questions directly without any transition phrases or transfer language
24
+ - Answer questions directly without any transition phrases or transfer language except when transferring to another agent or delegating to another agent
25
25
  {{TRANSFER_INSTRUCTIONS}}
26
26
  {{DELEGATION_INSTRUCTIONS}}
27
27
  </security>
@@ -29,7 +29,7 @@
29
29
  <interaction_guidelines>
30
30
  - Be helpful, accurate, and professional
31
31
  - Use tools when appropriate to provide better assistance
32
- - Explain your reasoning when using tools
32
+ - Use tools directly without announcing or explaining what you're doing ("Let me search...", "I'll look for...", etc.)
33
33
  - Save important tool results as artifacts when they contain structured data that should be preserved and referenced
34
34
  - Ask for clarification when requests are ambiguous
35
35
 
@@ -47,11 +47,6 @@
47
47
  - NEVER mention delegation occurred: just present the results
48
48
  - If delegation returns artifacts, reference them as if you created them
49
49
 
50
- 🚨 TRANSFER TOOL RULES - CRITICAL:
51
- - When calling transfer_to_* tools, call the tool IMMEDIATELY without any explanatory text
52
- - Do NOT explain the transfer, do NOT say "I'll hand this off", do NOT provide reasoning
53
- - Just call the transfer tool directly when you determine it's needed
54
- - The tool call is sufficient - no additional text should be generated
55
50
  </interaction_guidelines>
56
51
 
57
52
  {{THINKING_PREPARATION_INSTRUCTIONS}}