feat:完成大部分数据文件上传解析功能
This commit is contained in:
+16
-10
@@ -5,7 +5,7 @@
|
||||
组件目录和物料在物料 MCP,各类任务的做法在 skill;系统提示只放每次都要用、别处放不下的原则
|
||||
"""
|
||||
|
||||
from typing import Literal, Self
|
||||
from typing import Any, Literal, Self
|
||||
|
||||
from langchain.agents import create_agent
|
||||
from langchain.agents.middleware import ModelCallLimitMiddleware, wrap_model_call
|
||||
@@ -14,6 +14,7 @@ from langchain_core.messages import AIMessage, HumanMessage
|
||||
from loguru import logger
|
||||
from pydantic import BaseModel, Field, model_validator
|
||||
|
||||
from app.agent.data_tools import DATA_TOOLS
|
||||
from app.agent.skills import skills_prompt
|
||||
from app.agent.tools import (
|
||||
ScreenAgentContext,
|
||||
@@ -98,16 +99,22 @@ async def require_tool_call(request, handler):
|
||||
return response
|
||||
|
||||
|
||||
_agent = None
|
||||
# 是否挂数据工具 → agent
|
||||
_agents: dict[bool, Any] = {}
|
||||
|
||||
|
||||
async def get_screen_agent():
|
||||
"""第一次使用时组装,之后复用;系统提示是常量,不随物料目录变化"""
|
||||
global _agent
|
||||
if _agent is None:
|
||||
_agent = create_agent(
|
||||
async def get_screen_agent(with_data: bool = False):
|
||||
"""第一次使用时组装,之后复用;系统提示是常量,不随物料目录变化
|
||||
|
||||
会话里有数据文件时用挂了 describe_data、query_data 的实例,没有时不让模型看到用不了的工具
|
||||
"""
|
||||
if with_data not in _agents:
|
||||
tools = [get_nodes, apply_actions, *await get_mcp_tools()]
|
||||
if with_data:
|
||||
tools.extend(DATA_TOOLS)
|
||||
_agents[with_data] = create_agent(
|
||||
model=get_llm(),
|
||||
tools=[get_nodes, apply_actions, *await get_mcp_tools()],
|
||||
tools=tools,
|
||||
system_prompt=f"{SYSTEM_PROMPT}\n\n{skills_prompt()}",
|
||||
# 用工具调用给出结论:试过原生结构化输出(ProviderStrategy),歧义时模型更常直接执行而不追问,评测多删了组件
|
||||
response_format=ToolStrategy(AgentReply),
|
||||
@@ -124,5 +131,4 @@ async def get_screen_agent():
|
||||
checkpointer=False,
|
||||
name="screen_agent",
|
||||
)
|
||||
|
||||
return _agent
|
||||
return _agents[with_data]
|
||||
|
||||
Reference in New Issue
Block a user