MCPcopy Index your code
hub / github.com/InfinitiBit/graphbit / execute_production_tool_calls

Function execute_production_tool_calls

python/src/workflow/node.rs:1119–1286  ·  view source on GitHub ↗
(
    py: Python<'_>,
    tool_calls_json: String,
    node_tools: Vec<String>,
)

Source from the content-addressed store, hash-verified

1117/// Tool execution bridge for workflow integration
1118#[pyfunction]
1119pub(crate) fn execute_production_tool_calls(
1120 py: Python<'_>,
1121 tool_calls_json: String,
1122 node_tools: Vec<String>,
1123) -> PyResult<String> {
1124 use crate::tools::registry::ToolRegistry;
1125
1126 // Parse tool calls
1127 let tool_calls: Vec<serde_json::Value> =
1128 serde_json::from_str(&tool_calls_json).map_err(|e| {
1129 PyErr::new::<pyo3::exceptions::PyValueError, _>(format!(
1130 "Failed to parse tool calls JSON: {}",
1131 e
1132 ))
1133 })?;
1134
1135 // Create a tool registry with available tools
1136 let registry = ToolRegistry::new();
1137
1138 // Register tools from the global registry that are available for this node
1139 TOOL_REGISTRY.with(|global_registry| {
1140 let global_registry = global_registry.borrow();
1141 for tool_name in &node_tools {
1142 if let Some(tool_func) = global_registry.get(tool_name) {
1143 let params_dict = pyo3::types::PyDict::new(py);
1144 let _ = registry.register_tool(
1145 tool_name.clone(),
1146 format!("Tool function: {}", tool_name),
1147 tool_func.clone_ref(py),
1148 &params_dict,
1149 None,
1150 );
1151 }
1152 }
1153 Ok::<(), PyErr>(())
1154 })?;
1155
1156 let mut tool_execution_results = Vec::new();
1157
1158 // Execute each tool call
1159 for tool_call in tool_calls.iter() {
1160 if let (Some(tool_name), Some(parameters)) = (
1161 tool_call.get("tool_name").and_then(|v| v.as_str()),
1162 tool_call.get("parameters").and_then(|v| v.as_object()),
1163 ) {
1164 // Convert parameters to PyDict
1165 let params_dict = pyo3::types::PyDict::new(py);
1166 let mut param_conversion_error = None;
1167
1168 for (key, value) in parameters {
1169 match json_to_python_value(value, py) {
1170 Ok(py_value) => {
1171 if let Err(e) = params_dict.set_item(key, py_value) {
1172 param_conversion_error =
1173 Some(format!("Failed to set parameter '{}': {}", key, e));
1174 break;
1175 }
1176 }

Callers 2

Calls 7

json_to_python_valueFunction · 0.85
register_toolMethod · 0.80
cloneMethod · 0.80
has_toolMethod · 0.80
execute_toolMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected