Merge pull request #4 from ducga1998/coderabbitai/docstrings/e6dfed2

📝 Add docstrings to `feature-complete-XAU`
This commit is contained in:
Nguyễn Minh Đức 2025-10-15 18:21:21 +07:00 committed by GitHub
commit f94bc6f559
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 94 additions and 12 deletions

View File

@ -3,10 +3,28 @@ from tradingagents.dataflows.fred_api import get_dxy_data, get_real_yields, get_
def create_xau_macro_analyst(llm):
"""
Creates a node for the XAU Macro Analyst agent.
This agent specializes in analyzing macroeconomic factors that influence the price of gold (XAU/USD).
It replaces the traditional fundamentals analyst for equity trading.
Create a node factory that builds an XAU (gold) macroeconomic analyst agent.
The returned node analyzes macro drivers of XAU/USD (DXY, 10-year real yields, inflation metrics, and optionally Fed policy/VIX) using bound data-fetching tools, and synthesizes a comprehensive report that concludes with a Markdown table summarizing each factor's likely impact (Bullish, Bearish, or Neutral).
Returns:
callable: A node function that accepts a `state` dict and returns a dict containing:
- "messages": a list with the agent's final message/result.
- "xau_macro_report": the agent's textual report (empty string if the result contains tool calls).
"""
"""
Execute the XAU macro analyst for a given state.
Parameters:
state (dict): Execution state expected to include:
- "trade_date": date string used as the chain's current_date.
- "messages": conversation messages supplied to the chain.
Returns:
dict: {
"messages": [result], # list containing the chain result object
"xau_macro_report": report_str, # string report produced when no tool calls were made
}
"""
system_message = (
@ -51,7 +69,17 @@ def create_xau_macro_analyst(llm):
def xau_macro_analyst_node(state):
"""
The node function for the XAU Macro Analyst.
Run the XAU Macro Analyst chain for a given trading state and return the chain result plus a produced macro report.
Parameters:
state (dict): Execution state containing:
- "trade_date": date or string used as the chain's current date.
- "messages": list of messages to pass into the chain.
Returns:
dict: Contains:
- "messages": list with the chain invocation result as its single element.
- "xau_macro_report": the report string; set to the chain result's content if the result performed no tool calls, otherwise an empty string.
"""
current_date = state["trade_date"]
# The ticker is XAU, but the tools are specific to macro data.

View File

@ -4,10 +4,26 @@ from tradingagents.dataflows.etf_flows import get_gold_etf_summary, get_gold_etf
def create_xau_positioning_analyst(llm):
"""
Creates a node for the XAU Positioning Analyst agent.
This agent analyzes market positioning and sentiment for gold (XAU/USD)
using COT reports and ETF flow data. It replaces the standard social media analyst.
Create and configure an XAU (Gold) Positioning Analyst node that synthesizes COT reports and ETF flow data.
Constructs a tool-assisted prompt chain focused on Gold (XAU/USD) positioning using Commitment of Traders (COT) data and major gold ETF flows, and returns a node function that performs the analysis for a given state.
Returns:
xau_positioning_analyst_node (callable): A node function that accepts a `state` dict and returns a dict containing analysis messages and a generated `xau_positioning_report`.
"""
"""
Execute the XAU Positioning Analyst on a given state.
Parameters:
state (dict): Execution state containing at least:
- "trade_date": date or date-like string used as the prompt's current_date.
- "messages": list of messages to pass into the prompt chain.
Returns:
dict: {
"messages": [result_message], # list containing the chain result message
"xau_positioning_report": report (str) # report text when no tool calls were made, otherwise empty string
}
"""
system_message = (
@ -50,7 +66,18 @@ def create_xau_positioning_analyst(llm):
def xau_positioning_analyst_node(state):
"""
The node function for the XAU Positioning Analyst.
Execute the XAU positioning analyst chain for the given state and produce a positioning report.
Parameters:
state (dict): Runtime state containing:
- "trade_date" (str or date): Trade date to bind into the analyst chain.
- "messages" (list): Messages to pass into the analyst chain.
Returns:
dict: {
"messages": [result], # list containing the chain invocation result object
"xau_positioning_report": str # report text extracted from result.content when no tool calls were made, otherwise an empty string
}
"""
current_date = state["trade_date"]
chain_with_date = chain.partial(current_date=current_date)

View File

@ -59,6 +59,15 @@ from tradingagents.dataflows.correlation_tools import (
def create_msg_delete():
"""
Clear all messages in the provided state and insert a minimal placeholder message for compatibility.
Parameters:
state (dict): Mutable state containing a "messages" key with an iterable of message objects. Each message object must have an `id` attribute used to build removal operations.
Returns:
dict: A mapping with the key "messages" whose value is a list consisting of RemoveMessage removal operations for each existing message followed by a single HumanMessage placeholder with content "Continue".
"""
def delete_messages(state):
"""Clear messages and add placeholder for Anthropic compatibility"""
messages = state["messages"]

View File

@ -29,6 +29,13 @@ class XAUTradingGraph(TradingAgentsGraph):
def __init__(self, debug=False, config=None):
# Use XAU-specific config and analyst team
"""
Initialize the XAUTradingGraph with XAU-specific configuration and analyst team.
Parameters:
debug (bool): Enable debug mode when True.
config (dict | None): Optional configuration dictionary to override the default XAU_CONFIG; the analyst team is taken from this config's "analyst_team" key if present.
"""
xau_config = config or XAU_CONFIG
xau_analysts = xau_config.get("analyst_team", [])
@ -40,7 +47,16 @@ class XAUTradingGraph(TradingAgentsGraph):
def _create_tool_nodes(self):
"""
Override the tool node creation to use XAU-specific tools.
Constructs the XAU-specific mapping of tool nodes used by the trading graph.
Groups related analysis tools into four ToolNode entries for market data, macroeconomic indicators, news, and positioning/ETF flows.
Returns:
dict: Mapping of tool node names to ToolNode instances:
- "xau_market": market data and indicator tools
- "xau_macro": macroeconomic and FRED-series tools
- "xau_news": news aggregation tools
- "xau_positioning": positioning, COT analysis, and gold ETF tools
"""
return {
"xau_market": ToolNode([

View File

@ -7,7 +7,9 @@ load_dotenv()
def run_xau_analysis():
"""
Initializes and runs the XAU Trading System for a specific date.
Run the XAU trading-analysis workflow for a predetermined asset and date.
Initializes the XAU trading graph with debug enabled and the module configuration, executes a propagation for the hard-coded asset ticker "GC=F" on "2024-05-10", and prints any generated macro and positioning analyst reports followed by the final trade decision. On failure, prints an error message and the exception traceback.
"""
print("Initializing XAU Trading System...")