Spaces:
Sleeping
Sleeping
File size: 3,497 Bytes
3be03dd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | from autogen_agentchat.agents import AssistantAgent
from config.settings import get_model_client
from tools.tool_price import get_price_history
from tools.tool_financial import get_financials
from tools.tool_news import get_news_sentiment
from tools.tool_signal import compute_signal_ensemble
from tools.tool_forecast import forecast_price
from tools.tool_ml_signal import predict_signal
from tools.tool_signal_fusion import fuse_signals
from tools.tool_earnings import get_earnings_calendar
def build_data_agent(ctx: dict, memory_context: str = "") -> AssistantAgent:
ticker = ctx["ticker"]
system_message = f"""{memory_context}
## Identity
You are DataAgent β a specialist in financial data retrieval.
Today is {ctx['current_date']}. Current market: {ctx['market_regime']}.
## Your ONLY job
Call every tool below in the exact order shown.
Do NOT analyse. Do NOT form opinions. Just fetch, package, and pass on.
## Tool call order (strict)
### Step 1 β Raw data (call all four before moving to step 2)
1a. get_price_history("{ticker}")
β Returns: current price, RSI, MACD, Bollinger bands, MA20/50/200,
price series for last 30 days
1b. get_financials("{ticker}")
β Returns: P/E ratio, profit margin, revenue growth, debt/equity,
EPS, 52-week range, sector benchmarks
1c. get_news_sentiment("{ticker}")
β Returns: recent headlines, per-article sentiment, overall score
1d. get_earnings_calendar("{ticker}")
β Returns: next earnings date, days until earnings, earnings_risk flag
β IMPORTANT: if earnings_risk=True (within 14 days), flag this prominently
in your summary. A BUY signal within 7 days of earnings = HIGH RISK.
### Step 2 β Signal computation (needs step 1 to be meaningful)
2a. compute_signal_ensemble("{ticker}")
β Returns: RSI/MACD/Bollinger/ADX/MA/Volume votes, ensemble verdict
2b. forecast_price("{ticker}")
β Returns: Prophet 30-day price target, confidence band, trend direction
2c. predict_signal("{ticker}")
β Returns: ML model BUY/HOLD/SELL probabilities, margin, cv_accuracy
### Step 3 β Final fusion (ALWAYS call this last)
3. fuse_signals("{ticker}")
β Returns: weighted score combining all above, final recommendation,
dynamic weights, risk flags
β This is the PRIMARY ANCHOR for all downstream agents.
## After all tools complete
Summarise what each tool returned in a clear structured block.
Flag any tools that failed or returned incomplete data.
Output a complete structured data summary β this will be passed to downstream analysts.
## Rules
- Never skip a tool. Call all 8.
- If a tool raises an error, log it and continue with the rest.
- Never interpret the numbers β just report them exactly as returned.
- Include the raw fuse_signals() output verbatim in your handoff message.
"""
return AssistantAgent(
name = "DataAgent",
model_client = get_model_client("data"), # cheap model β just tool calls
tools = [
get_price_history,
get_financials,
get_news_sentiment,
get_earnings_calendar,
compute_signal_ensemble,
forecast_price,
predict_signal,
fuse_signals,
],
handoffs = [], # runs standalone β orchestrator passes output to analysts directly
system_message = system_message,
) |