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

Method execute_tools

python/src/tools/executor.rs:248–375  ·  view source on GitHub ↗

Execute a sequence of tool calls

(
        &self,
        tool_calls: &Bound<'_, PyList>,
        py: Python<'_>,
    )

Source from the content-addressed store, hash-verified

246
247 /// Execute a sequence of tool calls
248 pub fn execute_tools(
249 &self,
250 tool_calls: &Bound<'_, PyList>,
251 py: Python<'_>,
252 ) -> PyResult<ToolResultCollection> {
253 // Validate configuration first
254 self.validate_config()?;
255
256 let start_time = Instant::now();
257
258 // Validate input
259 if tool_calls.is_empty() {
260 return Ok(ToolResultCollection::new());
261 }
262
263 // Reset execution context
264 {
265 let mut context = self.execution_context.lock().map_err(|e| {
266 ToolExecutionError::ContextLockError(format!(
267 "Failed to acquire context lock: {}",
268 e
269 ))
270 })?;
271 context.reset();
272 context.start_execution();
273 }
274
275 if self.config.enable_logging {
276 info!(
277 "Starting tool execution sequence with {} tools",
278 tool_calls.len()
279 );
280 }
281
282 let mut results = ToolResultCollection::new();
283 let mut execution_count = 0;
284
285 for (index, tool_call_item) in tool_calls.iter().enumerate() {
286 // Check execution limits
287 if let Err(e) = self.check_execution_limits(execution_count, start_time) {
288 if self.config.enable_logging {
289 warn!("{}", e);
290 }
291 break;
292 }
293
294 // Parse and validate tool call
295 let tool_call = match self.parse_tool_call(&tool_call_item, py) {
296 Ok(call) => call,
297 Err(e) => {
298 let error_result = ToolResult::failure(
299 "unknown_tool".to_string(),
300 "invalid_params".to_string(),
301 format!("Failed to parse tool call: {}", e),
302 0,
303 );
304 results.add(error_result);
305

Callers

nothing calls this directly

Calls 13

resetMethod · 0.80
start_executionMethod · 0.80
parse_tool_callMethod · 0.80
to_stringMethod · 0.80
validate_tool_callMethod · 0.80
cloneMethod · 0.80
add_resultMethod · 0.80
validate_configMethod · 0.45
is_emptyMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected