24 lines
864 B
Python
24 lines
864 B
Python
from openai.types.chat import ChatCompletionMessageParam
|
|
from pydantic import BaseModel, Field, PrivateAttr
|
|
|
|
from mini_agent.tools.tool import Tool
|
|
|
|
|
|
class ConversationContext(BaseModel):
|
|
conversation_id: str = Field(description="会话ID")
|
|
run_id: str = Field(description="当前会话轮id")
|
|
messages: list[ChatCompletionMessageParam] = Field(description="消息历史", default_factory=list)
|
|
|
|
_discovered_tools: list[Tool] = PrivateAttr(default_factory=list)
|
|
|
|
discovered_tool_names: list[str] = Field(description="已发现的工具名称", default_factory=list)
|
|
|
|
@property
|
|
def discovered_tools(self):
|
|
return self._discovered_tools
|
|
|
|
def add_tool(self, tool: Tool):
|
|
if tool.id not in self.discovered_tool_names:
|
|
self.discovered_tool_names.append(tool.id)
|
|
self.discovered_tools.append(tool)
|