Execute agent task
(self, context: Dict[str, Any], params: Dict[str, Any])
| 130 | ) |
| 131 | |
| 132 | async def execute(self, context: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]: |
| 133 | """Execute agent task""" |
| 134 | query = context.get("query", "") |
| 135 | |
| 136 | if not query: |
| 137 | return {"status": "error", "error": "No query provided"} |
| 138 | |
| 139 | logger.info(f"Processing query: {query}") |
| 140 | |
| 141 | try: |
| 142 | tools = await self.get_registered_tools() |
| 143 | logger.info(f"Available tools: {len(tools)}") |
| 144 | |
| 145 | |
| 146 | # Retrieve related tools |
| 147 | related_tools = get_related_tools(query, tools) |
| 148 | logger.info(f"Related tools found: {len(related_tools)}") |
| 149 | |
| 150 | response = await self._call_model_with_tools( |
| 151 | system_prompt="", |
| 152 | prompt=query, |
| 153 | tools=related_tools, |
| 154 | temperature=params.get("temperature", 0.7), |
| 155 | max_iterations=params.get("max_iterations", 10), |
| 156 | max_tool_calls=params.get("max_tool_calls", 20) |
| 157 | ) |
| 158 | |
| 159 | return { |
| 160 | "status": "success", |
| 161 | "answer": response["content"], |
| 162 | "tool_calls": response["tool_calls_made"], |
| 163 | "iterations": response["iterations"] |
| 164 | } |
| 165 | |
| 166 | except Exception as e: |
| 167 | logger.error(f"Error during execution: {e}") |
| 168 | return {"status": "error", "error": str(e)} |
| 169 | |
| 170 | |
| 171 | async def main(): |
no test coverage detected