Skip to content

Commit 907c2e5

Browse files
[Fix] Fix for null tool call error (#70)
Fixed bug in llm_node to add tool_call in assistant_message only when tool_calls are present Co-authored-by: Vipul Mittal <[email protected]>
1 parent b06d22b commit 907c2e5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

sygra/core/graph/nodes/llm_node.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def _inject_history_multiturn(self, state: dict[str, Any], msg_list, window_size
135135
tool_calls = []
136136
tool_calls_data = entry.get("tool_calls", {})
137137
# convert into aimessage format
138-
if isinstance(tool_calls_data, dict):
138+
if isinstance(tool_calls_data, dict) and len(tool_calls_data) > 0:
139139
tool_calls.append(
140140
tool_utils.convert_openai_to_langchain_toolcall(tool_calls_data)
141141
)
@@ -145,7 +145,11 @@ def _inject_history_multiturn(self, state: dict[str, Any], msg_list, window_size
145145
tool_utils.convert_openai_to_langchain_toolcall(tc_entry)
146146
)
147147

148-
assistant_message = AIMessage(content=entry["content"], tool_calls=tool_calls)
148+
assistant_message = (
149+
AIMessage(content=entry["content"], tool_calls=tool_calls)
150+
if len(tool_calls) > 0
151+
else AIMessage(content=entry["content"])
152+
)
149153
updated_msg_list.append(assistant_message)
150154
elif entry["role"] == "tool":
151155
content = str(entry["content"])

0 commit comments

Comments
 (0)