How to Fix 'streaming response cutoff' in CrewAI (TypeScript)
What “streaming response cutoff” actually means
This error usually means CrewAI started streaming output from the model, then the stream ended before CrewAI got a complete, valid response. In TypeScript projects, it most often shows up when you’re using a streaming model call with an agent/task setup that expects a full final message, or when your transport layer cuts the connection early.
You’ll typically see it during kickoff(), execute(), or while reading a streamed response from CrewAgentExecutor / Task. The key point: CrewAI did not receive enough tokens or a properly terminated stream to finish parsing the assistant output.
The Most Common Cause
The #1 cause is mixing streaming mode with code that expects a final structured response, especially when the stream is consumed incorrectly or interrupted by your own wrapper.
A common failure pattern is returning early from the stream handler, or not fully draining the async iterator. In CrewAI TypeScript setups, this often happens around ChatOpenAI, custom LLM adapters, or when piping streamed chunks into your own callback logic.
| Broken pattern | Fixed pattern |
|---|---|
| Stops reading after first chunk | Drains the full stream |
| Returns partial content to CrewAI | Waits for complete assistant message |
| Uses streaming where non-streaming is required | Disables streaming for final structured outputs |
Broken code
import { Agent, Task, Crew } from "crewai";
const agent = new Agent({
role: "Support Analyst",
goal: "Answer customer questions",
backstory: "Works on banking support tickets",
// This LLM streams, but the rest of the pipeline expects a full response.
llm: {
model: "gpt-4o-mini",
stream: true,
},
});
const task = new Task({
description: "Summarize this claim note",
expectedOutput: "A short summary",
agent,
});
const crew = new Crew({ agents: [agent], tasks: [task] });
// Somewhere in your app:
const result = await crew.kickoff();
console.log(result);
Fixed code
import { Agent, Task, Crew } from "crewai";
const agent = new Agent({
role: "Support Analyst",
goal: "Answer customer questions",
backstory: "Works on banking support tickets",
// Disable streaming for final task execution unless you explicitly handle the stream.
llm: {
model: "gpt-4o-mini",
stream: false,
},
});
const task = new Task({
description: "Summarize this claim note",
expectedOutput: "A short summary",
agent,
});
const crew = new Crew({ agents: [agent], tasks: [task] });
const result = await crew.kickoff();
console.log(result);
If you do need streaming, consume it completely and only hand CrewAI finalized text.
const stream = await agent.llm.stream("Summarize this claim note");
let fullText = "";
for await (const chunk of stream) {
fullText += chunk;
}
console.log(fullText);
Other Possible Causes
1) Proxy or gateway timeout
If you’re running through an API gateway, reverse proxy, or serverless function timeout, the connection can die mid-stream.
proxy_read_timeout 300s;
proxy_send_timeout 300s;
In serverless environments, increase execution time or avoid streaming through that path.
2) Token limit too low
A truncated completion can look like a cutoff if the model hits max tokens before finishing.
llm: {
model: "gpt-4o-mini",
maxTokens: 256,
}
Fix:
llm: {
model: "gpt-4o-mini",
maxTokens: 1024,
}
3) Invalid tool output causing parser failure
CrewAI can cut off if an agent tool returns malformed JSON or unexpected text during an action chain.
tools: [
{
name: "lookupPolicy",
execute: async () => "{ policyId: 123 }", // invalid JSON
},
];
Fix:
tools: [
{
name: "lookupPolicy",
execute: async () => JSON.stringify({ policyId: 123 }),
},
];
4) Model/provider mismatch
Some providers advertise streaming but behave differently under load. If you swapped providers recently, verify the SDK supports true incremental chunks.
llm: {
provider: "custom-openai-compatible",
baseUrl: process.env.LLM_BASE_URL,
stream: true,
}
If that provider buffers responses instead of streaming real chunks, disable streaming and test again.
How to Debug It
- •
Turn off streaming first
- •Set
stream: false. - •If the error disappears, your issue is almost certainly in stream handling or transport interruption.
- •Set
- •
Log raw chunk boundaries
- •Print every chunk before passing it downstream.
- •Check whether the last chunk arrives cleanly or stops mid-response.
for await (const chunk of stream) {
console.log("chunk:", chunk);
}
- •
Check token and timeout settings
- •Inspect
maxTokens, request timeout, proxy timeout, and serverless limits. - •Compare them against typical completion length for your task.
- •Inspect
- •
Isolate tools and parsers
- •Run the same task with tools removed.
- •Then run with one tool at a time.
- •If cutoff only happens with one tool, that tool is returning invalid output or hanging.
Prevention
- •Use
stream: falsefor tasks where CrewAI needs a complete final answer for parsing or handoff. - •Keep tool outputs strict and machine-readable; return JSON strings, not ad hoc objects or prose.
- •Set explicit timeouts and token budgets in both your app and infrastructure layer.
- •Add integration tests that run one crew with streaming off and one with streaming on so regressions show up early.
Keep learning
- •The complete AI Agents Roadmap — my full 8-step breakdown
- •Free: The AI Agent Starter Kit — PDF checklist + starter code
- •Work with me — I build AI for banks and insurance companies
By Cyprian Aarons, AI Consultant at Topiax.
Want the complete 8-step roadmap?
Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.
Get the Starter Kit