| 318 | #[pymethods] |
| 319 | impl PyToolNextFn { |
| 320 | fn __call__<'py>( |
| 321 | &self, |
| 322 | py: Python<'py>, |
| 323 | args: &Bound<'py, PyAny>, |
| 324 | ) -> PyResult<Bound<'py, PyAny>> { |
| 325 | let next = self.inner.clone(); |
| 326 | let json_args = py_to_json(args)?; |
| 327 | let future = next(json_args); |
| 328 | pyo3_async_runtimes::tokio::future_into_py(py, async move { |
| 329 | let result = future |
| 330 | .await |
| 331 | .map_err(|e| pyo3::exceptions::PyRuntimeError::new_err(e.to_string()))?; |
| 332 | Python::attach(|py| json_to_py(py, &result)) |
| 333 | }) |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | /// Python-callable wrapper for the Rust `LlmExecutionNextFn`. |