执行Agent任务 Args: context: {"query": "用户问题"} params: {"temperature": 0.7}
(self, context: Dict[str, Any], params: Dict[str, Any])
| 57 | return self.tool_registry.get_all_definitions() |
| 58 | |
| 59 | async def execute(self, context: Dict[str, Any], params: Dict[str, Any]) -> Dict[str, Any]: |
| 60 | """ |
| 61 | 执行Agent任务 |
| 62 | |
| 63 | Args: |
| 64 | context: {"query": "用户问题"} |
| 65 | params: {"temperature": 0.7} |
| 66 | """ |
| 67 | query = context.get("query", "") |
| 68 | |
| 69 | if not query: |
| 70 | return {"status": "error", "error": "No query provided"} |
| 71 | |
| 72 | logger.info(f"📥 Query: {query}") |
| 73 | |
| 74 | try: |
| 75 | # 获取所有工具定义 |
| 76 | tools = self.get_registered_tools() |
| 77 | |
| 78 | # 调用模型(假设base_agent中有这个方法) |
| 79 | response = await self._call_model_with_tools( |
| 80 | prompt=query, |
| 81 | tools=tools, |
| 82 | temperature=params.get("temperature", 0.7), |
| 83 | max_iterations=params.get("max_iterations", 10), |
| 84 | max_tool_calls=params.get("max_tool_calls", 20) |
| 85 | ) |
| 86 | |
| 87 | return { |
| 88 | "status": "success", |
| 89 | "answer": response["content"], |
| 90 | "tool_calls": response["tool_calls_made"], |
| 91 | "iterations": response["iterations"] |
| 92 | } |
| 93 | |
| 94 | except Exception as e: |
| 95 | logger.error(f"❌ Error: {e}") |
| 96 | return {"status": "error", "error": str(e)} |
| 97 | |
| 98 | """ |
| 99 | Simple Function-based Tools Demo |
no test coverage detected