@inkeep/agents-run-api 0.33.1 → 0.33.2
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.
|
@@ -7,7 +7,7 @@ function createDefaultConversationHistoryConfig(mode = "full") {
|
|
|
7
7
|
mode,
|
|
8
8
|
limit: CONVERSATION_HISTORY_DEFAULT_LIMIT,
|
|
9
9
|
includeInternal: true,
|
|
10
|
-
messageTypes: ["chat"],
|
|
10
|
+
messageTypes: ["chat", "tool-result"],
|
|
11
11
|
maxOutputTokens: CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT
|
|
12
12
|
};
|
|
13
13
|
}
|
|
@@ -67,29 +67,40 @@ async function getScopedHistory({
|
|
|
67
67
|
conversationId,
|
|
68
68
|
options
|
|
69
69
|
});
|
|
70
|
-
if (!filters || !filters.subAgentId && !filters.taskId) {
|
|
70
|
+
if (!filters || !filters.subAgentId && !filters.taskId && !filters.delegationId && filters.isDelegated === void 0) {
|
|
71
71
|
return messages;
|
|
72
72
|
}
|
|
73
73
|
const relevantMessages = messages.filter((msg) => {
|
|
74
74
|
if (msg.role === "user") return true;
|
|
75
75
|
let matchesAgent = true;
|
|
76
76
|
let matchesTask = true;
|
|
77
|
+
let matchesDelegation = true;
|
|
77
78
|
if (filters.subAgentId) {
|
|
78
79
|
matchesAgent = msg.role === "agent" && msg.visibility === "user-facing" || msg.toSubAgentId === filters.subAgentId || msg.fromSubAgentId === filters.subAgentId;
|
|
79
80
|
}
|
|
80
81
|
if (filters.taskId) {
|
|
81
82
|
matchesTask = msg.taskId === filters.taskId || msg.a2aTaskId === filters.taskId;
|
|
82
83
|
}
|
|
83
|
-
if (filters.
|
|
84
|
-
|
|
84
|
+
if (filters.delegationId !== void 0 || filters.isDelegated !== void 0) {
|
|
85
|
+
if (msg.messageType === "tool-result") {
|
|
86
|
+
const messageDelegationId = msg.metadata?.a2a_metadata?.delegationId;
|
|
87
|
+
const messageIsDelegated = msg.metadata?.a2a_metadata?.isDelegated;
|
|
88
|
+
if (filters.delegationId) {
|
|
89
|
+
matchesDelegation = messageDelegationId === filters.delegationId || !messageDelegationId;
|
|
90
|
+
} else if (filters.isDelegated === false) {
|
|
91
|
+
matchesDelegation = !messageIsDelegated;
|
|
92
|
+
} else if (filters.isDelegated === true) {
|
|
93
|
+
matchesDelegation = messageIsDelegated === true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
85
96
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (filters.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return
|
|
97
|
+
const conditions = [];
|
|
98
|
+
if (filters.subAgentId) conditions.push(matchesAgent);
|
|
99
|
+
if (filters.taskId) conditions.push(matchesTask);
|
|
100
|
+
if (filters.delegationId !== void 0 || filters.isDelegated !== void 0)
|
|
101
|
+
conditions.push(matchesDelegation);
|
|
102
|
+
const finalResult = conditions.length === 0 || conditions.every(Boolean);
|
|
103
|
+
return finalResult;
|
|
93
104
|
});
|
|
94
105
|
return relevantMessages;
|
|
95
106
|
} catch (error) {
|
|
@@ -109,10 +120,12 @@ async function getUserFacingHistory(tenantId, projectId, conversationId, limit =
|
|
|
109
120
|
});
|
|
110
121
|
}
|
|
111
122
|
async function getFullConversationContext(tenantId, projectId, conversationId, maxTokens) {
|
|
123
|
+
const defaultConfig = createDefaultConversationHistoryConfig();
|
|
112
124
|
return await getConversationHistory(dbClient_default)({
|
|
113
125
|
scopes: { tenantId, projectId },
|
|
114
126
|
conversationId,
|
|
115
127
|
options: {
|
|
128
|
+
...defaultConfig,
|
|
116
129
|
limit: 100,
|
|
117
130
|
includeInternal: true,
|
|
118
131
|
maxOutputTokens: maxTokens
|
|
@@ -127,7 +140,7 @@ async function getFormattedConversationHistory({
|
|
|
127
140
|
options,
|
|
128
141
|
filters
|
|
129
142
|
}) {
|
|
130
|
-
const historyOptions = options ??
|
|
143
|
+
const historyOptions = options ?? createDefaultConversationHistoryConfig();
|
|
131
144
|
const conversationHistory = await getScopedHistory({
|
|
132
145
|
tenantId,
|
|
133
146
|
projectId,
|
|
@@ -156,6 +169,10 @@ async function getFormattedConversationHistory({
|
|
|
156
169
|
} else if (msg.role === "agent" && msg.messageType === "chat") {
|
|
157
170
|
const fromSubAgent = msg.fromSubAgentId || "unknown";
|
|
158
171
|
roleLabel = `${fromSubAgent} to User`;
|
|
172
|
+
} else if (msg.role === "assistant" && msg.messageType === "tool-result") {
|
|
173
|
+
const fromSubAgent = msg.fromSubAgentId || "unknown";
|
|
174
|
+
const toolName = msg.metadata?.a2a_metadata?.toolName || "unknown";
|
|
175
|
+
roleLabel = `${fromSubAgent} tool: ${toolName}`;
|
|
159
176
|
} else {
|
|
160
177
|
roleLabel = msg.role || "system";
|
|
161
178
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createDefaultConversationHistoryConfig, getConversationScopedArtifacts, getFormattedConversationHistory, getFullConversationContext, getScopedHistory, getUserFacingHistory, saveA2AMessageResponse } from './chunk-
|
|
1
|
+
export { createDefaultConversationHistoryConfig, getConversationScopedArtifacts, getFormattedConversationHistory, getFullConversationContext, getScopedHistory, getUserFacingHistory, saveA2AMessageResponse } from './chunk-7GZGZNDA.js';
|
package/dist/index.cjs
CHANGED
|
@@ -360,7 +360,7 @@ function createDefaultConversationHistoryConfig(mode = "full") {
|
|
|
360
360
|
mode,
|
|
361
361
|
limit: CONVERSATION_HISTORY_DEFAULT_LIMIT,
|
|
362
362
|
includeInternal: true,
|
|
363
|
-
messageTypes: ["chat"],
|
|
363
|
+
messageTypes: ["chat", "tool-result"],
|
|
364
364
|
maxOutputTokens: agentsCore.CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT
|
|
365
365
|
};
|
|
366
366
|
}
|
|
@@ -420,29 +420,40 @@ async function getScopedHistory({
|
|
|
420
420
|
conversationId,
|
|
421
421
|
options
|
|
422
422
|
});
|
|
423
|
-
if (!filters || !filters.subAgentId && !filters.taskId) {
|
|
423
|
+
if (!filters || !filters.subAgentId && !filters.taskId && !filters.delegationId && filters.isDelegated === void 0) {
|
|
424
424
|
return messages;
|
|
425
425
|
}
|
|
426
426
|
const relevantMessages = messages.filter((msg) => {
|
|
427
427
|
if (msg.role === "user") return true;
|
|
428
428
|
let matchesAgent = true;
|
|
429
429
|
let matchesTask = true;
|
|
430
|
+
let matchesDelegation = true;
|
|
430
431
|
if (filters.subAgentId) {
|
|
431
432
|
matchesAgent = msg.role === "agent" && msg.visibility === "user-facing" || msg.toSubAgentId === filters.subAgentId || msg.fromSubAgentId === filters.subAgentId;
|
|
432
433
|
}
|
|
433
434
|
if (filters.taskId) {
|
|
434
435
|
matchesTask = msg.taskId === filters.taskId || msg.a2aTaskId === filters.taskId;
|
|
435
436
|
}
|
|
436
|
-
if (filters.
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
437
|
+
if (filters.delegationId !== void 0 || filters.isDelegated !== void 0) {
|
|
438
|
+
if (msg.messageType === "tool-result") {
|
|
439
|
+
const messageDelegationId = msg.metadata?.a2a_metadata?.delegationId;
|
|
440
|
+
const messageIsDelegated = msg.metadata?.a2a_metadata?.isDelegated;
|
|
441
|
+
if (filters.delegationId) {
|
|
442
|
+
matchesDelegation = messageDelegationId === filters.delegationId || !messageDelegationId;
|
|
443
|
+
} else if (filters.isDelegated === false) {
|
|
444
|
+
matchesDelegation = !messageIsDelegated;
|
|
445
|
+
} else if (filters.isDelegated === true) {
|
|
446
|
+
matchesDelegation = messageIsDelegated === true;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
444
449
|
}
|
|
445
|
-
|
|
450
|
+
const conditions = [];
|
|
451
|
+
if (filters.subAgentId) conditions.push(matchesAgent);
|
|
452
|
+
if (filters.taskId) conditions.push(matchesTask);
|
|
453
|
+
if (filters.delegationId !== void 0 || filters.isDelegated !== void 0)
|
|
454
|
+
conditions.push(matchesDelegation);
|
|
455
|
+
const finalResult = conditions.length === 0 || conditions.every(Boolean);
|
|
456
|
+
return finalResult;
|
|
446
457
|
});
|
|
447
458
|
return relevantMessages;
|
|
448
459
|
} catch (error) {
|
|
@@ -462,10 +473,12 @@ async function getUserFacingHistory(tenantId, projectId, conversationId, limit =
|
|
|
462
473
|
});
|
|
463
474
|
}
|
|
464
475
|
async function getFullConversationContext(tenantId, projectId, conversationId, maxTokens) {
|
|
476
|
+
const defaultConfig2 = createDefaultConversationHistoryConfig();
|
|
465
477
|
return await agentsCore.getConversationHistory(dbClient_default)({
|
|
466
478
|
scopes: { tenantId, projectId },
|
|
467
479
|
conversationId,
|
|
468
480
|
options: {
|
|
481
|
+
...defaultConfig2,
|
|
469
482
|
limit: 100,
|
|
470
483
|
includeInternal: true,
|
|
471
484
|
maxOutputTokens: maxTokens
|
|
@@ -480,7 +493,7 @@ async function getFormattedConversationHistory({
|
|
|
480
493
|
options,
|
|
481
494
|
filters
|
|
482
495
|
}) {
|
|
483
|
-
const historyOptions = options ??
|
|
496
|
+
const historyOptions = options ?? createDefaultConversationHistoryConfig();
|
|
484
497
|
const conversationHistory = await getScopedHistory({
|
|
485
498
|
tenantId,
|
|
486
499
|
projectId,
|
|
@@ -509,6 +522,10 @@ async function getFormattedConversationHistory({
|
|
|
509
522
|
} else if (msg.role === "agent" && msg.messageType === "chat") {
|
|
510
523
|
const fromSubAgent = msg.fromSubAgentId || "unknown";
|
|
511
524
|
roleLabel = `${fromSubAgent} to User`;
|
|
525
|
+
} else if (msg.role === "assistant" && msg.messageType === "tool-result") {
|
|
526
|
+
const fromSubAgent = msg.fromSubAgentId || "unknown";
|
|
527
|
+
const toolName = msg.metadata?.a2a_metadata?.toolName || "unknown";
|
|
528
|
+
roleLabel = `${fromSubAgent} tool: ${toolName}`;
|
|
512
529
|
} else {
|
|
513
530
|
roleLabel = msg.role || "system";
|
|
514
531
|
}
|
|
@@ -4664,10 +4681,12 @@ var AgentSession = class {
|
|
|
4664
4681
|
const conversationHistory = await getFormattedConversationHistory({
|
|
4665
4682
|
tenantId: this.tenantId,
|
|
4666
4683
|
projectId: this.projectId,
|
|
4667
|
-
conversationId: this.
|
|
4684
|
+
conversationId: this.contextId || "default",
|
|
4668
4685
|
options: {
|
|
4669
4686
|
limit: agentsCore.CONVERSATION_HISTORY_DEFAULT_LIMIT,
|
|
4670
|
-
maxOutputTokens: agentsCore.CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT
|
|
4687
|
+
maxOutputTokens: agentsCore.CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT,
|
|
4688
|
+
includeInternal: true,
|
|
4689
|
+
messageTypes: ["chat", "tool-result"]
|
|
4671
4690
|
},
|
|
4672
4691
|
filters: {}
|
|
4673
4692
|
});
|
|
@@ -8594,6 +8613,7 @@ var Agent = class {
|
|
|
8594
8613
|
__publicField(this, "streamHelper");
|
|
8595
8614
|
__publicField(this, "streamRequestId");
|
|
8596
8615
|
__publicField(this, "conversationId");
|
|
8616
|
+
__publicField(this, "delegationId");
|
|
8597
8617
|
__publicField(this, "artifactComponents", []);
|
|
8598
8618
|
__publicField(this, "isDelegatedAgent", false);
|
|
8599
8619
|
__publicField(this, "contextResolver");
|
|
@@ -8731,6 +8751,12 @@ var Agent = class {
|
|
|
8731
8751
|
setDelegationStatus(isDelegated) {
|
|
8732
8752
|
this.isDelegatedAgent = isDelegated;
|
|
8733
8753
|
}
|
|
8754
|
+
/**
|
|
8755
|
+
* Set delegation ID for this agent instance
|
|
8756
|
+
*/
|
|
8757
|
+
setDelegationId(delegationId) {
|
|
8758
|
+
this.delegationId = delegationId;
|
|
8759
|
+
}
|
|
8734
8760
|
/**
|
|
8735
8761
|
* Get streaming helper if this agent should stream to user
|
|
8736
8762
|
* Returns undefined for delegated agents to prevent streaming data operations to user
|
|
@@ -8762,7 +8788,7 @@ var Agent = class {
|
|
|
8762
8788
|
"agent.id": this.config.agentId || "unknown"
|
|
8763
8789
|
});
|
|
8764
8790
|
}
|
|
8765
|
-
const isInternalTool = toolName.includes("save_tool_result") || toolName.includes("thinking_complete") || toolName.startsWith("transfer_to_")
|
|
8791
|
+
const isInternalTool = toolName.includes("save_tool_result") || toolName.includes("thinking_complete") || toolName.startsWith("transfer_to_");
|
|
8766
8792
|
if (streamRequestId && !isInternalTool) {
|
|
8767
8793
|
agentSessionManager.recordEvent(streamRequestId, "tool_call", this.config.id, {
|
|
8768
8794
|
toolName,
|
|
@@ -8773,6 +8799,40 @@ var Agent = class {
|
|
|
8773
8799
|
try {
|
|
8774
8800
|
const result = await originalExecute(args, context);
|
|
8775
8801
|
const duration = Date.now() - startTime;
|
|
8802
|
+
const toolResultConversationId = this.getToolResultConversationId();
|
|
8803
|
+
if (streamRequestId && !isInternalTool && toolResultConversationId) {
|
|
8804
|
+
try {
|
|
8805
|
+
const messageId = agentsCore.generateId();
|
|
8806
|
+
const messagePayload = {
|
|
8807
|
+
id: messageId,
|
|
8808
|
+
tenantId: this.config.tenantId,
|
|
8809
|
+
projectId: this.config.projectId,
|
|
8810
|
+
conversationId: toolResultConversationId,
|
|
8811
|
+
role: "assistant",
|
|
8812
|
+
content: {
|
|
8813
|
+
text: this.formatToolResult(toolName, args, result, toolCallId)
|
|
8814
|
+
},
|
|
8815
|
+
visibility: "internal",
|
|
8816
|
+
messageType: "tool-result",
|
|
8817
|
+
fromSubAgentId: this.config.id,
|
|
8818
|
+
metadata: {
|
|
8819
|
+
a2a_metadata: {
|
|
8820
|
+
toolName,
|
|
8821
|
+
toolCallId,
|
|
8822
|
+
timestamp: Date.now(),
|
|
8823
|
+
delegationId: this.delegationId,
|
|
8824
|
+
isDelegated: this.isDelegatedAgent
|
|
8825
|
+
}
|
|
8826
|
+
}
|
|
8827
|
+
};
|
|
8828
|
+
await agentsCore.createMessage(dbClient_default)(messagePayload);
|
|
8829
|
+
} catch (error) {
|
|
8830
|
+
logger19.warn(
|
|
8831
|
+
{ error, toolName, toolCallId, conversationId: toolResultConversationId },
|
|
8832
|
+
"Failed to store tool result in conversation history"
|
|
8833
|
+
);
|
|
8834
|
+
}
|
|
8835
|
+
}
|
|
8776
8836
|
if (streamRequestId && !isInternalTool) {
|
|
8777
8837
|
agentSessionManager.recordEvent(streamRequestId, "tool_result", this.config.id, {
|
|
8778
8838
|
toolName,
|
|
@@ -9570,7 +9630,20 @@ var Agent = class {
|
|
|
9570
9630
|
*/
|
|
9571
9631
|
formatToolResult(toolName, args, result, toolCallId) {
|
|
9572
9632
|
const input = args ? JSON.stringify(args, null, 2) : "No input";
|
|
9573
|
-
|
|
9633
|
+
let parsedResult = result;
|
|
9634
|
+
if (typeof result === "string") {
|
|
9635
|
+
try {
|
|
9636
|
+
parsedResult = JSON.parse(result);
|
|
9637
|
+
} catch (e) {
|
|
9638
|
+
}
|
|
9639
|
+
}
|
|
9640
|
+
const cleanResult = parsedResult && typeof parsedResult === "object" && !Array.isArray(parsedResult) ? {
|
|
9641
|
+
...parsedResult,
|
|
9642
|
+
result: parsedResult.result && typeof parsedResult.result === "object" && !Array.isArray(parsedResult.result) ? Object.fromEntries(
|
|
9643
|
+
Object.entries(parsedResult.result).filter(([key]) => key !== "_structureHints")
|
|
9644
|
+
) : parsedResult.result
|
|
9645
|
+
} : parsedResult;
|
|
9646
|
+
const output = typeof cleanResult === "string" ? cleanResult : JSON.stringify(cleanResult, null, 2);
|
|
9574
9647
|
return `## Tool: ${toolName}
|
|
9575
9648
|
|
|
9576
9649
|
### \u{1F527} TOOL_CALL_ID: ${toolCallId}
|
|
@@ -9581,6 +9654,13 @@ ${input}
|
|
|
9581
9654
|
### Output
|
|
9582
9655
|
${output}`;
|
|
9583
9656
|
}
|
|
9657
|
+
/**
|
|
9658
|
+
* Get the conversation ID for storing tool results
|
|
9659
|
+
* Always uses the real conversation ID - delegation filtering happens at query time
|
|
9660
|
+
*/
|
|
9661
|
+
getToolResultConversationId() {
|
|
9662
|
+
return this.conversationId;
|
|
9663
|
+
}
|
|
9584
9664
|
/**
|
|
9585
9665
|
* Analyze tool result structure and add helpful path hints for artifact creation
|
|
9586
9666
|
* Only adds hints when artifact components are available
|
|
@@ -9880,13 +9960,17 @@ ${output}`;
|
|
|
9880
9960
|
const historyConfig = this.config.conversationHistoryConfig ?? createDefaultConversationHistoryConfig();
|
|
9881
9961
|
if (historyConfig && historyConfig.mode !== "none") {
|
|
9882
9962
|
if (historyConfig.mode === "full") {
|
|
9963
|
+
const filters = {
|
|
9964
|
+
delegationId: this.delegationId,
|
|
9965
|
+
isDelegated: this.isDelegatedAgent
|
|
9966
|
+
};
|
|
9883
9967
|
conversationHistory = await getFormattedConversationHistory({
|
|
9884
9968
|
tenantId: this.config.tenantId,
|
|
9885
9969
|
projectId: this.config.projectId,
|
|
9886
9970
|
conversationId: contextId,
|
|
9887
9971
|
currentMessage: userMessage,
|
|
9888
9972
|
options: historyConfig,
|
|
9889
|
-
filters
|
|
9973
|
+
filters
|
|
9890
9974
|
});
|
|
9891
9975
|
} else if (historyConfig.mode === "scoped") {
|
|
9892
9976
|
conversationHistory = await getFormattedConversationHistory({
|
|
@@ -9897,7 +9981,9 @@ ${output}`;
|
|
|
9897
9981
|
options: historyConfig,
|
|
9898
9982
|
filters: {
|
|
9899
9983
|
subAgentId: this.config.id,
|
|
9900
|
-
taskId
|
|
9984
|
+
taskId,
|
|
9985
|
+
delegationId: this.delegationId,
|
|
9986
|
+
isDelegated: this.isDelegatedAgent
|
|
9901
9987
|
}
|
|
9902
9988
|
});
|
|
9903
9989
|
}
|
|
@@ -10473,7 +10559,6 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
10473
10559
|
}
|
|
10474
10560
|
})
|
|
10475
10561
|
]);
|
|
10476
|
-
logger20.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
|
|
10477
10562
|
const enhancedInternalRelations = await Promise.all(
|
|
10478
10563
|
internalRelations.data.map(async (relation) => {
|
|
10479
10564
|
try {
|
|
@@ -10813,10 +10898,12 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
10813
10898
|
}
|
|
10814
10899
|
const streamRequestId = task.context?.metadata?.stream_request_id || task.context?.metadata?.streamRequestId;
|
|
10815
10900
|
const isDelegation = task.context?.metadata?.isDelegation === true;
|
|
10901
|
+
const delegationId = task.context?.metadata?.delegationId;
|
|
10816
10902
|
agent.setDelegationStatus(isDelegation);
|
|
10903
|
+
agent.setDelegationId(delegationId);
|
|
10817
10904
|
if (isDelegation) {
|
|
10818
10905
|
logger20.info(
|
|
10819
|
-
{ subAgentId: config.subAgentId, taskId: task.id },
|
|
10906
|
+
{ subAgentId: config.subAgentId, taskId: task.id, delegationId },
|
|
10820
10907
|
"Delegated agent - streaming disabled"
|
|
10821
10908
|
);
|
|
10822
10909
|
if (streamRequestId && config.tenantId && config.projectId) {
|
|
@@ -10970,7 +11057,7 @@ var createTaskHandlerConfig = async (params) => {
|
|
|
10970
11057
|
throw new Error(`Agent not found: ${params.subAgentId}`);
|
|
10971
11058
|
}
|
|
10972
11059
|
const effectiveModels = await resolveModelConfig(params.agentId, subAgent);
|
|
10973
|
-
const effectiveConversationHistoryConfig = subAgent.conversationHistoryConfig
|
|
11060
|
+
const effectiveConversationHistoryConfig = subAgent.conversationHistoryConfig;
|
|
10974
11061
|
return {
|
|
10975
11062
|
tenantId: params.tenantId,
|
|
10976
11063
|
projectId: params.projectId,
|
|
@@ -11325,40 +11412,16 @@ init_dbClient();
|
|
|
11325
11412
|
init_dbClient();
|
|
11326
11413
|
init_logger();
|
|
11327
11414
|
function isTransferTask(result) {
|
|
11328
|
-
console.log(
|
|
11329
|
-
"[isTransferTask] Checking result:",
|
|
11330
|
-
JSON.stringify(
|
|
11331
|
-
{
|
|
11332
|
-
hasArtifacts: "artifacts" in result,
|
|
11333
|
-
artifactsLength: result.kind === "task" ? result.artifacts?.length : 0,
|
|
11334
|
-
firstArtifactParts: result.kind === "task" ? result.artifacts?.[0]?.parts?.length : 0,
|
|
11335
|
-
allParts: result.kind === "task" ? result.artifacts?.[0]?.parts?.map((p, i) => ({
|
|
11336
|
-
index: i,
|
|
11337
|
-
kind: p.kind,
|
|
11338
|
-
hasData: !!(p.kind === "data" && p.data),
|
|
11339
|
-
dataType: p.kind === "data" ? p.data?.type : void 0,
|
|
11340
|
-
dataKeys: p.kind === "data" ? Object.keys(p.data) : []
|
|
11341
|
-
})) : []
|
|
11342
|
-
},
|
|
11343
|
-
null,
|
|
11344
|
-
2
|
|
11345
|
-
)
|
|
11346
|
-
);
|
|
11347
11415
|
if (!("artifacts" in result) || !result.artifacts) {
|
|
11348
|
-
console.log("[isTransferTask] No artifacts found");
|
|
11349
11416
|
return false;
|
|
11350
11417
|
}
|
|
11351
11418
|
const hasTransfer = result.artifacts.some(
|
|
11352
11419
|
(artifact) => artifact.parts.some((part) => {
|
|
11353
11420
|
if (part.kind !== "data" || !part.data) return false;
|
|
11354
11421
|
const isTransfer = typeof part.data === "object" && "type" in part.data && part.data.type === "transfer";
|
|
11355
|
-
if (isTransfer) {
|
|
11356
|
-
console.log("[isTransferTask] Found transfer data:", JSON.stringify(part.data, null, 2));
|
|
11357
|
-
}
|
|
11358
11422
|
return isTransfer;
|
|
11359
11423
|
})
|
|
11360
11424
|
);
|
|
11361
|
-
console.log("[isTransferTask] Result:", hasTransfer);
|
|
11362
11425
|
return hasTransfer;
|
|
11363
11426
|
}
|
|
11364
11427
|
function extractTransferData(task) {
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { flushBatchProcessor } from './chunk-H2IQDFCM.js';
|
|
2
|
-
import { getFormattedConversationHistory, createDefaultConversationHistoryConfig, saveA2AMessageResponse } from './chunk-
|
|
2
|
+
import { getFormattedConversationHistory, createDefaultConversationHistoryConfig, saveA2AMessageResponse } from './chunk-7GZGZNDA.js';
|
|
3
3
|
import { dbClient_default } from './chunk-4HDXSU6S.js';
|
|
4
4
|
import { env } from './chunk-UZXC6MEO.js';
|
|
5
5
|
import { getLogger } from './chunk-A2S7GSHL.js';
|
|
@@ -3017,10 +3017,12 @@ var AgentSession = class {
|
|
|
3017
3017
|
const conversationHistory = await getFormattedConversationHistory({
|
|
3018
3018
|
tenantId: this.tenantId,
|
|
3019
3019
|
projectId: this.projectId,
|
|
3020
|
-
conversationId: this.
|
|
3020
|
+
conversationId: this.contextId || "default",
|
|
3021
3021
|
options: {
|
|
3022
3022
|
limit: CONVERSATION_HISTORY_DEFAULT_LIMIT,
|
|
3023
|
-
maxOutputTokens: CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT
|
|
3023
|
+
maxOutputTokens: CONVERSATION_HISTORY_MAX_OUTPUT_TOKENS_DEFAULT,
|
|
3024
|
+
includeInternal: true,
|
|
3025
|
+
messageTypes: ["chat", "tool-result"]
|
|
3024
3026
|
},
|
|
3025
3027
|
filters: {}
|
|
3026
3028
|
});
|
|
@@ -6919,6 +6921,7 @@ var Agent = class {
|
|
|
6919
6921
|
__publicField(this, "streamHelper");
|
|
6920
6922
|
__publicField(this, "streamRequestId");
|
|
6921
6923
|
__publicField(this, "conversationId");
|
|
6924
|
+
__publicField(this, "delegationId");
|
|
6922
6925
|
__publicField(this, "artifactComponents", []);
|
|
6923
6926
|
__publicField(this, "isDelegatedAgent", false);
|
|
6924
6927
|
__publicField(this, "contextResolver");
|
|
@@ -7056,6 +7059,12 @@ var Agent = class {
|
|
|
7056
7059
|
setDelegationStatus(isDelegated) {
|
|
7057
7060
|
this.isDelegatedAgent = isDelegated;
|
|
7058
7061
|
}
|
|
7062
|
+
/**
|
|
7063
|
+
* Set delegation ID for this agent instance
|
|
7064
|
+
*/
|
|
7065
|
+
setDelegationId(delegationId) {
|
|
7066
|
+
this.delegationId = delegationId;
|
|
7067
|
+
}
|
|
7059
7068
|
/**
|
|
7060
7069
|
* Get streaming helper if this agent should stream to user
|
|
7061
7070
|
* Returns undefined for delegated agents to prevent streaming data operations to user
|
|
@@ -7087,7 +7096,7 @@ var Agent = class {
|
|
|
7087
7096
|
"agent.id": this.config.agentId || "unknown"
|
|
7088
7097
|
});
|
|
7089
7098
|
}
|
|
7090
|
-
const isInternalTool = toolName.includes("save_tool_result") || toolName.includes("thinking_complete") || toolName.startsWith("transfer_to_")
|
|
7099
|
+
const isInternalTool = toolName.includes("save_tool_result") || toolName.includes("thinking_complete") || toolName.startsWith("transfer_to_");
|
|
7091
7100
|
if (streamRequestId && !isInternalTool) {
|
|
7092
7101
|
agentSessionManager.recordEvent(streamRequestId, "tool_call", this.config.id, {
|
|
7093
7102
|
toolName,
|
|
@@ -7098,6 +7107,40 @@ var Agent = class {
|
|
|
7098
7107
|
try {
|
|
7099
7108
|
const result = await originalExecute(args, context);
|
|
7100
7109
|
const duration = Date.now() - startTime;
|
|
7110
|
+
const toolResultConversationId = this.getToolResultConversationId();
|
|
7111
|
+
if (streamRequestId && !isInternalTool && toolResultConversationId) {
|
|
7112
|
+
try {
|
|
7113
|
+
const messageId = generateId();
|
|
7114
|
+
const messagePayload = {
|
|
7115
|
+
id: messageId,
|
|
7116
|
+
tenantId: this.config.tenantId,
|
|
7117
|
+
projectId: this.config.projectId,
|
|
7118
|
+
conversationId: toolResultConversationId,
|
|
7119
|
+
role: "assistant",
|
|
7120
|
+
content: {
|
|
7121
|
+
text: this.formatToolResult(toolName, args, result, toolCallId)
|
|
7122
|
+
},
|
|
7123
|
+
visibility: "internal",
|
|
7124
|
+
messageType: "tool-result",
|
|
7125
|
+
fromSubAgentId: this.config.id,
|
|
7126
|
+
metadata: {
|
|
7127
|
+
a2a_metadata: {
|
|
7128
|
+
toolName,
|
|
7129
|
+
toolCallId,
|
|
7130
|
+
timestamp: Date.now(),
|
|
7131
|
+
delegationId: this.delegationId,
|
|
7132
|
+
isDelegated: this.isDelegatedAgent
|
|
7133
|
+
}
|
|
7134
|
+
}
|
|
7135
|
+
};
|
|
7136
|
+
await createMessage(dbClient_default)(messagePayload);
|
|
7137
|
+
} catch (error) {
|
|
7138
|
+
logger15.warn(
|
|
7139
|
+
{ error, toolName, toolCallId, conversationId: toolResultConversationId },
|
|
7140
|
+
"Failed to store tool result in conversation history"
|
|
7141
|
+
);
|
|
7142
|
+
}
|
|
7143
|
+
}
|
|
7101
7144
|
if (streamRequestId && !isInternalTool) {
|
|
7102
7145
|
agentSessionManager.recordEvent(streamRequestId, "tool_result", this.config.id, {
|
|
7103
7146
|
toolName,
|
|
@@ -7783,7 +7826,7 @@ var Agent = class {
|
|
|
7783
7826
|
inputSchema: tool3.inputSchema || tool3.parameters || {},
|
|
7784
7827
|
usageGuidelines: name.startsWith("transfer_to_") || name.startsWith("delegate_to_") ? `Use this tool to ${name.startsWith("transfer_to_") ? "transfer" : "delegate"} to another agent when appropriate.` : "Use this tool when appropriate for the task at hand."
|
|
7785
7828
|
}));
|
|
7786
|
-
const { getConversationScopedArtifacts } = await import('./conversations-
|
|
7829
|
+
const { getConversationScopedArtifacts } = await import('./conversations-WAUHDR5J.js');
|
|
7787
7830
|
const historyConfig = this.config.conversationHistoryConfig ?? createDefaultConversationHistoryConfig();
|
|
7788
7831
|
const referenceArtifacts = await getConversationScopedArtifacts({
|
|
7789
7832
|
tenantId: this.config.tenantId,
|
|
@@ -7895,7 +7938,20 @@ var Agent = class {
|
|
|
7895
7938
|
*/
|
|
7896
7939
|
formatToolResult(toolName, args, result, toolCallId) {
|
|
7897
7940
|
const input = args ? JSON.stringify(args, null, 2) : "No input";
|
|
7898
|
-
|
|
7941
|
+
let parsedResult = result;
|
|
7942
|
+
if (typeof result === "string") {
|
|
7943
|
+
try {
|
|
7944
|
+
parsedResult = JSON.parse(result);
|
|
7945
|
+
} catch (e) {
|
|
7946
|
+
}
|
|
7947
|
+
}
|
|
7948
|
+
const cleanResult = parsedResult && typeof parsedResult === "object" && !Array.isArray(parsedResult) ? {
|
|
7949
|
+
...parsedResult,
|
|
7950
|
+
result: parsedResult.result && typeof parsedResult.result === "object" && !Array.isArray(parsedResult.result) ? Object.fromEntries(
|
|
7951
|
+
Object.entries(parsedResult.result).filter(([key]) => key !== "_structureHints")
|
|
7952
|
+
) : parsedResult.result
|
|
7953
|
+
} : parsedResult;
|
|
7954
|
+
const output = typeof cleanResult === "string" ? cleanResult : JSON.stringify(cleanResult, null, 2);
|
|
7899
7955
|
return `## Tool: ${toolName}
|
|
7900
7956
|
|
|
7901
7957
|
### \u{1F527} TOOL_CALL_ID: ${toolCallId}
|
|
@@ -7906,6 +7962,13 @@ ${input}
|
|
|
7906
7962
|
### Output
|
|
7907
7963
|
${output}`;
|
|
7908
7964
|
}
|
|
7965
|
+
/**
|
|
7966
|
+
* Get the conversation ID for storing tool results
|
|
7967
|
+
* Always uses the real conversation ID - delegation filtering happens at query time
|
|
7968
|
+
*/
|
|
7969
|
+
getToolResultConversationId() {
|
|
7970
|
+
return this.conversationId;
|
|
7971
|
+
}
|
|
7909
7972
|
/**
|
|
7910
7973
|
* Analyze tool result structure and add helpful path hints for artifact creation
|
|
7911
7974
|
* Only adds hints when artifact components are available
|
|
@@ -8205,13 +8268,17 @@ ${output}`;
|
|
|
8205
8268
|
const historyConfig = this.config.conversationHistoryConfig ?? createDefaultConversationHistoryConfig();
|
|
8206
8269
|
if (historyConfig && historyConfig.mode !== "none") {
|
|
8207
8270
|
if (historyConfig.mode === "full") {
|
|
8271
|
+
const filters = {
|
|
8272
|
+
delegationId: this.delegationId,
|
|
8273
|
+
isDelegated: this.isDelegatedAgent
|
|
8274
|
+
};
|
|
8208
8275
|
conversationHistory = await getFormattedConversationHistory({
|
|
8209
8276
|
tenantId: this.config.tenantId,
|
|
8210
8277
|
projectId: this.config.projectId,
|
|
8211
8278
|
conversationId: contextId,
|
|
8212
8279
|
currentMessage: userMessage,
|
|
8213
8280
|
options: historyConfig,
|
|
8214
|
-
filters
|
|
8281
|
+
filters
|
|
8215
8282
|
});
|
|
8216
8283
|
} else if (historyConfig.mode === "scoped") {
|
|
8217
8284
|
conversationHistory = await getFormattedConversationHistory({
|
|
@@ -8222,7 +8289,9 @@ ${output}`;
|
|
|
8222
8289
|
options: historyConfig,
|
|
8223
8290
|
filters: {
|
|
8224
8291
|
subAgentId: this.config.id,
|
|
8225
|
-
taskId
|
|
8292
|
+
taskId,
|
|
8293
|
+
delegationId: this.delegationId,
|
|
8294
|
+
isDelegated: this.isDelegatedAgent
|
|
8226
8295
|
}
|
|
8227
8296
|
});
|
|
8228
8297
|
}
|
|
@@ -8798,7 +8867,6 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8798
8867
|
}
|
|
8799
8868
|
})
|
|
8800
8869
|
]);
|
|
8801
|
-
logger16.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
|
|
8802
8870
|
const enhancedInternalRelations = await Promise.all(
|
|
8803
8871
|
internalRelations.data.map(async (relation) => {
|
|
8804
8872
|
try {
|
|
@@ -9138,10 +9206,12 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9138
9206
|
}
|
|
9139
9207
|
const streamRequestId = task.context?.metadata?.stream_request_id || task.context?.metadata?.streamRequestId;
|
|
9140
9208
|
const isDelegation = task.context?.metadata?.isDelegation === true;
|
|
9209
|
+
const delegationId = task.context?.metadata?.delegationId;
|
|
9141
9210
|
agent.setDelegationStatus(isDelegation);
|
|
9211
|
+
agent.setDelegationId(delegationId);
|
|
9142
9212
|
if (isDelegation) {
|
|
9143
9213
|
logger16.info(
|
|
9144
|
-
{ subAgentId: config.subAgentId, taskId: task.id },
|
|
9214
|
+
{ subAgentId: config.subAgentId, taskId: task.id, delegationId },
|
|
9145
9215
|
"Delegated agent - streaming disabled"
|
|
9146
9216
|
);
|
|
9147
9217
|
if (streamRequestId && config.tenantId && config.projectId) {
|
|
@@ -9295,7 +9365,7 @@ var createTaskHandlerConfig = async (params) => {
|
|
|
9295
9365
|
throw new Error(`Agent not found: ${params.subAgentId}`);
|
|
9296
9366
|
}
|
|
9297
9367
|
const effectiveModels = await resolveModelConfig(params.agentId, subAgent);
|
|
9298
|
-
const effectiveConversationHistoryConfig = subAgent.conversationHistoryConfig
|
|
9368
|
+
const effectiveConversationHistoryConfig = subAgent.conversationHistoryConfig;
|
|
9299
9369
|
return {
|
|
9300
9370
|
tenantId: params.tenantId,
|
|
9301
9371
|
projectId: params.projectId,
|
|
@@ -9639,40 +9709,16 @@ app.post("/a2a", async (c) => {
|
|
|
9639
9709
|
});
|
|
9640
9710
|
var agents_default = app;
|
|
9641
9711
|
function isTransferTask(result) {
|
|
9642
|
-
console.log(
|
|
9643
|
-
"[isTransferTask] Checking result:",
|
|
9644
|
-
JSON.stringify(
|
|
9645
|
-
{
|
|
9646
|
-
hasArtifacts: "artifacts" in result,
|
|
9647
|
-
artifactsLength: result.kind === "task" ? result.artifacts?.length : 0,
|
|
9648
|
-
firstArtifactParts: result.kind === "task" ? result.artifacts?.[0]?.parts?.length : 0,
|
|
9649
|
-
allParts: result.kind === "task" ? result.artifacts?.[0]?.parts?.map((p, i) => ({
|
|
9650
|
-
index: i,
|
|
9651
|
-
kind: p.kind,
|
|
9652
|
-
hasData: !!(p.kind === "data" && p.data),
|
|
9653
|
-
dataType: p.kind === "data" ? p.data?.type : void 0,
|
|
9654
|
-
dataKeys: p.kind === "data" ? Object.keys(p.data) : []
|
|
9655
|
-
})) : []
|
|
9656
|
-
},
|
|
9657
|
-
null,
|
|
9658
|
-
2
|
|
9659
|
-
)
|
|
9660
|
-
);
|
|
9661
9712
|
if (!("artifacts" in result) || !result.artifacts) {
|
|
9662
|
-
console.log("[isTransferTask] No artifacts found");
|
|
9663
9713
|
return false;
|
|
9664
9714
|
}
|
|
9665
9715
|
const hasTransfer = result.artifacts.some(
|
|
9666
9716
|
(artifact) => artifact.parts.some((part) => {
|
|
9667
9717
|
if (part.kind !== "data" || !part.data) return false;
|
|
9668
9718
|
const isTransfer = typeof part.data === "object" && "type" in part.data && part.data.type === "transfer";
|
|
9669
|
-
if (isTransfer) {
|
|
9670
|
-
console.log("[isTransferTask] Found transfer data:", JSON.stringify(part.data, null, 2));
|
|
9671
|
-
}
|
|
9672
9719
|
return isTransfer;
|
|
9673
9720
|
})
|
|
9674
9721
|
);
|
|
9675
|
-
console.log("[isTransferTask] Result:", hasTransfer);
|
|
9676
9722
|
return hasTransfer;
|
|
9677
9723
|
}
|
|
9678
9724
|
function extractTransferData(task) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inkeep/agents-run-api",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.2",
|
|
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.33.
|
|
56
|
+
"@inkeep/agents-core": "^0.33.2"
|
|
57
57
|
},
|
|
58
58
|
"optionalDependencies": {
|
|
59
59
|
"keytar": "^7.9.0"
|