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

Method task

sdk/python/src/lib.rs:1936–1957  ·  view source on GitHub ↗

Delegate a bounded task with the compact object-shaped API.

(&self, py: Python<'_>, options: &Bound<'_, PyDict>)

Source from the content-addressed store, hash-verified

1934
1935 /// Delegate a bounded task with the compact object-shaped API.
1936 fn task(&self, py: Python<'_>, options: &Bound<'_, PyDict>) -> PyResult<PyToolResult> {
1937 let json_str = py_dict_to_json(options)?;
1938 let args: serde_json::Value = serde_json::from_str(&json_str)
1939 .map_err(|e| PyValueError::new_err(format!("Invalid task options: {e}")))?;
1940 let args = normalize_task_options(args)?;
1941
1942 let session = self.inner.clone();
1943 let result = py
1944 .allow_threads(move || get_runtime().block_on(session.tool("task", args)))
1945 .map_err(|e| PyRuntimeError::new_err(format!("Task delegation failed: {e}")))?;
1946
1947 Ok(PyToolResult {
1948 name: result.name,
1949 output: result.output,
1950 exit_code: result.exit_code,
1951 metadata_json: result.metadata.as_ref().map(serde_json::Value::to_string),
1952 error_kind_json: result
1953 .error_kind
1954 .as_ref()
1955 .and_then(|k| serde_json::to_string(k).ok()),
1956 })
1957 }
1958
1959 /// Delegate a bounded task to a child agent through the built-in ``task`` tool.
1960 #[pyo3(signature = (agent, description, prompt, background=false, max_steps=None))]

Calls 6

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

Tested by

no test coverage detected