MCPcopy Index your code
hub / github.com/AI45Lab/Code / tool

Method tool

sdk/python/src/lib.rs:1908–1933  ·  view source on GitHub ↗

Execute a tool by name, bypassing the LLM.

(
        &self,
        py: Python<'_>,
        name: String,
        args: &Bound<'_, pyo3::types::PyDict>,
    )

Source from the content-addressed store, hash-verified

1906
1907 /// Execute a tool by name, bypassing the LLM.
1908 fn tool(
1909 &self,
1910 py: Python<'_>,
1911 name: String,
1912 args: &Bound<'_, pyo3::types::PyDict>,
1913 ) -> PyResult<PyToolResult> {
1914 let json_str = py_dict_to_json(args)?;
1915 let json_value: serde_json::Value = serde_json::from_str(&json_str)
1916 .map_err(|e| PyValueError::new_err(format!("Invalid JSON args: {e}")))?;
1917
1918 let session = self.inner.clone();
1919 let result = py
1920 .allow_threads(move || get_runtime().block_on(session.tool(&name, json_value)))
1921 .map_err(|e| PyRuntimeError::new_err(format!("Tool execution failed: {e}")))?;
1922
1923 Ok(PyToolResult {
1924 name: result.name,
1925 output: result.output,
1926 exit_code: result.exit_code,
1927 metadata_json: result.metadata.as_ref().map(serde_json::Value::to_string),
1928 error_kind_json: result
1929 .error_kind
1930 .as_ref()
1931 .and_then(|k| serde_json::to_string(k).ok()),
1932 })
1933 }
1934
1935 /// Delegate a bounded task with the compact object-shaped API.
1936 fn task(&self, py: Python<'_>, options: &Bound<'_, PyDict>) -> PyResult<PyToolResult> {

Callers 12

taskMethod · 0.45
delegate_taskMethod · 0.45
tasksMethod · 0.45
programMethod · 0.45
web_searchMethod · 0.45
gitMethod · 0.45
git_commandMethod · 0.45
test_extract_personFunction · 0.45
test_sentimentFunction · 0.45
test_nestedFunction · 0.45
test_arrayFunction · 0.45
test_prompt_modeFunction · 0.45

Calls 4

py_dict_to_jsonFunction · 0.85
block_onMethod · 0.80
get_runtimeFunction · 0.70
cloneMethod · 0.45

Tested by 5

test_extract_personFunction · 0.36
test_sentimentFunction · 0.36
test_nestedFunction · 0.36
test_arrayFunction · 0.36
test_prompt_modeFunction · 0.36