Skip to content

Multi-Agent Intelligence Swarm ​

examples/data-research/analyst-swarm.halo policies |* parallel |! people

An autonomous research analyst that detects anomalies in market data, correlates findings with news sentiment, builds a risk report, and routes it for human sign-off.

Open in the playground and play with it →

halo
// ============================================================
// Multi-Agent Intelligence Swarm
// ============================================================
// An autonomous research analyst that detects anomalies in
// market data, correlates findings with news sentiment,
// builds a risk report, and routes it for human sign-off.
// ============================================================

// --- SAFETY & COMPLIANCE ---
// Personal financial data is masked before any model sees it, and news
// text can't steer the agents. Insider trading can't be pattern-matched:
// the RiskAssessor's approve/reject gate and the human sign-off stop it.
policy FinancialCompliance : Redact(PII, APIKey) & Block(PromptInjection)
policy BudgetLimit         : MaxSpend(25.00)

// --- TOOLS: External connections ---
tool Bloomberg      : POST("api.bloomberg.com/v1/data", apiKey: Env.BLM_KEY)
tool NewsAPI        : POST("api.newsapi.org/v2", apiKey: Env.NEWS_KEY)
tool SlackChannel   : POST("hooks.slack.com/services/webhook-id")
tool VectorDB       : PostgreSQL(Env.VECTOR_DB_URI)

// --- MEMORY: Persistent state ---
tool MarketHistory  : VectorStore(Env.PINECONE_KEY, namespace: "market-data")
tool Playbook       : VectorStore(Env.PINECONE_KEY, namespace: "response-playbooks")

// --- MINDS: The agents ---
// A second model answers every Researcher call alongside it; its answers are
// recorded in context.meta.shadows for comparison, never used.
agent Researcher_QA [openai/gpt-4o, temp: 0.1]
  system """
    You are a quantitative research analyst specializing in
    market anomaly detection. Always include confidence
    intervals and cite data sources.
  """
  requires FinancialCompliance, BudgetLimit

// The researcher runs deep analysis with full tool access
@shadow(Researcher_QA)
agent Researcher [anthropic/claude-sonnet-4, temp: 0.1]
  system """
    You are a quantitative research analyst specializing in
    market anomaly detection. Correlate price movements with
    news events and historical patterns. Always include
    confidence intervals and cite data sources.
  """
  equips Bloomberg, MarketHistory, Playbook
  requires FinancialCompliance, BudgetLimit

// The writer produces human-readable reports
agent ReportWriter [openai/gpt-4o-mini, temp: 0.3]
  system """
    You are a financial briefing author. Write concise
    executive-level reports from raw analyst data. Structure
    as: situation, analysis, recommendation, risk. Use
    precise language — no hedging, no filler.
  """
  requires FinancialCompliance

// The risk assessor makes go/no-go decisions
agent RiskAssessor [anthropic/claude-sonnet-4, temp: 0.0]
  system """
    You are a risk compliance officer. Make binary approve/reject
    decisions on analyst reports. Check for regulatory exposure,
    position-size risk, and compliance violations. Reject
    anything with unresolved red flags, and anything that rests
    on material non-public information.
    Answer with JSON: {"decision": "approve" | "reject", "reason": "..."}
  """
  requires FinancialCompliance, BudgetLimit

// --- THE STREAM ---
schema MarketAnomaly {
  symbol : String
}

@timeout(10m)
@retry(3, 5s)
pipeline AnomalyResponse(alert: MarketAnomaly) -> Result:
  alert
    // Step 1: Fan-out — run independent investigations in parallel
    // Both tasks merge automatically when the block closes
    |* {
         Researcher.analyze(
           context.data.alert.symbol,
           "Compare current metrics against 90-day historical baseline"
         ) as assessment,
         Researcher.search(
           context.data.alert.symbol,
           "breaking news about the affected company and sector"
         ) as news
       }

    // Step 2: Gate — only proceed if anomaly is confirmed (confidence > 75%)
    |? (context.data.assessment.confidence > 75)

    // Step 3: Correlate findings with existing playbooks
    |> Researcher.similar(
         context.data.assessment.summary,
         0.85
       ) as playbook

    // Step 4: Generate the report
    |> ReportWriter.compose(
         "AnalystBriefing",
         [context.data.assessment, context.data.news, context.data.playbook],
         "executive"
       ) as briefing

    // Step 5: Risk sign-off — the assessor must approve
    |> RiskAssessor.evaluate(
         context.data.briefing,
         "financial_compliance"
       ) as risk

    // Step 6: Gate on risk decision
    |? (context.data.risk.decision == "approve")

    // Step 7: Send for final human review via Slack
    |! yield(
         SlackChannel,
         context.data.briefing.executive_summary,
         [context.data.briefing.full_report, context.data.briefing.charts],
         1h
       )

    // Step 8: Wait for human response
    ~> listen(SlackChannel.Interaction) as human_response

    // Step 9: Final gate — human approved?
    |? (context.data.human_response.approved == true)
    |> System.Distribute(
         context.data.briefing.distribution_list,
         SlackChannel
       )

curl -fsSL https://halolang.com/install.sh | sh