Implementation:24mlight A Share investment Agent sentiment agent
| Knowledge Sources | |
|---|---|
| Domains | NLP, Finance, Sentiment_Analysis |
| Last Updated | 2026-10-10 14:00 GMT |
Overview
Concrete tool for LLM-based news sentiment analysis that fetches stock news, filters to recent articles, and scores sentiment from -1 to 1 provided by the A_Share_investment_Agent repository.
Description
The sentiment_agent function fetches news via get_stock_news(), filters to the last 7 days, and calls get_news_sentiment() which sends formatted news content to an LLM with sentiment analysis prompts. It parses the LLM JSON response for score, signal, confidence, and reasoning, with fallback handling for errors.
Usage
Import when you need to:
- Analyze market sentiment from recent news for a stock
- Run as a parallel node in the LangGraph workflow (after market_data_agent)
Decorated with @agent_endpoint("sentiment", "情绪分析师...").
Code Reference
Source Location
- Repository: A_Share_investment_Agent
- File: src/agents/sentiment.py
- Lines: L16-161
Signature
@agent_endpoint("sentiment", "情绪分析师,分析市场情绪和媒体信号")
def sentiment_agent(state: AgentState) -> dict:
"""Responsible for sentiment analysis."""
Import
from src.agents.sentiment import sentiment_agent
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| state | AgentState | Yes | Reads data["ticker"], data["end_date"] |
Outputs
| Name | Type | Description |
|---|---|---|
| messages | list | HumanMessage with {signal, confidence, reasoning} |
| data["sentiment_analysis"] | str | Sentiment score or "error" |
Usage Examples =
from src.agents.sentiment import sentiment_agent
# Runs as parallel node after market_data_agent
# 1. Fetches news via get_stock_news(symbol, max_news, date, agent_name="sentiment_agent")
# 2. Filters news to last 7 days
# 3. Calls get_news_sentiment(recent_news, symbol, cache_date, trace_state)
# 4. Returns signal (bullish/bearish/neutral/error), confidence, reasoning