Spaces:
Running

yf176 commited on
Commit
cec724c
·
1 Parent(s): c07a8a8

fix: break TrendAnalyst/DataFetcher routing loop - cycle guard + smart mid-chain routing

Browse files
src/polyhedra/agents/quant/datafetcher.py CHANGED
@@ -119,7 +119,15 @@ class DataFetcherAgent(Agent):
119
  logger.warning("DataFetcher: failed to write summary for %s: %s", ticker, exc)
120
 
121
  content = self._build_response(fetched, failed, cap_hit, cap_hit_ticker)
122
- next_mentions = ["human"] if (not fetched and cap_hit) else ["trendanalyst"]
 
 
 
 
 
 
 
 
123
  return AgentResponse(
124
  agent_role=self.role,
125
  content=content,
 
119
  logger.warning("DataFetcher: failed to write summary for %s: %s", ticker, exc)
120
 
121
  content = self._build_response(fetched, failed, cap_hit, cap_hit_ticker)
122
+ # If trend analysis for today already exists, DataFetcher was called mid-chain
123
+ # (e.g. by TrendAnalyst requesting more data). Skip straight to sentimentanalyst.
124
+ trend_exists = bool(self.files.read(f"quant/trend_analysis_{date.today().isoformat()}.md"))
125
+ if not fetched and cap_hit:
126
+ next_mentions = ["human"]
127
+ elif trend_exists:
128
+ next_mentions = ["sentimentanalyst"]
129
+ else:
130
+ next_mentions = ["trendanalyst"]
131
  return AgentResponse(
132
  agent_role=self.role,
133
  content=content,
src/polyhedra/agents/quant/trendanalyst.py CHANGED
@@ -113,6 +113,14 @@ class TrendAnalystAgent(Agent):
113
 
114
  next_role, reason, analysis = parse_llm_routing(llm_text)
115
 
 
 
 
 
 
 
 
 
116
  artifact_path = f"quant/trend_analysis_{today}.md"
117
  self.files.write(artifact_path, analysis, mode="overwrite")
118
 
@@ -159,6 +167,9 @@ Format each ticker as a `## <TICKER>` section header. Be specific with numbers.
159
  - If a required input summary file is missing or empty, respond with:
160
  "Skipped — missing input: quant/raw/<ticker>_summary.md"
161
  and route to @datafetcher.
 
 
 
162
  {_ETF_CONSTRAINT}
163
 
164
  ## [5] ROUTING
 
113
 
114
  next_role, reason, analysis = parse_llm_routing(llm_text)
115
 
116
+ # Cycle guard: summaries exist → DataFetcher already ran this session.
117
+ # Never re-route back to datafetcher; proceed to sentimentanalyst.
118
+ if next_role == "datafetcher":
119
+ logger.warning(
120
+ "TrendAnalyst: suppressing datafetcher re-route (cycle guard) → sentimentanalyst"
121
+ )
122
+ next_role = "sentimentanalyst"
123
+
124
  artifact_path = f"quant/trend_analysis_{today}.md"
125
  self.files.write(artifact_path, analysis, mode="overwrite")
126
 
 
167
  - If a required input summary file is missing or empty, respond with:
168
  "Skipped — missing input: quant/raw/<ticker>_summary.md"
169
  and route to @datafetcher.
170
+ - If you were invoked after DataFetcher already ran (i.e. summary files are present),
171
+ treat any remaining data gaps (e.g. missing earnings) as unavailable data.
172
+ Flag them explicitly and proceed to @sentimentanalyst — do NOT route back to @datafetcher.
173
  {_ETF_CONSTRAINT}
174
 
175
  ## [5] ROUTING