diff --git a/agent.py b/agent.py new file mode 100644 index 0000000..7900644 --- /dev/null +++ b/agent.py @@ -0,0 +1,28 @@ +from langchain.agents import create_agent +from langchain_ollama import ChatOllama + +from tools import search_local_kb, web_search + +OLLAMA_BASE_URL = "http://127.0.0.1:11434" +LLM_MODEL = "llama3" + +SYSTEM_PROMPT = """ +You are a RAG assistant that must choose the best source before answering. + +Rules: +- Use search_local_kb for questions about local notes, internal documents, course materials, or any topic that may already exist in the local knowledge base. +- Use web_search for current events, recent news, live facts, or questions that clearly require the internet. +- Do not call both tools unless the first one clearly failed to provide enough information. +- Every final answer must end with a separate line in the exact format: "Источник: chromadb" or "Источник: tavily". +- Answer in Russian. +""" + +agent = create_agent( + model=ChatOllama( + model=LLM_MODEL, + base_url=OLLAMA_BASE_URL, + temperature=0, + ), + tools=[search_local_kb, web_search], + system_prompt=SYSTEM_PROMPT, +)