MCPcopy Create free account
hub / github.com/KCORES/vector-db-bench / parse_tool_call

Function parse_tool_call

agent/src/main.rs:326–393  ·  view source on GitHub ↗

Parse a ToolCall from the function name and JSON arguments string.

(name: &str, arguments: &str)

Source from the content-addressed store, hash-verified

324
325/// Parse a ToolCall from the function name and JSON arguments string.
326fn parse_tool_call(name: &str, arguments: &str) -> Result<ToolCall, String> {
327 match name {
328 "read_file" => {
329 let v: serde_json::Value =
330 serde_json::from_str(arguments).map_err(|e| format!("Invalid JSON: {}", e))?;
331 Ok(ToolCall::ReadFile {
332 path: v["path"]
333 .as_str()
334 .ok_or("Missing 'path' field")?
335 .to_string(),
336 })
337 }
338 "write_file" => {
339 let v: serde_json::Value =
340 serde_json::from_str(arguments).map_err(|e| format!("Invalid JSON: {}", e))?;
341 Ok(ToolCall::WriteFile {
342 path: v["path"]
343 .as_str()
344 .ok_or("Missing 'path' field")?
345 .to_string(),
346 content: v["content"]
347 .as_str()
348 .ok_or("Missing 'content' field")?
349 .to_string(),
350 })
351 }
352 "list_files" => {
353 let v: serde_json::Value =
354 serde_json::from_str(arguments).map_err(|e| format!("Invalid JSON: {}", e))?;
355 Ok(ToolCall::ListFiles {
356 path: v["path"]
357 .as_str()
358 .ok_or("Missing 'path' field")?
359 .to_string(),
360 })
361 }
362 "run_benchmark" => {
363 let v: serde_json::Value =
364 serde_json::from_str(arguments).map_err(|e| format!("Invalid JSON: {}", e))?;
365 Ok(ToolCall::RunBenchmark {
366 concurrency: v["concurrency"].as_u64().map(|n| n as usize),
367 warmup: v["warmup"].as_u64().map(|n| n as usize),
368 max_queries: v["max_queries"].as_u64().map(|n| n as usize),
369 })
370 }
371 "run_profiling" => {
372 let v: serde_json::Value =
373 serde_json::from_str(arguments).map_err(|e| format!("Invalid JSON: {}", e))?;
374 Ok(ToolCall::RunProfiling {
375 duration: v["duration"].as_u64(),
376 })
377 }
378 "run_correctness_test" => Ok(ToolCall::RunCorrectnessTest),
379 "build_project" => Ok(ToolCall::BuildProject),
380 "get_status" => Ok(ToolCall::GetStatus),
381 "finish" => {
382 let v: serde_json::Value =
383 serde_json::from_str(arguments).map_err(|e| format!("Invalid JSON: {}", e))?;

Callers 14

mainFunction · 0.85
test_parse_read_fileFunction · 0.85
test_parse_write_fileFunction · 0.85
test_parse_list_filesFunction · 0.85
test_parse_run_profilingFunction · 0.85
test_parse_get_statusFunction · 0.85
test_parse_build_projectFunction · 0.85
test_parse_finishFunction · 0.85
test_parse_unknown_toolFunction · 0.85

Calls

no outgoing calls

Tested by 13

test_parse_read_fileFunction · 0.68
test_parse_write_fileFunction · 0.68
test_parse_list_filesFunction · 0.68
test_parse_run_profilingFunction · 0.68
test_parse_get_statusFunction · 0.68
test_parse_build_projectFunction · 0.68
test_parse_finishFunction · 0.68
test_parse_unknown_toolFunction · 0.68
test_parse_invalid_jsonFunction · 0.68