feat: 向量记忆 RAG、工具市场、SSE 流式响应、前端集成与测试覆盖

- 新增 embedding_service(语义检索)、knowledge_service(RAG)、text_chunker、document_parser
- 新增 tool_registry(自定义工具注册表)并完善工具市场 API(CRUD + code/http 执行)
- 新增 agent_vector_memory / knowledge_base 模型及对应数据库表
- 实现 SSE 流式响应与 Agent 预算控制
- AgentChat.vue 集成 MainLayout 导航布局
- 完善测试体系:7 个新测试文件共 110 个测试覆盖
- 修复 conftest.py SQLite 内存数据库连接隔离问题

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
renjianbo
2026-05-01 22:30:46 +08:00
parent 036f533881
commit 7b9e0826de
35 changed files with 4353 additions and 365 deletions

View File

@@ -13,6 +13,7 @@ from app.agent_runtime.schemas import (
AgentConfig,
AgentLLMConfig,
AgentToolConfig,
AgentBudgetConfig,
)
logger = logging.getLogger(__name__)
@@ -24,6 +25,8 @@ async def run_agent_node(
execution_logger: Optional[Any] = None,
user_id: Optional[str] = None,
on_tool_executed: Optional[Any] = None,
on_llm_invocation: Optional[Any] = None,
budget_limits: Optional[Dict[str, int]] = None,
) -> Dict[str, Any]:
"""
在工作流中执行 Agent 节点。
@@ -72,6 +75,14 @@ async def run_agent_node(
if node_data.get("base_url"):
llm_config.base_url = node_data["base_url"]
# 3a. 构建预算配置(接收工作流级预算限制)
budget = AgentBudgetConfig()
if budget_limits:
if "max_llm_invocations" in budget_limits:
budget.max_llm_invocations = max(1, int(budget_limits["max_llm_invocations"]))
if "max_tool_calls" in budget_limits:
budget.max_tool_calls = max(1, int(budget_limits["max_tool_calls"]))
agent_config = AgentConfig(
name=node_data.get("label", "agent_node"),
system_prompt=formatted_prompt,
@@ -84,6 +95,7 @@ async def run_agent_node(
"enabled": node_data.get("memory", True),
"persist_to_db": node_data.get("memory", True),
},
budget=budget,
user_id=user_id,
)
@@ -93,6 +105,9 @@ async def run_agent_node(
execution_logger=execution_logger,
on_tool_executed=on_tool_executed,
)
# 注入 LLM 预算回调(使 Agent 内部 LLM 调用计入工作流预算)
if on_llm_invocation:
runtime.on_llm_invocation = on_llm_invocation
result = await runtime.run(query)