(py: Python<'_>)
| 896 | /// Bridge function to sync tools from global registry to thread-local registry |
| 897 | #[pyfunction] |
| 898 | pub(crate) fn sync_global_tools_to_workflow(py: Python<'_>) -> PyResult<()> { |
| 899 | use crate::tools::decorator::get_global_registry; |
| 900 | |
| 901 | // Get tools from the global registry |
| 902 | let global_registry = get_global_registry(); |
| 903 | let global_guard = global_registry.lock().map_err(|e| { |
| 904 | PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(format!( |
| 905 | "Failed to acquire global registry lock: {}", |
| 906 | e |
| 907 | )) |
| 908 | })?; |
| 909 | |
| 910 | // Get the list of registered tools from the global registry |
| 911 | let global_tools = global_guard.list_tools().map_err(|e| { |
| 912 | PyErr::new::<pyo3::exceptions::PyRuntimeError, _>(format!( |
| 913 | "Failed to list global tools: {}", |
| 914 | e |
| 915 | )) |
| 916 | })?; |
| 917 | |
| 918 | // For each tool in the global registry, get the actual function and register it in thread-local |
| 919 | TOOL_REGISTRY.with(|local_registry| { |
| 920 | let mut local_registry = local_registry.borrow_mut(); |
| 921 | |
| 922 | for tool_name in global_tools { |
| 923 | // Create a placeholder function that delegates to the global registry |
| 924 | let tool_placeholder = py.eval( |
| 925 | c"lambda *args, **kwargs: 'Tool execution delegated to global registry'", |
| 926 | None, |
| 927 | None, |
| 928 | )?; |
| 929 | |
| 930 | local_registry.insert( |
| 931 | tool_name.clone(), |
| 932 | tool_placeholder.into_pyobject(py)?.into_any().unbind(), |
| 933 | ); |
| 934 | } |
| 935 | |
| 936 | Ok::<(), PyErr>(()) |
| 937 | })?; |
| 938 | |
| 939 | Ok(()) |
| 940 | } |
| 941 | |
| 942 | /// Execute a tool from the global registry |
| 943 | fn execute_tool_from_global_registry( |
nothing calls this directly
no test coverage detected