修改引用逻辑,修改长期记忆bug
This commit is contained in:
7
app/agent/__init__.py
Normal file
7
app/agent/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
"""
|
||||
Agent 子模块
|
||||
"""
|
||||
|
||||
from app.agent.service import AIAgentService
|
||||
|
||||
__all__ = ["AIAgentService"]
|
||||
@@ -3,11 +3,9 @@
|
||||
利用 LangGraph 的 checkpointer 获取对话历史和摘要
|
||||
"""
|
||||
|
||||
from typing import List, Dict, Any, Optional
|
||||
import logging
|
||||
from typing import List, Dict, Any
|
||||
from app.logger import error # 保持兼容,或者替换为 logger
|
||||
|
||||
|
||||
class ThreadHistoryService:
|
||||
"""线程历史查询服务"""
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# app/prompts.py
|
||||
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
||||
from langchain_core.tools import BaseTool
|
||||
|
||||
def create_system_prompt(tools: list = None) -> ChatPromptTemplate:
|
||||
"""
|
||||
@@ -11,7 +10,7 @@ def create_system_prompt(tools: list = None) -> ChatPromptTemplate:
|
||||
tool_descs = []
|
||||
for tool in tools:
|
||||
# 提取工具名称和描述的第一行
|
||||
name = getattr(tool, 'name', tool.__name__)
|
||||
name = getattr(tool, 'name', None) or getattr(tool, '__name__', 'unknown_tool')
|
||||
desc = (tool.description or "").split('\n')[0]
|
||||
tool_descs.append(f"- {name}: {desc}")
|
||||
tools_section = "\n".join(tool_descs)
|
||||
|
||||
@@ -3,27 +3,17 @@ AI Agent 服务类 - 支持多模型动态切换
|
||||
接收外部传入的 checkpointer,不负责管理连接生命周期
|
||||
"""
|
||||
|
||||
import os
|
||||
import json
|
||||
from dotenv import load_dotenv
|
||||
|
||||
from langchain_community.chat_models import ChatZhipuAI
|
||||
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
|
||||
from pydantic import SecretStr
|
||||
from langgraph.checkpoint.postgres.aio import AsyncPostgresSaver
|
||||
|
||||
# 本地模块
|
||||
from app.graph_builder import GraphBuilder, GraphContext
|
||||
from app.graph_tools import AVAILABLE_TOOLS, TOOLS_BY_NAME
|
||||
from app.rag import RAGPipeline
|
||||
from app.rag.tools import create_rag_tool_sync
|
||||
from rag_core import create_parent_retriever
|
||||
from app.llm_factory import LLMFactory
|
||||
from app.rag_initializer import init_rag_tool
|
||||
from app.logger import debug, info, warning, error
|
||||
from app.graph.graph_builder import GraphBuilder, GraphContext
|
||||
from app.graph.graph_tools import AVAILABLE_TOOLS, TOOLS_BY_NAME
|
||||
from app.agent.llm_factory import LLMFactory
|
||||
from app.agent.rag_initializer import init_rag_tool
|
||||
from app.logger import info, warning
|
||||
load_dotenv()
|
||||
|
||||
|
||||
class AIAgentService:
|
||||
def __init__(self, checkpointer):
|
||||
self.checkpointer = checkpointer
|
||||
Reference in New Issue
Block a user