Bug Description
response_adapter.py line 164 crashes with IndexError: list index out of range when the streaming API sends a final SSE chunk that does not contain a choices field (e.g., a usage-only statistics chunk).
# Line 164 — no guard for missing or empty choices
if "message" not in done_message["choices"][0]:
Steps to Reproduce
- Configure Agently (v4.1.3.5) with an OpenAI-compatible API that sends a usage-only chunk as the final SSE event before
[DONE], such as MiMo:
agent.set_settings(
"OpenAICompatible",
{
"base_url": os.environ.get("MIMO_BASE_URL"),
"model": os.environ.get("MIMO_DEFAULT_MODEL"),
"auth": os.environ.get("MIMO_API_KEY"),
},
)
- Make a streaming request:
result = agent.prompt("Hello").get_delta()
- The stream completes successfully (content is accumulated in
content_buffer), but the final [DONE] handler crashes.
Error Traceback
IndexError: list index out of range
File ".../agently/core/model/ModelResponse.py", line 321, in _get_response_generator
async for event, data in broadcast_generator:
File ".../agently/builtins/plugins/ModelRequester/OpenAICompatible/modules/response_adapter.py", line 164, in broadcast_response
if "message" not in done_message["choices"][0]:
Expected Behavior
The adapter should guard against missing or empty choices before accessing done_message["choices"][0]. For example:
if "choices" in done_message and len(done_message["choices"]) > 0:
if "message" not in done_message["choices"][0]:
done_message["choices"][0].update({"message": {}})
done_message["choices"][0]["message"].update(...)
else:
done_message["choices"] = [{"message": {"role": "assistant", "content": done_content or content_buffer}}]
Actual Behavior
The code assumes every SSE chunk has a non-empty choices array. Some non-standard OpenAI-compatible APIs (e.g., MiMo) send a final chunk like:
{"id":"...","usage":{"prompt_tokens":...,"completion_tokens":...}}
This overwrites message_record (line 66), and when [DONE] is processed, done_message["choices"] is a KeyError or done_message["choices"] is [], causing IndexError.
Workaround
Set "stream": False in plugin settings to bypass streaming.
Environment
- Agently version: 4.1.3.5
- Python: 3.10
- Model provider: MiMo (OpenAI-compatible API)
- OS: macOS
Bug Description
response_adapter.pyline 164 crashes withIndexError: list index out of rangewhen the streaming API sends a final SSE chunk that does not contain achoicesfield (e.g., a usage-only statistics chunk).Steps to Reproduce
[DONE], such as MiMo:content_buffer), but the final[DONE]handler crashes.Error Traceback
Expected Behavior
The adapter should guard against missing or empty
choicesbefore accessingdone_message["choices"][0]. For example:Actual Behavior
The code assumes every SSE chunk has a non-empty
choicesarray. Some non-standard OpenAI-compatible APIs (e.g., MiMo) send a final chunk like:{"id":"...","usage":{"prompt_tokens":...,"completion_tokens":...}}This overwrites
message_record(line 66), and when[DONE]is processed,done_message["choices"]is aKeyErrorordone_message["choices"]is[], causingIndexError.Workaround
Set
"stream": Falsein plugin settings to bypass streaming.Environment