Skip to content

Commit b54c7a9

Browse files
inkeep-oss-sync[bot]shagun-singh-inkeepinkeep-internal-ci[bot]
authored
Include tool results and calls in conversation history if Signoz fetch fails (#1958) (#3394)
* base * fix * style: auto-format with biome --------- GitOrigin-RevId: 035f14a199553ca2bdbfd738b03e5d87a1651db9 Co-authored-by: shagun-singh-inkeep <shagun.singh@inkeep.com> Co-authored-by: inkeep-internal-ci[bot] <259778081+inkeep-internal-ci[bot]@users.noreply.github.com>
1 parent c4a33da commit b54c7a9

2 files changed

Lines changed: 61 additions & 15 deletions

File tree

.changeset/funny-sloths-lay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@inkeep/agents-api": patch
3+
---
4+
5+
Include tool results and calls in conversation history if Signoz fetch fails

agents-api/src/domains/evals/services/EvaluationService.ts

Lines changed: 56 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,11 @@ export class EvaluationService {
6464
throw new Error('Failed to resolve ref');
6565
}
6666

67-
// Get conversation history
68-
const conversationHistory = await getConversationHistory(runDbClient)({
69-
scopes: { tenantId, projectId },
70-
conversationId: conversation.id,
71-
options: {
72-
includeInternal: false,
73-
limit: 100,
74-
},
75-
});
76-
7767
// Get agent definition
7868
let agentDefinition: FullAgentDefinition | null = null;
7969
let agentId: string | null = null;
8070

8171
try {
82-
// Get agentId from subagent
8372
agentId = conversation.agentId ?? null;
8473

8574
if (agentId) {
@@ -117,13 +106,65 @@ export class EvaluationService {
117106
'Trace fetch completed'
118107
);
119108

120-
const conversationText = JSON.stringify(conversationHistory, null, 2);
109+
let conversationText: string;
110+
let traceText: string;
111+
112+
if (prettifiedTrace) {
113+
traceText = JSON.stringify(prettifiedTrace, null, 2);
114+
try {
115+
const conversationHistory = await getConversationHistory(runDbClient)({
116+
scopes: { tenantId, projectId },
117+
conversationId: conversation.id,
118+
options: {
119+
includeInternal: false,
120+
limit: 100,
121+
},
122+
});
123+
conversationText = JSON.stringify(conversationHistory, null, 2);
124+
} catch (error) {
125+
logger.warn(
126+
{ error, conversationId: conversation.id },
127+
'Failed to fetch conversation history, proceeding without it'
128+
);
129+
conversationText = 'Conversation history not available';
130+
}
131+
} else {
132+
try {
133+
const fullHistory = await getConversationHistory(runDbClient)({
134+
scopes: { tenantId, projectId },
135+
conversationId: conversation.id,
136+
options: {
137+
includeInternal: true,
138+
limit: 200,
139+
},
140+
});
141+
142+
logger.info(
143+
{
144+
conversationId: conversation.id,
145+
fullHistoryCount: fullHistory.length,
146+
hasToolMessages: fullHistory.some(
147+
(m) => m.messageType === 'tool-call' || m.messageType === 'tool-result'
148+
),
149+
},
150+
'Trace unavailable, using full conversation history with tool messages as fallback'
151+
);
152+
153+
conversationText = JSON.stringify(fullHistory, null, 2);
154+
} catch (error) {
155+
logger.warn(
156+
{ error, conversationId: conversation.id },
157+
'Failed to fetch full conversation history fallback, proceeding without it'
158+
);
159+
conversationText = 'Conversation history not available';
160+
}
161+
traceText =
162+
'Trace data not available — tool call details are included in Conversation History above.';
163+
}
164+
121165
const agentDefinitionText = agentDefinition
122166
? JSON.stringify(agentDefinition, null, 2)
123167
: 'Agent definition not available';
124-
const traceText = prettifiedTrace
125-
? JSON.stringify(prettifiedTrace, null, 2)
126-
: 'Trace data not available';
127168

128169
const modelConfig: ModelSettings = (evaluator.model ?? {}) as ModelSettings;
129170

0 commit comments

Comments
 (0)