@inkeep/agents-run-api 0.33.0 → 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,
|
|
@@ -9565,6 +9625,42 @@ var Agent = class {
|
|
|
9565
9625
|
getStreamRequestId() {
|
|
9566
9626
|
return this.streamRequestId || "";
|
|
9567
9627
|
}
|
|
9628
|
+
/**
|
|
9629
|
+
* Format tool result for storage in conversation history
|
|
9630
|
+
*/
|
|
9631
|
+
formatToolResult(toolName, args, result, toolCallId) {
|
|
9632
|
+
const input = args ? JSON.stringify(args, null, 2) : "No input";
|
|
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);
|
|
9647
|
+
return `## Tool: ${toolName}
|
|
9648
|
+
|
|
9649
|
+
### \u{1F527} TOOL_CALL_ID: ${toolCallId}
|
|
9650
|
+
|
|
9651
|
+
### Input
|
|
9652
|
+
${input}
|
|
9653
|
+
|
|
9654
|
+
### Output
|
|
9655
|
+
${output}`;
|
|
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
|
+
}
|
|
9568
9664
|
/**
|
|
9569
9665
|
* Analyze tool result structure and add helpful path hints for artifact creation
|
|
9570
9666
|
* Only adds hints when artifact components are available
|
|
@@ -9864,13 +9960,17 @@ var Agent = class {
|
|
|
9864
9960
|
const historyConfig = this.config.conversationHistoryConfig ?? createDefaultConversationHistoryConfig();
|
|
9865
9961
|
if (historyConfig && historyConfig.mode !== "none") {
|
|
9866
9962
|
if (historyConfig.mode === "full") {
|
|
9963
|
+
const filters = {
|
|
9964
|
+
delegationId: this.delegationId,
|
|
9965
|
+
isDelegated: this.isDelegatedAgent
|
|
9966
|
+
};
|
|
9867
9967
|
conversationHistory = await getFormattedConversationHistory({
|
|
9868
9968
|
tenantId: this.config.tenantId,
|
|
9869
9969
|
projectId: this.config.projectId,
|
|
9870
9970
|
conversationId: contextId,
|
|
9871
9971
|
currentMessage: userMessage,
|
|
9872
9972
|
options: historyConfig,
|
|
9873
|
-
filters
|
|
9973
|
+
filters
|
|
9874
9974
|
});
|
|
9875
9975
|
} else if (historyConfig.mode === "scoped") {
|
|
9876
9976
|
conversationHistory = await getFormattedConversationHistory({
|
|
@@ -9881,7 +9981,9 @@ var Agent = class {
|
|
|
9881
9981
|
options: historyConfig,
|
|
9882
9982
|
filters: {
|
|
9883
9983
|
subAgentId: this.config.id,
|
|
9884
|
-
taskId
|
|
9984
|
+
taskId,
|
|
9985
|
+
delegationId: this.delegationId,
|
|
9986
|
+
isDelegated: this.isDelegatedAgent
|
|
9885
9987
|
}
|
|
9886
9988
|
});
|
|
9887
9989
|
}
|
|
@@ -10457,7 +10559,6 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
10457
10559
|
}
|
|
10458
10560
|
})
|
|
10459
10561
|
]);
|
|
10460
|
-
logger20.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
|
|
10461
10562
|
const enhancedInternalRelations = await Promise.all(
|
|
10462
10563
|
internalRelations.data.map(async (relation) => {
|
|
10463
10564
|
try {
|
|
@@ -10797,10 +10898,12 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
10797
10898
|
}
|
|
10798
10899
|
const streamRequestId = task.context?.metadata?.stream_request_id || task.context?.metadata?.streamRequestId;
|
|
10799
10900
|
const isDelegation = task.context?.metadata?.isDelegation === true;
|
|
10901
|
+
const delegationId = task.context?.metadata?.delegationId;
|
|
10800
10902
|
agent.setDelegationStatus(isDelegation);
|
|
10903
|
+
agent.setDelegationId(delegationId);
|
|
10801
10904
|
if (isDelegation) {
|
|
10802
10905
|
logger20.info(
|
|
10803
|
-
{ subAgentId: config.subAgentId, taskId: task.id },
|
|
10906
|
+
{ subAgentId: config.subAgentId, taskId: task.id, delegationId },
|
|
10804
10907
|
"Delegated agent - streaming disabled"
|
|
10805
10908
|
);
|
|
10806
10909
|
if (streamRequestId && config.tenantId && config.projectId) {
|
|
@@ -10954,7 +11057,7 @@ var createTaskHandlerConfig = async (params) => {
|
|
|
10954
11057
|
throw new Error(`Agent not found: ${params.subAgentId}`);
|
|
10955
11058
|
}
|
|
10956
11059
|
const effectiveModels = await resolveModelConfig(params.agentId, subAgent);
|
|
10957
|
-
const effectiveConversationHistoryConfig = subAgent.conversationHistoryConfig
|
|
11060
|
+
const effectiveConversationHistoryConfig = subAgent.conversationHistoryConfig;
|
|
10958
11061
|
return {
|
|
10959
11062
|
tenantId: params.tenantId,
|
|
10960
11063
|
projectId: params.projectId,
|
|
@@ -11309,40 +11412,16 @@ init_dbClient();
|
|
|
11309
11412
|
init_dbClient();
|
|
11310
11413
|
init_logger();
|
|
11311
11414
|
function isTransferTask(result) {
|
|
11312
|
-
console.log(
|
|
11313
|
-
"[isTransferTask] Checking result:",
|
|
11314
|
-
JSON.stringify(
|
|
11315
|
-
{
|
|
11316
|
-
hasArtifacts: "artifacts" in result,
|
|
11317
|
-
artifactsLength: result.kind === "task" ? result.artifacts?.length : 0,
|
|
11318
|
-
firstArtifactParts: result.kind === "task" ? result.artifacts?.[0]?.parts?.length : 0,
|
|
11319
|
-
allParts: result.kind === "task" ? result.artifacts?.[0]?.parts?.map((p, i) => ({
|
|
11320
|
-
index: i,
|
|
11321
|
-
kind: p.kind,
|
|
11322
|
-
hasData: !!(p.kind === "data" && p.data),
|
|
11323
|
-
dataType: p.kind === "data" ? p.data?.type : void 0,
|
|
11324
|
-
dataKeys: p.kind === "data" ? Object.keys(p.data) : []
|
|
11325
|
-
})) : []
|
|
11326
|
-
},
|
|
11327
|
-
null,
|
|
11328
|
-
2
|
|
11329
|
-
)
|
|
11330
|
-
);
|
|
11331
11415
|
if (!("artifacts" in result) || !result.artifacts) {
|
|
11332
|
-
console.log("[isTransferTask] No artifacts found");
|
|
11333
11416
|
return false;
|
|
11334
11417
|
}
|
|
11335
11418
|
const hasTransfer = result.artifacts.some(
|
|
11336
11419
|
(artifact) => artifact.parts.some((part) => {
|
|
11337
11420
|
if (part.kind !== "data" || !part.data) return false;
|
|
11338
11421
|
const isTransfer = typeof part.data === "object" && "type" in part.data && part.data.type === "transfer";
|
|
11339
|
-
if (isTransfer) {
|
|
11340
|
-
console.log("[isTransferTask] Found transfer data:", JSON.stringify(part.data, null, 2));
|
|
11341
|
-
}
|
|
11342
11422
|
return isTransfer;
|
|
11343
11423
|
})
|
|
11344
11424
|
);
|
|
11345
|
-
console.log("[isTransferTask] Result:", hasTransfer);
|
|
11346
11425
|
return hasTransfer;
|
|
11347
11426
|
}
|
|
11348
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,
|
|
@@ -7890,6 +7933,42 @@ var Agent = class {
|
|
|
7890
7933
|
getStreamRequestId() {
|
|
7891
7934
|
return this.streamRequestId || "";
|
|
7892
7935
|
}
|
|
7936
|
+
/**
|
|
7937
|
+
* Format tool result for storage in conversation history
|
|
7938
|
+
*/
|
|
7939
|
+
formatToolResult(toolName, args, result, toolCallId) {
|
|
7940
|
+
const input = args ? JSON.stringify(args, null, 2) : "No input";
|
|
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);
|
|
7955
|
+
return `## Tool: ${toolName}
|
|
7956
|
+
|
|
7957
|
+
### \u{1F527} TOOL_CALL_ID: ${toolCallId}
|
|
7958
|
+
|
|
7959
|
+
### Input
|
|
7960
|
+
${input}
|
|
7961
|
+
|
|
7962
|
+
### Output
|
|
7963
|
+
${output}`;
|
|
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
|
+
}
|
|
7893
7972
|
/**
|
|
7894
7973
|
* Analyze tool result structure and add helpful path hints for artifact creation
|
|
7895
7974
|
* Only adds hints when artifact components are available
|
|
@@ -8189,13 +8268,17 @@ var Agent = class {
|
|
|
8189
8268
|
const historyConfig = this.config.conversationHistoryConfig ?? createDefaultConversationHistoryConfig();
|
|
8190
8269
|
if (historyConfig && historyConfig.mode !== "none") {
|
|
8191
8270
|
if (historyConfig.mode === "full") {
|
|
8271
|
+
const filters = {
|
|
8272
|
+
delegationId: this.delegationId,
|
|
8273
|
+
isDelegated: this.isDelegatedAgent
|
|
8274
|
+
};
|
|
8192
8275
|
conversationHistory = await getFormattedConversationHistory({
|
|
8193
8276
|
tenantId: this.config.tenantId,
|
|
8194
8277
|
projectId: this.config.projectId,
|
|
8195
8278
|
conversationId: contextId,
|
|
8196
8279
|
currentMessage: userMessage,
|
|
8197
8280
|
options: historyConfig,
|
|
8198
|
-
filters
|
|
8281
|
+
filters
|
|
8199
8282
|
});
|
|
8200
8283
|
} else if (historyConfig.mode === "scoped") {
|
|
8201
8284
|
conversationHistory = await getFormattedConversationHistory({
|
|
@@ -8206,7 +8289,9 @@ var Agent = class {
|
|
|
8206
8289
|
options: historyConfig,
|
|
8207
8290
|
filters: {
|
|
8208
8291
|
subAgentId: this.config.id,
|
|
8209
|
-
taskId
|
|
8292
|
+
taskId,
|
|
8293
|
+
delegationId: this.delegationId,
|
|
8294
|
+
isDelegated: this.isDelegatedAgent
|
|
8210
8295
|
}
|
|
8211
8296
|
});
|
|
8212
8297
|
}
|
|
@@ -8782,7 +8867,6 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
8782
8867
|
}
|
|
8783
8868
|
})
|
|
8784
8869
|
]);
|
|
8785
|
-
logger16.info({ toolsForAgent, internalRelations, externalRelations }, "agent stuff");
|
|
8786
8870
|
const enhancedInternalRelations = await Promise.all(
|
|
8787
8871
|
internalRelations.data.map(async (relation) => {
|
|
8788
8872
|
try {
|
|
@@ -9122,10 +9206,12 @@ var createTaskHandler = (config, credentialStoreRegistry) => {
|
|
|
9122
9206
|
}
|
|
9123
9207
|
const streamRequestId = task.context?.metadata?.stream_request_id || task.context?.metadata?.streamRequestId;
|
|
9124
9208
|
const isDelegation = task.context?.metadata?.isDelegation === true;
|
|
9209
|
+
const delegationId = task.context?.metadata?.delegationId;
|
|
9125
9210
|
agent.setDelegationStatus(isDelegation);
|
|
9211
|
+
agent.setDelegationId(delegationId);
|
|
9126
9212
|
if (isDelegation) {
|
|
9127
9213
|
logger16.info(
|
|
9128
|
-
{ subAgentId: config.subAgentId, taskId: task.id },
|
|
9214
|
+
{ subAgentId: config.subAgentId, taskId: task.id, delegationId },
|
|
9129
9215
|
"Delegated agent - streaming disabled"
|
|
9130
9216
|
);
|
|
9131
9217
|
if (streamRequestId && config.tenantId && config.projectId) {
|
|
@@ -9279,7 +9365,7 @@ var createTaskHandlerConfig = async (params) => {
|
|
|
9279
9365
|
throw new Error(`Agent not found: ${params.subAgentId}`);
|
|
9280
9366
|
}
|
|
9281
9367
|
const effectiveModels = await resolveModelConfig(params.agentId, subAgent);
|
|
9282
|
-
const effectiveConversationHistoryConfig = subAgent.conversationHistoryConfig
|
|
9368
|
+
const effectiveConversationHistoryConfig = subAgent.conversationHistoryConfig;
|
|
9283
9369
|
return {
|
|
9284
9370
|
tenantId: params.tenantId,
|
|
9285
9371
|
projectId: params.projectId,
|
|
@@ -9623,40 +9709,16 @@ app.post("/a2a", async (c) => {
|
|
|
9623
9709
|
});
|
|
9624
9710
|
var agents_default = app;
|
|
9625
9711
|
function isTransferTask(result) {
|
|
9626
|
-
console.log(
|
|
9627
|
-
"[isTransferTask] Checking result:",
|
|
9628
|
-
JSON.stringify(
|
|
9629
|
-
{
|
|
9630
|
-
hasArtifacts: "artifacts" in result,
|
|
9631
|
-
artifactsLength: result.kind === "task" ? result.artifacts?.length : 0,
|
|
9632
|
-
firstArtifactParts: result.kind === "task" ? result.artifacts?.[0]?.parts?.length : 0,
|
|
9633
|
-
allParts: result.kind === "task" ? result.artifacts?.[0]?.parts?.map((p, i) => ({
|
|
9634
|
-
index: i,
|
|
9635
|
-
kind: p.kind,
|
|
9636
|
-
hasData: !!(p.kind === "data" && p.data),
|
|
9637
|
-
dataType: p.kind === "data" ? p.data?.type : void 0,
|
|
9638
|
-
dataKeys: p.kind === "data" ? Object.keys(p.data) : []
|
|
9639
|
-
})) : []
|
|
9640
|
-
},
|
|
9641
|
-
null,
|
|
9642
|
-
2
|
|
9643
|
-
)
|
|
9644
|
-
);
|
|
9645
9712
|
if (!("artifacts" in result) || !result.artifacts) {
|
|
9646
|
-
console.log("[isTransferTask] No artifacts found");
|
|
9647
9713
|
return false;
|
|
9648
9714
|
}
|
|
9649
9715
|
const hasTransfer = result.artifacts.some(
|
|
9650
9716
|
(artifact) => artifact.parts.some((part) => {
|
|
9651
9717
|
if (part.kind !== "data" || !part.data) return false;
|
|
9652
9718
|
const isTransfer = typeof part.data === "object" && "type" in part.data && part.data.type === "transfer";
|
|
9653
|
-
if (isTransfer) {
|
|
9654
|
-
console.log("[isTransferTask] Found transfer data:", JSON.stringify(part.data, null, 2));
|
|
9655
|
-
}
|
|
9656
9719
|
return isTransfer;
|
|
9657
9720
|
})
|
|
9658
9721
|
);
|
|
9659
|
-
console.log("[isTransferTask] Result:", hasTransfer);
|
|
9660
9722
|
return hasTransfer;
|
|
9661
9723
|
}
|
|
9662
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"
|