Execute several delegated child-agent tasks with the compact API.
(&self, py: Python<'_>, tasks: &Bound<'_, PyAny>)
| 1988 | |
| 1989 | /// Execute several delegated child-agent tasks with the compact API. |
| 1990 | fn tasks(&self, py: Python<'_>, tasks: &Bound<'_, PyAny>) -> PyResult<PyToolResult> { |
| 1991 | let json_mod = py.import("json")?; |
| 1992 | let json_str: String = json_mod.call_method1("dumps", (tasks,))?.extract()?; |
| 1993 | let task_values: serde_json::Value = serde_json::from_str(&json_str) |
| 1994 | .map_err(|e| PyValueError::new_err(format!("Invalid task list: {e}")))?; |
| 1995 | let args = parallel_task_args(task_values)?; |
| 1996 | |
| 1997 | let session = self.inner.clone(); |
| 1998 | let result = py |
| 1999 | .allow_threads(move || get_runtime().block_on(session.tool("parallel_task", args))) |
| 2000 | .map_err(|e| { |
| 2001 | PyRuntimeError::new_err(format!("Parallel task delegation failed: {e}")) |
| 2002 | })?; |
| 2003 | |
| 2004 | Ok(PyToolResult { |
| 2005 | name: result.name, |
| 2006 | output: result.output, |
| 2007 | exit_code: result.exit_code, |
| 2008 | metadata_json: result.metadata.as_ref().map(serde_json::Value::to_string), |
| 2009 | error_kind_json: result |
| 2010 | .error_kind |
| 2011 | .as_ref() |
| 2012 | .and_then(|k| serde_json::to_string(k).ok()), |
| 2013 | }) |
| 2014 | } |
| 2015 | |
| 2016 | /// Execute several delegated child-agent tasks concurrently through ``parallel_task``. |
| 2017 | fn parallel_task(&self, py: Python<'_>, tasks: &Bound<'_, PyAny>) -> PyResult<PyToolResult> { |
no test coverage detected