FeiMatrix-Synapse / tools /tool_registry.py
aifeifei798's picture
Upload 7 files
719390c verified
raw
history blame
1.37 kB
# tools/tool_registry.py
from langchain_core.tools import tool
from typing import List, Any
# Import the actual tool functions
from .stock_tool import get_stock_price
from .news_tool import search_latest_news
# Use LangChain's @tool decorator to define tools.
# This is more robust as it automatically handles descriptions and argument schemas.
@tool
def get_stock_price_tool(symbol: str) -> str:
"""
Gets the real-time stock price for a given stock symbol (e.g., AAPL, GOOGL).
Use this tool when the user asks for the stock price of a specific company.
"""
return get_stock_price(symbol)
@tool
def search_latest_news_tool(query: str) -> str:
"""
Searches for the latest news articles based on a keyword.
Use this tool when the user asks about the latest updates, events, or news on a certain topic.
"""
return search_latest_news(query)
# Central registry for all tools
_all_tools = [
get_stock_price_tool,
search_latest_news_tool,
]
def get_all_tools() -> List[Any]:
"""Returns a list containing all defined tool objects."""
return _all_tools
def get_tool_by_name(name: str) -> Any:
"""Finds and returns a tool object by its name."""
for tool_obj in _all_tools:
if tool_obj.name == name:
return tool_obj
return None