Skip to content

Commit bbca177

Browse files
authored
Update agent.py
1 parent 67d378c commit bbca177

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

python_agent_harness/agent.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,12 @@ def safe_delta(text: str) -> None:
676676
return # response arrived after cancel: drop it
677677

678678
# persist the assistant response in the conversation history
679-
# (text and/or tool calls) so later turns and the UI see it
679+
# (text and/or tool calls) so later turns and the UI see it;
680+
# always append to maintain role alternation — a missing
681+
# assistant message before a nudge creates consecutive user
682+
# messages which some APIs reject with a 400 error.
683+
self.messages.append(assistant)
680684
if assistant.text().strip() or assistant.tool_calls:
681-
self.messages.append(assistant)
682685
if not assistant.tool_calls and self.top_level:
683686
session.last_messages = list(self.messages)
684687

0 commit comments

Comments
 (0)