MCPcopy Create free account
hub / github.com/agent0ai/agent-zero / execute_tool_call

Function execute_tool_call

helpers/parallel_tools.py:496–544  ·  view source on GitHub ↗
(agent: "Agent", tool_name: str, tool_args: dict[str, Any])

Source from the content-addressed store, hash-verified

494
495
496async def execute_tool_call(agent: "Agent", tool_name: str, tool_args: dict[str, Any]) -> str:
497 if tool_name == "parallel":
498 raise ValueError("`parallel` cannot be nested inside a parallel worker.")
499
500 tool = None
501 try:
502 import helpers.mcp_handler as mcp_helper
503
504 tool = mcp_helper.MCPConfig.get_instance().get_tool(agent, tool_name)
505 except ImportError:
506 tool = None
507 except Exception as exc:
508 PrintStyle.warning(f"Failed to initialize MCP tool '{tool_name}' for parallel job: {exc}")
509
510 if not tool:
511 tool = agent.get_tool(
512 name=tool_name,
513 method=None,
514 args=tool_args,
515 message=json.dumps({"tool_name": tool_name, "tool_args": tool_args}),
516 loop_data=agent.loop_data,
517 )
518 if not tool:
519 raise ValueError(f"Tool '{tool_name}' not found or could not be initialized.")
520
521 agent.loop_data.current_tool = tool
522 try:
523 await agent.handle_intervention()
524 await tool.before_execution(**tool_args)
525 await agent.handle_intervention()
526 await call_extensions_async(
527 "tool_execute_before",
528 agent,
529 tool_args=tool_args or {},
530 tool_name=tool_name,
531 )
532 response = await tool.execute(**tool_args)
533 await agent.handle_intervention()
534 await call_extensions_async(
535 "tool_execute_after",
536 agent,
537 response=response,
538 tool_name=tool_name,
539 )
540 await tool.after_execution(response)
541 await agent.handle_intervention()
542 return response.message
543 finally:
544 agent.loop_data.current_tool = None
545
546
547async def _cancel_job(

Callers 1

_run_direct_tool_jobFunction · 0.85

Calls 8

call_extensions_asyncFunction · 0.90
get_toolMethod · 0.45
get_instanceMethod · 0.45
warningMethod · 0.45
handle_interventionMethod · 0.45
before_executionMethod · 0.45
executeMethod · 0.45
after_executionMethod · 0.45

Tested by

no test coverage detected