feat: Agent 运行时、对话 API、作业助手与引擎修复及前端执行超时
- agent_runtime 模块与 agent_chat API,前端 AgentChat 视图与路由对接 - workflow_engine: code 节点命名空间与 json 引用修复 - llm_service: 工具调用 extra_body(如 DeepSeek) - create_homework_manager_agent / _3 脚本与测试脚本扩展 - frontend: WORKFLOW_EXECUTION_HTTP_TIMEOUT_MS、AgentChatPreview/MainLayout 等 - 文档:架构说明与自主 Agent 改造完成情况 Made-with: Cursor
This commit is contained in:
64
backend/app/agent_runtime/schemas.py
Normal file
64
backend/app/agent_runtime/schemas.py
Normal file
@@ -0,0 +1,64 @@
|
||||
"""
|
||||
Agent Runtime 配置与数据结构 Schema
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, List, Optional
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class AgentToolConfig(BaseModel):
|
||||
"""Agent 可用工具配置"""
|
||||
# 若为空列表则使用全部已注册工具
|
||||
include_tools: List[str] = Field(default_factory=list, description="允许的工具名称白名单")
|
||||
exclude_tools: List[str] = Field(default_factory=list, description="排除的工具名称黑名单")
|
||||
|
||||
|
||||
class AgentMemoryConfig(BaseModel):
|
||||
"""Agent 记忆配置"""
|
||||
enabled: bool = True
|
||||
max_history_messages: int = 20 # 注入 LLM 的上文最大消息数
|
||||
session_key: Optional[str] = None # 会话标识,默认自动生成
|
||||
persist_to_db: bool = True # 是否写入 MySQL 长期记忆
|
||||
|
||||
|
||||
class AgentLLMConfig(BaseModel):
|
||||
"""Agent 模型配置"""
|
||||
provider: str = "openai" # openai / deepseek
|
||||
model: str = "gpt-4o-mini"
|
||||
temperature: float = 0.7
|
||||
max_tokens: Optional[int] = None
|
||||
api_key: Optional[str] = None
|
||||
base_url: Optional[str] = None
|
||||
max_iterations: int = 10 # ReAct 循环最大步数
|
||||
request_timeout: float = 120.0
|
||||
extra_body: Optional[Dict[str, Any]] = None
|
||||
|
||||
|
||||
class AgentConfig(BaseModel):
|
||||
"""Agent 完整配置"""
|
||||
name: str = "default_agent"
|
||||
system_prompt: str = "你是一个有用的AI助手。请使用可用工具来帮助用户完成任务。"
|
||||
llm: AgentLLMConfig = Field(default_factory=AgentLLMConfig)
|
||||
tools: AgentToolConfig = Field(default_factory=AgentToolConfig)
|
||||
memory: AgentMemoryConfig = Field(default_factory=AgentMemoryConfig)
|
||||
user_id: Optional[str] = None
|
||||
|
||||
|
||||
class AgentMessage(BaseModel):
|
||||
"""Agent 对话消息"""
|
||||
role: str # user / assistant / tool
|
||||
content: str
|
||||
tool_calls: Optional[List[Dict[str, Any]]] = None
|
||||
tool_call_id: Optional[str] = None
|
||||
name: Optional[str] = None
|
||||
|
||||
|
||||
class AgentResult(BaseModel):
|
||||
"""Agent 执行结果"""
|
||||
success: bool = True
|
||||
content: str = ""
|
||||
truncated: bool = False
|
||||
iterations_used: int = 0
|
||||
tool_calls_made: int = 0
|
||||
error: Optional[str] = None
|
||||
Reference in New Issue
Block a user