73 lines
3.1 KiB
Python
73 lines
3.1 KiB
Python
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
|
|
|
from tradingagents.agents.utils.agent_utils import (
|
|
build_instrument_context,
|
|
get_balance_sheet,
|
|
get_cashflow,
|
|
get_fundamentals,
|
|
get_income_statement,
|
|
get_insider_transactions,
|
|
get_language_instruction,
|
|
)
|
|
|
|
|
|
def create_fundamentals_analyst(llm):
|
|
def fundamentals_analyst_node(state):
|
|
current_date = state["trade_date"]
|
|
instrument_context = build_instrument_context(
|
|
state["company_of_interest"],
|
|
state.get("instrument_profile"),
|
|
)
|
|
|
|
tools = [
|
|
get_fundamentals,
|
|
get_balance_sheet,
|
|
get_cashflow,
|
|
get_income_statement,
|
|
get_insider_transactions,
|
|
]
|
|
|
|
system_message = (
|
|
"You are a fundamentals analyst focused on medium-term business quality and event risk. "
|
|
"Center the report on recent disclosures, earnings quality, guidance changes, capital structure, cash flow, margins, insider transactions, and any notable balance-sheet shifts. "
|
|
"Use `get_fundamentals(ticker, curr_date)` for the overview, `get_balance_sheet`, `get_cashflow`, and `get_income_statement` for statement detail, and `get_insider_transactions(ticker)` for insider activity. "
|
|
"Do not frame this as only a past-week exercise; emphasize the latest reported fundamentals and the most recent event-driven changes that matter for traders."
|
|
" End with a Markdown table summarizing the main fundamental strengths, weaknesses, and watch items."
|
|
+ get_language_instruction()
|
|
)
|
|
|
|
prompt = ChatPromptTemplate.from_messages(
|
|
[
|
|
(
|
|
"system",
|
|
"You are a helpful AI assistant, collaborating with other assistants."
|
|
" Use the provided tools to progress towards answering the question."
|
|
" If you are unable to fully answer, that's OK; another assistant with different tools"
|
|
" will help where you left off. Execute what you can to make progress."
|
|
" Return the completed fundamentals report directly once you have enough evidence."
|
|
" You have access to the following tools: {tool_names}.\n{system_message}"
|
|
" For your reference, the current date is {current_date}. {instrument_context}",
|
|
),
|
|
MessagesPlaceholder(variable_name="messages"),
|
|
]
|
|
)
|
|
|
|
prompt = prompt.partial(system_message=system_message)
|
|
prompt = prompt.partial(tool_names=", ".join([tool.name for tool in tools]))
|
|
prompt = prompt.partial(current_date=current_date)
|
|
prompt = prompt.partial(instrument_context=instrument_context)
|
|
|
|
chain = prompt | llm.bind_tools(tools)
|
|
result = chain.invoke(state["messages"])
|
|
|
|
report = ""
|
|
if len(result.tool_calls) == 0:
|
|
report = result.content
|
|
|
|
return {
|
|
"messages": [result],
|
|
"fundamentals_report": report,
|
|
}
|
|
|
|
return fundamentals_analyst_node
|