@@ -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