From bc13e3365ca2be6cdbc9941a3a4319d2c75a54d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D0=B8=D0=BB=20=D0=92=D0=B8=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D0=BE=D0=B2?= Date: Thu, 2 Jul 2026 09:38:03 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20agent.py=20=E2=80=94=20=D0=AD=D0=BA?= =?UTF-8?q?=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD:=20RAG-=D0=B0=D0=B3=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=20=D1=81=20ChromaDB=20=D0=B8=20=D0=B2=D0=B5=D0=B1-=D0=BF?= =?UTF-8?q?=D0=BE=D0=B8=D1=81=D0=BA=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 agent.py diff --git a/agent.py b/agent.py new file mode 100644 index 0000000..8f705ac --- /dev/null +++ b/agent.py @@ -0,0 +1,38 @@ +import os +from langchain_community.chat_models import ChatOllama +from langchain.tools import tool +from deepagents import create_deep_agent +from deepagents.backends import FilesystemBackend, LocalShellBackend, CompositeBackend +from langchain_core.messages import HumanMessage + +from tools import search_local_kb, web_search + +llm = ChatOllama( + model="llama3", + base_url=os.getenv("OLLAMA_HOST", "http://localhost:11434"), +) + +backend = CompositeBackend( + [ + LocalShellBackend(workspace_dir="./workspace"), + FilesystemBackend(), + ] +) + +agent = create_deep_agent( + model=llm, + tools=[search_local_kb, web_search], + backend=backend, + system_prompt=( + "You are a helpful agent. " + "Use search_local_kb for local knowledge and web_search for up-to-date info. " + "Prefix answers with [Local KB] or [Web Search] and indicate source." + ), +) + +async def run_agent(query: str) -> str: + result = await agent.ainvoke( + {"messages": [HumanMessage(content=query)]}, + {"configurable": {"thread_id": "session-1"}}, + ) + return result["messages"][-1].content \ No newline at end of file