fixed anthropic support. Anthropic has different format of response when it has tool calls. Explicit handling added

This commit is contained in:
Edward Sun 2025-06-21 12:51:34 -07:00
parent 7eaf4d995f
commit 52284ce13c
5 changed files with 26 additions and 6 deletions

View File

@ -97,7 +97,7 @@ class MessageBuffer:
if content is not None: if content is not None:
latest_section = section latest_section = section
latest_content = content latest_content = content
if latest_section and latest_content: if latest_section and latest_content:
# Format the current section for display # Format the current section for display
section_titles = { section_titles = {
@ -808,7 +808,7 @@ def run_analysis():
msg_type = "System" msg_type = "System"
# Add message to buffer # Add message to buffer
message_buffer.add_message(msg_type, content) message_buffer.add_message(msg_type, content)
# If it's a tool call, add it to tool calls # If it's a tool call, add it to tool calls
if hasattr(last_message, "tool_calls"): if hasattr(last_message, "tool_calls"):

View File

@ -51,9 +51,14 @@ def create_fundamentals_analyst(llm, toolkit):
result = chain.invoke(state["messages"]) result = chain.invoke(state["messages"])
report = ""
if len(result.tool_calls) == 0:
report = result.content
return { return {
"messages": [result], "messages": [result],
"fundamentals_report": result.content, "fundamentals_report": report,
} }
return fundamentals_analyst_node return fundamentals_analyst_node

View File

@ -76,9 +76,14 @@ Volume-Based Indicators:
result = chain.invoke(state["messages"]) result = chain.invoke(state["messages"])
report = ""
if len(result.tool_calls) == 0:
report = result.content
return { return {
"messages": [result], "messages": [result],
"market_report": result.content, "market_report": report,
} }
return market_analyst_node return market_analyst_node

View File

@ -47,9 +47,14 @@ def create_news_analyst(llm, toolkit):
chain = prompt | llm.bind_tools(tools) chain = prompt | llm.bind_tools(tools)
result = chain.invoke(state["messages"]) result = chain.invoke(state["messages"])
report = ""
if len(result.tool_calls) == 0:
report = result.content
return { return {
"messages": [result], "messages": [result],
"news_report": result.content, "news_report": report,
} }
return news_analyst_node return news_analyst_node

View File

@ -47,9 +47,14 @@ def create_social_media_analyst(llm, toolkit):
result = chain.invoke(state["messages"]) result = chain.invoke(state["messages"])
report = ""
if len(result.tool_calls) == 0:
report = result.content
return { return {
"messages": [result], "messages": [result],
"sentiment_report": result.content, "sentiment_report": report,
} }
return social_media_analyst_node return social_media_analyst_node