MCPcopy
hub / github.com/arc53/DocsGPT / execute

Method execute

application/agents/tool_executor.py:555–815  ·  view source on GitHub ↗

Execute a tool call. Yields status events, returns (result, call_id).

(self, tools_dict: Dict, call, llm_class_name: str)

Source from the content-addressed store, hash-verified

553 return True, True
554
555 def execute(self, tools_dict: Dict, call, llm_class_name: str):
556 """Execute a tool call. Yields status events, returns (result, call_id)."""
557 parser = ToolActionParser(llm_class_name, name_mapping=self._name_to_tool)
558 tool_id, action_name, call_args = parser.parse_args(call)
559 llm_name = getattr(call, "name", "unknown")
560
561 call_id = getattr(call, "id", None) or str(uuid.uuid4())
562
563 if tool_id is None or action_name is None:
564 error_message = f"Error: Failed to parse LLM tool call. Tool name: {llm_name}"
565 logger.error(
566 "tool_call_parse_failed",
567 extra={
568 "llm_class_name": llm_class_name,
569 "llm_tool_name": llm_name,
570 "call_id": call_id,
571 },
572 )
573
574 tool_call_data = {
575 "tool_name": "unknown",
576 "call_id": call_id,
577 "action_name": llm_name,
578 "arguments": call_args or {},
579 "result": f"Failed to parse tool call. Invalid tool name format: {llm_name}",
580 }
581 # Journal the malformed call so it still shows up in tool analytics.
582 if _record_proposed(
583 call_id,
584 "unknown",
585 llm_name or "unknown",
586 call_args if isinstance(call_args, dict) else {},
587 message_id=self.message_id,
588 user_id=self.user,
589 agent_id=self.agent_id,
590 ):
591 _mark_failed(
592 call_id, tool_call_data["result"], user_id=self.user
593 )
594 yield {"type": "tool_call", "data": {**tool_call_data, "status": "error"}}
595 self.tool_calls.append(tool_call_data)
596 return "Failed to parse tool call.", call_id
597
598 if tool_id not in tools_dict:
599 error_message = f"Error: Tool ID '{tool_id}' extracted from LLM call not found in available tools_dict. Available IDs: {list(tools_dict.keys())}"
600 logger.error(
601 "tool_id_not_found",
602 extra={
603 "tool_id": tool_id,
604 "llm_tool_name": llm_name,
605 "call_id": call_id,
606 "available_tool_count": len(tools_dict),
607 },
608 )
609
610 tool_call_data = {
611 "tool_name": "unknown",
612 "call_id": call_id,

Calls 9

parse_argsMethod · 0.95
_get_or_load_toolMethod · 0.95
ToolActionParserClass · 0.90
_record_proposedFunction · 0.85
_mark_failedFunction · 0.85
_mark_executedFunction · 0.85
itemsMethod · 0.80
getMethod · 0.45
execute_actionMethod · 0.45