Skip to content

Build and run agents you can see, understand and trust.

fix(agent): guard against empty or interrupted streaming responses (#1861)

xueshanfeihu0073d10118e4f86
diff --git a/src/agentscope/agent/_agent.py b/src/agentscope/agent/_agent.py
index 7440a1305..8c7acc90e 100644
--- a/src/agentscope/agent/_agent.py
+++ b/src/agentscope/agent/_agent.py
@@ -879,6 +879,15 @@ class Agent:
block_id=data_block_id,
)
+ # Guard against empty or interrupted streaming responses.
+ if completed_response is None:
+ raise RuntimeError(
+ "Model returned an empty streaming response: no is_last=True"
+ " chunk was received. The model call may have been "
+ "interrupted mid-stream (network dropout, timeout, or model "
+ "bug).",
+ )
+
# Send the model call ended event with usage if available
yield ModelCallEndEvent(
reply_id=self.state.reply_id,