Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion backend/app/api/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,15 @@ async def _call_with_failover():
async def _on_failover(reason: str):
await websocket.send_json({"type": "info", "content": f"Primary model error, {reason}"})

# To prevent tool call message pairs(assistant + tool) from being broken down.
_truncated = conversation[-ctx_size:]
while _truncated and _truncated[0].get("role") == "tool":
_truncated.pop(0)

return await call_llm_with_failover(
primary_model=llm_model,
fallback_model=fallback_llm_model,
messages=conversation[-ctx_size:],
messages=_truncated,
agent_name=agent_name,
role_description=role_description,
agent_id=agent_id,
Expand Down