from typing import List, Callable
from agno.knowledge.document import Document
from agno.knowledge.protocol import KnowledgeProtocol
class MyKnowledge:
"""Custom knowledge implementation."""
def __init__(self, data_source: str):
self.data_source = data_source
def build_context(self, **kwargs) -> str:
return "Use search_docs to find information from the knowledge base."
def get_tools(self, **kwargs) -> List[Callable]:
return [self.search_docs]
async def aget_tools(self, **kwargs) -> List[Callable]:
return [self.search_docs]
def search_docs(self, query: str) -> str:
"""Search the knowledge base.
Args:
query: Search query
"""
# Your search implementation
results = self._search(query)
return "\n\n".join(results)
def retrieve(self, query: str, **kwargs) -> List[Document]:
"""Retrieve documents for context injection."""
results = self._search(query)
return [Document(content=r) for r in results]
def _search(self, query: str) -> List[str]:
# Your actual search logic
return ["Result 1", "Result 2"]