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

Method _execute_tool_request

agent.py:1134–1223  ·  view source on GitHub ↗
(
        self,
        tool_name: str,
        tool_args: dict,
        message: str,
        raw_tool_name: str = "",
        responses_item_factory: Callable[[Any], dict[str, Any]] | None = None,
    )

Source from the content-addressed store, hash-verified

1132 return await self.process_tools(llm_result.response)
1133
1134 async def _execute_tool_request(
1135 self,
1136 tool_name: str,
1137 tool_args: dict,
1138 message: str,
1139 raw_tool_name: str = "",
1140 responses_item_factory: Callable[[Any], dict[str, Any]] | None = None,
1141 ):
1142 raw_tool_name = raw_tool_name or tool_name
1143 tool_method = None
1144 tool = None
1145
1146 try:
1147 import helpers.mcp_handler as mcp_helper
1148
1149 mcp_tool_candidate = mcp_helper.MCPConfig.get_instance().get_tool(
1150 self, tool_name
1151 )
1152 if mcp_tool_candidate:
1153 tool = mcp_tool_candidate
1154 except ImportError:
1155 PrintStyle(
1156 background_color="black", font_color="yellow", padding=True
1157 ).print("MCP helper module not found. Skipping MCP tool lookup.")
1158 except Exception as e:
1159 PrintStyle(background_color="black", font_color="red", padding=True).print(
1160 f"Failed to get MCP tool '{tool_name}': {e}"
1161 )
1162
1163 if not tool:
1164 tool = self.get_tool(
1165 name=tool_name,
1166 method=tool_method,
1167 args=tool_args,
1168 message=message,
1169 loop_data=self.loop_data,
1170 )
1171
1172 if not tool:
1173 error_detail = (
1174 f"Tool '{raw_tool_name}' not found or could not be initialized."
1175 )
1176 wmsg = self.hist_add_warning(error_detail)
1177 PrintStyle(font_color="red", padding=True).print(error_detail)
1178 self.context.log.log(
1179 type="warning",
1180 content=f"{self.agent_name}: {error_detail}",
1181 id=wmsg.id,
1182 )
1183 return None
1184
1185 self.loop_data.current_tool = tool # type: ignore
1186 try:
1187 await self.handle_intervention()
1188
1189 await tool.before_execution(**tool_args)
1190 await self.handle_intervention()
1191

Callers 2

Calls 11

get_toolMethod · 0.95
hist_add_warningMethod · 0.95
handle_interventionMethod · 0.95
PrintStyleClass · 0.90
get_instanceMethod · 0.45
printMethod · 0.45
logMethod · 0.45
before_executionMethod · 0.45
executeMethod · 0.45
after_executionMethod · 0.45

Tested by

no test coverage detected