Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:24mlight A Share investment Agent macro news agent

From Leeroopedia
Knowledge Sources
Domains Finance, Macro_Economics, NLP
Last Updated 2026-10-10 14:00 GMT

Overview

Concrete tool for CSI 300 market-wide macro news analysis with SQLite caching, fetching index news and generating LLM-based macro environment summaries provided by the A_Share_investment_Agent repository.

Description

The macro_news_agent function fetches news for the CSI 300 index (ticker "000300"), sends it to an LLM with a structured macro analysis prompt, and produces a payload with signal, confidence, score (0-100), summary, key drivers, key risks, and actionable insight. Results are cached in SQLite keyed by macro_news_summary|000300|{date} to avoid redundant LLM calls on the same day.

The module includes extensive JSON sanitization helpers: _sanitize_signal, _sanitize_confidence, _sanitize_score, _sanitize_list, _normalize_llm_json_text, _coerce_to_dict, _sanitize_llm_text, and _payload_from_llm — all designed to robustly parse potentially malformed LLM JSON responses.

Usage

Import when you need to:

  • Analyze CSI 300 market-wide macro news for investment context
  • Run as a parallel node after market_data_agent (alongside other analysts)

Decorated with @agent_endpoint("macro_news_agent", "获取沪深300全量新闻...").

Code Reference

Source Location

  • Repository: A_Share_investment_Agent
  • File: src/agents/macro_news_agent.py
  • Lines: L217-400 (agent), L29-213 (sanitization helpers)

Signature

@agent_endpoint("macro_news_agent", "获取沪深300全量新闻并进行宏观分析...")
def macro_news_agent(state: AgentState) -> Dict[str, Any]:
    """Fetch CSI 300 news and generate LLM macro summary."""

Import

from src.agents.macro_news_agent import macro_news_agent

I/O Contract

Inputs

Name Type Required Description
state AgentState Yes Reads data["end_date"] as cache_date; uses ticker "000300"

Outputs

Name Type Description
messages list HumanMessage with macro analysis payload
data["macro_news_analysis_result"] dict {index, signal, confidence, score, summary, key_drivers, key_risks, actionable_insight, news_count, from_cache}
data["macro_news_summary_text"] str Summary text

Usage Examples

from src.agents.macro_news_agent import macro_news_agent

# Runs as parallel node after market_data_agent
# 1. Checks SQLite cache for macro_news_summary|000300|{date}
# 2. If cache miss: fetches news via get_stock_news("000300", ...)
# 3. Sends news to LLM with prompts/macro_news_agent/prompt.md
# 4. Parses JSON with extensive sanitization (curly quotes, code fences, etc.)
# 5. Caches result in SQLite llm_result_cache table

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment