fix: handle comma-separated indicators in get_indicators tool

LLMs (especially smaller models) sometimes pass multiple indicator
names as a single comma-separated string instead of making separate
tool calls. Split and process each individually at the tool boundary.
This commit is contained in:
Yijia-Xiao 2026-03-15 18:05:36 +00:00
parent eec6ca4b53
commit fe9c8d5d31
1 changed files with 11 additions and 3 deletions

View File

@ -10,14 +10,22 @@ def get_indicators(
look_back_days: Annotated[int, "how many days to look back"] = 30,
) -> str:
"""
Retrieve technical indicators for a given ticker symbol.
Retrieve a single technical indicator for a given ticker symbol.
Uses the configured technical_indicators vendor.
Args:
symbol (str): Ticker symbol of the company, e.g. AAPL, TSM
indicator (str): Technical indicator to get the analysis and report of
indicator (str): A single technical indicator name, e.g. 'rsi', 'macd'. Call this tool once per indicator.
curr_date (str): The current trading date you are trading on, YYYY-mm-dd
look_back_days (int): How many days to look back, default is 30
Returns:
str: A formatted dataframe containing the technical indicators for the specified ticker symbol and indicator.
"""
return route_to_vendor("get_indicators", symbol, indicator, curr_date, look_back_days)
# LLMs sometimes pass multiple indicators as a comma-separated string;
# split and process each individually.
indicators = [i.strip() for i in indicator.split(",") if i.strip()]
if len(indicators) > 1:
results = []
for ind in indicators:
results.append(route_to_vendor("get_indicators", symbol, ind, curr_date, look_back_days))
return "\n\n".join(results)
return route_to_vendor("get_indicators", symbol, indicator.strip(), curr_date, look_back_days)