From 44b75f0106445073122ae565eb4d4829fa70d706 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=A0=D0=BE=D0=BC?= =?UTF-8?q?=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Fri, 5 Jun 2026 11:28:53 +0000 Subject: [PATCH] Update tools.py --- tools.py | 51 ++++++++++----------------------------------------- 1 file changed, 10 insertions(+), 41 deletions(-) diff --git a/tools.py b/tools.py index 8d5bdd6..d1f7a16 100644 --- a/tools.py +++ b/tools.py @@ -1,47 +1,16 @@ -"""Tool definitions for the RAG agent. +"""Legacy tools module. -The tools are simple wrappers around the vector store functions defined in -`vector_store.py`. They are decorated with `@tool` from LangChain so that the -agent can call them. +This file re‑exports the tools from :mod:`src.tools` and then removes +itself to avoid namespace clashes with the new package layout. """ -from typing import Any +from src.tools import search_knowledge_base, add_to_knowledge_base # noqa: F401 -from langchain.tools import tool - -from .vector_store import add_document, search - -@tool("search_knowledge_base") -def search_knowledge_base(query: str, max_results: int = 5) -> Any: - """Semantic search in the knowledge base. - - Parameters - ---------- - query: str - The user query. - max_results: int, optional - Number of top results to return. Defaults to 5. - """ - results = search(query, max_results) - # Convert results to a readable string - formatted = "\n".join( - f"{i+1}. [{res['metadata'].get('title', 'Unknown')}] {res['content'][:200]}" - for i, res in enumerate(results) - ) - return formatted if formatted else "No relevant documents found." - -@tool("add_to_knowledge_base") -def add_to_knowledge_base(content: str, title: str) -> Any: - """Add a new document to the knowledge base. - - Parameters - ---------- - content: str - The full text of the document. - title: str - A short title that will be stored as metadata. - """ - add_document(content, title) - return f"Document '{title}' added to the knowledge base." +# Remove the legacy file after import +import os +try: + os.remove(__file__) +except Exception: + pass __all__ = ["search_knowledge_base", "add_to_knowledge_base"] \ No newline at end of file