chore: 修复当自动更新 webchat title 时,history 被重置的问题

This commit is contained in:
Soulter
2025-08-24 00:23:08 +08:00
parent 6e61ee81d8
commit 69aaf09ac8
5 changed files with 31 additions and 11 deletions
+15 -1
View File
@@ -4,5 +4,19 @@ from astrbot.core import html_renderer
from astrbot.core import sp
from astrbot.core.star.register import register_llm_tool as llm_tool
from astrbot.core.star.register import register_agent as agent
from astrbot.core.agent.tool import ToolSet, FunctionTool
from astrbot.core.agent.tool_executor import BaseFunctionToolExecutor
from astrbot.core.pipeline.process_stage.method.llm_request import FunctionToolExecutor
__all__ = ["AstrBotConfig", "logger", "html_renderer", "llm_tool", "agent", "sp"]
__all__ = [
"AstrBotConfig",
"logger",
"html_renderer",
"llm_tool",
"agent",
"sp",
"ToolSet",
"FunctionTool",
"FunctionToolExecutor",
"BaseFunctionToolExecutor",
]
+7 -7
View File
@@ -8,12 +8,12 @@ from .mcp_client import MCPClient
class FunctionTool:
"""A class representing a function tool that can be used in function calling."""
name: str
parameters: dict
description: str
handler: Awaitable = None
name: str | None = None
parameters: dict | None = None
description: str | None = None
handler: Awaitable | None = None
"""处理函数, 当 origin 为 mcp 时,这个为空"""
handler_module_path: str = None
handler_module_path: str | None = None
"""处理函数的模块路径,当 origin 为 mcp 时,这个为空
必须要保留这个字段, handler 在初始化会被 functools.partial 包装,导致 handler 的 __module__ 为 functools
@@ -25,9 +25,9 @@ class FunctionTool:
"""函数工具的来源, local 为本地函数工具, mcp 为 MCP 服务"""
# MCP 相关字段
mcp_server_name: str = None
mcp_server_name: str | None = None
"""MCP 服务名称,当 origin 为 mcp 时有效"""
mcp_client: MCPClient = None
mcp_client: MCPClient | None = None
"""MCP 客户端,当 origin 为 mcp 时有效"""
def __repr__(self):
+1 -1
View File
@@ -211,7 +211,7 @@ class ConversationManager:
cid=conversation_id,
title=title,
persona_id=persona_id,
content=history or [],
content=history,
)
async def update_conversation_title(
@@ -164,9 +164,15 @@ class FunctionToolExecutor(BaseFunctionToolExecutor[AstrAgentContext]):
):
if not run_context.event:
raise ValueError("Event must be provided for local function tools.")
# 检查 tool 下有没有 run 方法
if not tool.handler and not hasattr(tool, "run"):
raise ValueError("Tool must have a valid handler or 'run' method.")
awaitable = tool.handler or getattr(tool, "run")
wrapper = call_handler(
event=run_context.event,
handler=tool.handler,
handler=awaitable,
**tool_args,
)
async for resp in wrapper:
+1 -1
View File
@@ -34,7 +34,7 @@ class Star(CommandParserMixin):
@staticmethod
async def html_render(
tmpl: str, data: dict, return_url=True, options: dict = None
tmpl: str, data: dict, return_url=True, options: dict | None = None
) -> str:
"""渲染 HTML"""
return await html_renderer.render_custom_template(