Squashed 'packages/tools/' content from commit 78317b9c

git-subtree-dir: packages/tools
git-subtree-split: 78317b9c127f18bd040c1d77e3c0840cdc9a5b38
This commit is contained in:
Greyson Lalonde
2025-09-12 21:58:02 -04:00
commit e16606672a
303 changed files with 49010 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
from typing import Optional, Type
from pydantic import BaseModel, Field
from ..rag.rag_tool import RagTool
class FixedXMLSearchToolSchema(BaseModel):
"""Input for XMLSearchTool."""
search_query: str = Field(
...,
description="Mandatory search query you want to use to search the XML's content",
)
class XMLSearchToolSchema(FixedXMLSearchToolSchema):
"""Input for XMLSearchTool."""
xml: str = Field(..., description="File path or URL of a XML file to be searched")
class XMLSearchTool(RagTool):
name: str = "Search a XML's content"
description: str = (
"A tool that can be used to semantic search a query from a XML's content."
)
args_schema: Type[BaseModel] = XMLSearchToolSchema
def __init__(self, xml: Optional[str] = None, **kwargs):
super().__init__(**kwargs)
if xml is not None:
self.add(xml)
self.description = f"A tool that can be used to semantic search a query the {xml} XML's content."
self.args_schema = FixedXMLSearchToolSchema
self._generate_description()
def _run(
self,
search_query: str,
xml: Optional[str] = None,
) -> str:
if xml is not None:
self.add(xml)
return super()._run(query=search_query)