(self, instance_id: str, parameters: dict[str, Any], **kwargs)
| 84 | |
| 85 | @rollout_trace_op |
| 86 | async def execute(self, instance_id: str, parameters: dict[str, Any], **kwargs) -> tuple[ToolResponse, float, dict]: |
| 87 | if self.name == "" or self.name is None or parameters is None: |
| 88 | error_msg = "Error: 'parameters' is missing or empty." |
| 89 | logger.error(f"[MCPTool] {error_msg} Received tool name: {self.name}, parameters: {parameters}") |
| 90 | return ToolResponse(text=json.dumps({"result": error_msg})), 0.0, {} |
| 91 | |
| 92 | try: |
| 93 | result_text, metadata = await self._call_tool(instance_id, parameters) |
| 94 | |
| 95 | # Store results in instance dictionary |
| 96 | self._instance_dict[instance_id]["reward"].append(result_text.strip()) |
| 97 | |
| 98 | # Convert metadata to metrics |
| 99 | metrics = { |
| 100 | "query_count": metadata.get("query_count", 0), |
| 101 | "status": metadata.get("status", "unknown"), |
| 102 | "total_results": metadata.get("total_results", 0), |
| 103 | "api_request_error": metadata.get("api_request_error"), |
| 104 | } |
| 105 | |
| 106 | return ToolResponse(text=result_text), 0.0, metrics |
| 107 | |
| 108 | except Exception as e: |
| 109 | error_result = json.dumps({"result": f"Tool execution failed: {e}"}) |
| 110 | logger.error(f"[MCPBaseTool] Execution failed: {e}") |
| 111 | return ToolResponse(text=error_result), 0.0, {"error": str(e)} |
| 112 | |
| 113 | async def calc_reward(self, instance_id: str, **kwargs) -> str: |
| 114 | return self._instance_dict[instance_id]["reward"] |
nothing calls this directly
no test coverage detected