37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
"""Agent construction for the RAG system.
|
|
|
|
The agent uses the modern LangChain 1.x interfaces.
|
|
It is built from a ChatOllama LLM and the tools defined in ``rag_tools``.
|
|
"""
|
|
|
|
from langchain_ollama import ChatOllama
|
|
from langchain.agents import AgentExecutor
|
|
|
|
from .rag_tools import search_knowledge_base, add_to_knowledge_base
|
|
|
|
# LLM configuration
|
|
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 |