MCPcopy Create free account
hub / github.com/InfinitiBit/graphbit / sync_global_tools_to_workflow

Function sync_global_tools_to_workflow

python/src/workflow/node.rs:898–940  ·  view source on GitHub ↗
(py: Python<'_>)

Source from the content-addressed store, hash-verified

896/// Bridge function to sync tools from global registry to thread-local registry
897#[pyfunction]
898pub(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
943fn execute_tool_from_global_registry(

Callers

nothing calls this directly

Calls 4

get_global_registryFunction · 0.85
insertMethod · 0.80
cloneMethod · 0.80
list_toolsMethod · 0.45

Tested by

no test coverage detected