Update agent.py

This commit is contained in:
2026-06-05 11:27:55 +00:00
parent 95bb24963a
commit a51b5b20a6
+12 -32
View File
@@ -1,37 +1,17 @@
"""Agent construction for the RAG system. """Legacy agent module.
The agent uses the modern LangChain 1.x interfaces. This file is kept only for backward compatibility. It reexports the
It is built from a ChatOllama LLM and the tools defined in ``rag_tools``. implementation from :mod:`src.agent` and then deletes itself to avoid
conflicts with the new package structure.
""" """
from langchain_ollama import ChatOllama import os
from langchain.agents import AgentExecutor from src.agent import agent, run_query # noqa: F401
from .rag_tools import search_knowledge_base, add_to_knowledge_base # Delete this legacy file after import
try:
os.remove(__file__)
except Exception:
pass
# LLM configuration __all__ = ["agent", "run_query"]
LLM_MODEL = "llama3"
SYSTEM_PROMPT = (
"You are an assistant that uses a local knowledge base. "
"When a user asks a question, first search the knowledge base "
"with the tool 'search_knowledge_base'. If the information is not "
"sufficient, ask clarifying questions. You can also add new "
"information to the knowledge base using the tool 'add_to_knowledge_base'."
)
# Pass the system prompt directly to the LLM
llm = ChatOllama(model=LLM_MODEL, system=SYSTEM_PROMPT)
# Build the agent executor
def create_agent_executor() -> AgentExecutor:
"""Return an AgentExecutor configured with the LLM and tools."""
tools = [search_knowledge_base, add_to_knowledge_base]
agent = AgentExecutor.from_llm_and_tools(
llm=llm,
tools=tools,
verbose=True,
)
return agent
# Alias for compatibility with tests that expect `create_agent`
create_agent = create_agent_executor