From 64bed2b2d936b902a6214affc7e7fe9591d93bfa Mon Sep 17 00:00:00 2001 From: Tomas Carnecky Date: Sat, 6 Jun 2026 16:19:20 +0200 Subject: [PATCH] Trace LLM interaction --- Cargo.lock | 1 + bin/pudox-run/Cargo.toml | 1 + bin/pudox-run/src/main.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index f59021e..6627f0b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1230,6 +1230,7 @@ dependencies = [ "async-openai", "reqwest 0.12.28", "serde", + "serde_json", "tokio", "tracing", "tracing-subscriber", diff --git a/bin/pudox-run/Cargo.toml b/bin/pudox-run/Cargo.toml index c2179c1..cd27467 100644 --- a/bin/pudox-run/Cargo.toml +++ b/bin/pudox-run/Cargo.toml @@ -14,3 +14,4 @@ tokio = { version = "1", features = ["full"] } tracing-subscriber = "0.3" async-openai = { version = "0.38.2", features = ["chat-completion"] } serde = { version = "1", features = ["derive"] } +serde_json = "1" diff --git a/bin/pudox-run/src/main.rs b/bin/pudox-run/src/main.rs index e3abf21..8f1f1af 100644 --- a/bin/pudox-run/src/main.rs +++ b/bin/pudox-run/src/main.rs @@ -114,6 +114,15 @@ async fn complete_chat_messages( messages: &Vec, tools: &Vec, ) -> Result> { + tracing::info!("Sending {} message(s) to LLM", messages.len()); + for (i, msg) in messages.iter().enumerate() { + tracing::debug!( + " [{}] {}", + i, + serde_json::to_string(msg).unwrap_or_else(|_| format!("{:?}", msg)) + ); + } + let request = CreateChatCompletionRequestArgs::default() .model("caurea/gemma-4-26B-A4B-it") .max_tokens(4000u32) @@ -126,6 +135,18 @@ async fn complete_chat_messages( let choice = &response.choices[0]; let message = choice.message.clone(); + if let Some(content) = &message.content { + tracing::info!("LLM response content: {}", content); + } + if let Some(tool_calls) = &message.tool_calls { + for tc in tool_calls { + tracing::info!( + "LLM tool call: {}", + serde_json::to_string(tc).unwrap_or_else(|_| format!("{:?}", tc)) + ); + } + } + Ok(message) } @@ -158,6 +179,11 @@ async fn handle_tool_calls( for tool_call in tool_calls { match tool_call { ChatCompletionMessageToolCalls::Function(f) => { + tracing::info!( + "Dispatching tool call: {} args={}", + f.function.name, + f.function.arguments + ); if f.function.name == "finish" { return Ok(ToolCallResult::Finish); } -- 2.51.2