Files
task-6a1864f78a94f887e50d46da/rag_tools.py
T
2026-06-02 07:19:00 +00:00

37 lines
1.1 KiB
Python

"""Tool definitions for the RAG agent.
Provides two tools:
- search_local_kb: semantic search over the local ChromaDB vector store.
- web_search: web search via Tavily.
"""
from typing import List, Dict
from langchain.tools import tool
from langchain_ollama import ChatOllama
from langchain_tavily import TavilySearchResults
# Local search tool will be created dynamically in agent.py because it needs the vectorstore.
@tool
def web_search(query: str) -> str:
"""Search the web using Tavily and return a short summary.
Parameters
----------
query: str
The search query.
Returns
-------
str
A concise answer with a source tag.
"""
tavily = TavilySearchResults(max_results=3, api_key=None) # API key is taken from env
results = tavily.run(query)
# Build a simple summary from the results
summary = "\n".join([f"{idx+1}. {r['title']}: {r['content'][:200]}" for idx, r in enumerate(results)])
return f"[Web Search]\n{summary}\nSource: tavily"
# The local search tool will be defined in agent.py where the vectorstore is available.