Skip to content

Commit 915147a

Browse files
committed
Fix: ReAct steps taken logging for debugging AutoAgents
1 parent 2da0c60 commit 915147a

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

crates/codegraph-mcp/src/autoagents/agent_builder.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,23 @@ impl ChatResponse for CodeGraphChatResponse {
190190
}
191191

192192
fn tool_calls(&self) -> Option<Vec<ToolCall>> {
193+
tracing::info!("tool_calls() called with content length: {}", self.content.len());
194+
tracing::debug!("Content preview: {}", &self.content.chars().take(200).collect::<String>());
195+
193196
// Try to parse the response as CodeGraph's JSON format
194197
match serde_json::from_str::<CodeGraphLLMResponse>(&self.content) {
195198
Ok(parsed) => {
199+
tracing::info!("Successfully parsed CodeGraphLLMResponse. has_tool_call={}, is_final={}",
200+
parsed.tool_call.is_some(), parsed.is_final);
201+
196202
// If there's a tool_call and is_final is false, convert to AutoAgents format
197203
if let Some(tool_call) = parsed.tool_call {
198204
if !parsed.is_final {
199205
// Convert parameters to JSON string
200206
let arguments = match serde_json::to_string(&tool_call.parameters) {
201207
Ok(json) => json,
202208
Err(e) => {
203-
tracing::warn!(
209+
tracing::error!(
204210
"Failed to serialize tool call parameters: {}",
205211
e
206212
);
@@ -211,36 +217,38 @@ impl ChatResponse for CodeGraphChatResponse {
211217
// Generate unique ID using atomic counter
212218
let call_id = TOOL_CALL_COUNTER.fetch_add(1, Ordering::SeqCst);
213219

214-
tracing::debug!(
215-
"Parsed tool call: {} with args: {}",
216-
tool_call.tool_name,
217-
arguments
218-
);
219-
220220
let autoagents_tool_call = ToolCall {
221221
id: format!("call_{}", call_id),
222222
call_type: "function".to_string(),
223223
function: FunctionCall {
224-
name: tool_call.tool_name,
225-
arguments,
224+
name: tool_call.tool_name.clone(),
225+
arguments: arguments.clone(),
226226
},
227227
};
228228

229+
tracing::info!(
230+
"Returning tool call: name='{}', args='{}', id='{}'",
231+
tool_call.tool_name,
232+
arguments,
233+
autoagents_tool_call.id
234+
);
235+
229236
return Some(vec![autoagents_tool_call]);
230237
} else {
231-
tracing::debug!("is_final is true, not returning tool calls");
238+
tracing::info!("is_final is true, not returning tool calls");
232239
}
233240
} else {
234-
tracing::debug!("No tool_call in parsed response");
241+
tracing::info!("No tool_call field in parsed response");
235242
}
236243
}
237244
Err(e) => {
238245
// Not a JSON response or doesn't match our format - that's fine
239-
tracing::trace!("Response is not CodeGraph JSON format: {}", e);
246+
tracing::warn!("Response is not CodeGraph JSON format: {}. Content: {}",
247+
e, &self.content.chars().take(500).collect::<String>());
240248
}
241249
}
242250

243-
// No tool calls in response
251+
tracing::info!("tool_calls() returning None");
244252
None
245253
}
246254
}

crates/codegraph-mcp/src/autoagents/codegraph_agent.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,23 @@ pub struct CodeGraphAgentOutput {
2020

2121
impl From<ReActAgentOutput> for CodeGraphAgentOutput {
2222
fn from(output: ReActAgentOutput) -> Self {
23-
let resp = output.response;
23+
let resp = output.response.clone();
24+
let num_steps = output.tool_calls.len();
2425

2526
if output.done && !resp.trim().is_empty() {
2627
// Try to parse as structured JSON
27-
if let Ok(value) = serde_json::from_str::<CodeGraphAgentOutput>(&resp) {
28+
if let Ok(mut value) = serde_json::from_str::<CodeGraphAgentOutput>(&resp) {
29+
// Override steps_taken with actual count from ReActAgentOutput
30+
value.steps_taken = num_steps.to_string();
2831
return value;
2932
}
3033
}
3134

32-
// Fallback: create output from raw response
35+
// Fallback: create output from raw response with actual step count
3336
CodeGraphAgentOutput {
3437
answer: resp,
3538
findings: String::new(),
36-
steps_taken: "0".to_string(),
39+
steps_taken: num_steps.to_string(),
3740
}
3841
}
3942
}

0 commit comments

Comments
 (0)