| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- """
- 基础工具适配器 - 第三方工具适配接口
- 职责:
- 1. 定义统一的适配器接口
- 2. 处理工具执行上下文的转换
- 3. 统一返回值格式
- """
- from abc import ABC, abstractmethod
- from typing import Any, Callable, Dict
- from agent.tools.models import ToolResult, ToolContext
- class ToolAdapter(ABC):
- """工具适配器基类"""
- @abstractmethod
- async def adapt_execute(
- self,
- tool_func: Callable,
- args: Dict[str, Any],
- context: ToolContext
- ) -> ToolResult:
- """
- 适配第三方工具的执行
- Args:
- tool_func: 原始工具函数/对象
- args: 工具参数
- context: 我们的上下文对象
- Returns:
- ToolResult: 统一的返回格式
- """
- pass
- @abstractmethod
- def adapt_schema(self, original_schema: Dict) -> Dict:
- """
- 适配工具 Schema 到我们的格式
- Args:
- original_schema: 原始工具的 Schema
- Returns:
- 适配后的 Schema(OpenAI Tool Schema 格式)
- """
- pass
- def extract_memory(self, result: Any) -> str:
- """
- 从结果中提取长期记忆摘要
- Args:
- result: 工具执行结果
- Returns:
- 记忆摘要字符串
- """
- return ""
|