Creates a fundamentals analyst node for the trading graph.
Parameters:
| Name |
Type |
Description |
Default |
llm
|
ChatModel
|
The language model to use for generating responses.
|
required
|
Returns:
| Type |
Description |
Callable[[AgentState], dict[str, Any]]
|
Callable[[AgentState], dict[str, Any]]: A function representing the fundamentals analyst node.
|
Source code in src/tradingagents/agents/analysts/fundamentals_analyst.py
| def create_fundamentals_analyst(llm: ChatModel) -> Callable[[AgentState], dict[str, Any]]:
"""Creates a fundamentals analyst node for the trading graph.
Args:
llm (ChatModel): The language model to use for generating responses.
Returns:
Callable[[AgentState], dict[str, Any]]: A function representing the fundamentals analyst node.
"""
def fundamentals_analyst_node(state: AgentState) -> dict[str, Any]:
"""Executes the fundamentals analyst logic to generate a fundamentals report.
Args:
state (AgentState): The current state of the agent, containing data like trade_date and company_of_interest.
Returns:
dict[str, Any]: A dictionary containing updated messages and the fundamentals_report.
"""
tools = [get_fundamentals, get_balance_sheet, get_cashflow, get_income_statement]
prompt = ChatPromptTemplate.from_messages([
("system", load_prompt("fundamentals_analyst")),
MessagesPlaceholder(variable_name="messages"),
])
prompt = prompt.partial(tool_names=", ".join([tool.name for tool in tools]))
prompt = prompt.partial(current_date=state.trade_date)
prompt = prompt.partial(ticker=state.company_of_interest)
chain = prompt | llm.bind_tools(tools)
result = chain.invoke(state.messages)
report = "" if result.tool_calls else result.content
return {"messages": [result], "fundamentals_report": report}
return fundamentals_analyst_node
|