nexus-e-commerce / tools.py
sadaqatyar's picture
Update tools.py
9b7638e verified
raw
history blame contribute delete
740 Bytes
from agents import function_tool
# This tool find and pull out similar info from the data
def create_search_tool(retriever):
@function_tool
def search_docs(query: str) -> str:
"""Search the knowledge base for relevant information."""
docs = retriever.get_relevant_documents(query)
results = []
for i, doc in enumerate(docs, start=1):
page = doc.metadata.get("page", "N/A")
source = doc.metadata.get("source", "N/A")
snippet = doc.page_content
results.append(f"[Result {i}] (Page {page}, Source: {source})\n{snippet}")
return "\n\n".join(results)
# return the tool function so it can be passed to the Agent
return search_docs