Skip to content

armgit / uzu

Public Imported from GitHub
0

A high-performance inference engine for AI models

Fix tool calls result block parsing (#802)

Aleksandr Golokozce5881e983d7
diff --git a/crates/legacy/cli/src/server/chat_tool_calls.rs b/crates/legacy/cli/src/server/chat_tool_calls.rs
index cb8fd6fa4..f573a549e 100644
--- a/crates/legacy/cli/src/server/chat_tool_calls.rs
+++ b/crates/legacy/cli/src/server/chat_tool_calls.rs
@@ -244,7 +244,7 @@ pub fn tool_call_result_block(
identifier: &str,
content: String,
) -> ChatContentBlock {
- let value = serde_json::from_str::<serde_json::Value>(&content).unwrap_or(serde_json::Value::String(content));
+ let value = serde_json::Value::String(content);
ChatContentBlock::ToolCallResult {
identifier: Some(identifier.to_string()),
name: None,
diff --git a/crates/legacy/cli/unit/server/chat_tool_calls_test.rs b/crates/legacy/cli/unit/server/chat_tool_calls_test.rs
index b9dd72b0c..332d838d0 100644
--- a/crates/legacy/cli/unit/server/chat_tool_calls_test.rs
+++ b/crates/legacy/cli/unit/server/chat_tool_calls_test.rs
@@ -57,6 +57,23 @@ fn tool_call_round_trip_maps_to_chat_blocks() {
assert_eq!(results[0].1.as_deref(), Some("get_time"), "result name should be backfilled from the matching call");
}
+#[test]
+fn json_looking_tool_result_content_remains_text() {
+ for content in ["26", r#"{"number":1}"#, "[hello]", "[1,2,3]", r#"[{"number":228}]"#, r#"[{"text":"hi"}]"#] {
+ let block = tool_call_result_block("call_1", content.to_string());
+ let ChatContentBlock::ToolCallResult {
+ value,
+ ..
+ } = block
+ else {
+ panic!("expected tool call result");
+ };
+
+ let serialized = serde_json::to_value(value).expect("tool result should be serializable");
+ assert_eq!(serialized.as_str(), Some(content));
+ }
+}
+
#[test]
fn invalid_tool_call_arguments_stay_serializable() {
let call = |arguments: &str| {