How to Fix 'deployment crash in production' in CrewAI (TypeScript)
When CrewAI says deployment crash in production, it usually means your agent graph boots locally but dies once the app runs under real production constraints: missing env vars, bad tool wiring, async failures, or a process that exits before the crew finishes. In TypeScript, this often shows up after deployment to Vercel, Docker, ECS, or a serverless runtime where startup and execution behavior is stricter than your laptop.
The key is to separate CrewAI runtime failures from deployment/runtime failures. Most of the time, the crash is not “CrewAI is broken” — it’s one of a few predictable integration mistakes.
The Most Common Cause
The #1 cause is running async CrewAI execution incorrectly in a production entrypoint. In TypeScript, people often create the crew and call kickoff() without properly awaiting it, or they let the process exit before the promise resolves.
Here’s the broken pattern:
// broken.ts
import { Crew, Agent, Task } from "@crewai/typescript";
const agent = new Agent({
name: "SupportAgent",
role: "Customer support",
goal: "Answer user questions",
});
const task = new Task({
description: "Summarize the ticket",
agent,
});
const crew = new Crew({
agents: [agent],
tasks: [task],
});
// ❌ Promise not awaited
crew.kickoff();
console.log("Deployment started");
process.exit(0);
And here’s the fixed pattern:
// fixed.ts
import { Crew, Agent, Task } from "@crewai/typescript";
async function main() {
const agent = new Agent({
name: "SupportAgent",
role: "Customer support",
goal: "Answer user questions",
});
const task = new Task({
description: "Summarize the ticket",
agent,
});
const crew = new Crew({
agents: [agent],
tasks: [task],
});
const result = await crew.kickoff();
console.log("Crew result:", result);
}
main().catch((err) => {
console.error("CrewAI deployment crash:", err);
process.exit(1);
});
If you see errors like:
- •
UnhandledPromiseRejectionWarning - •
Error: Crew kickoff failed - •
TypeError: Cannot read properties of undefined - •
Process exited with code 0 before task completion
this is the first place to look.
Other Possible Causes
1. Missing environment variables in production
Local .env files often mask this. In production, OPENAI_API_KEY, CREWAI_API_KEY, or model-specific variables may be absent.
// bad
const apiKey = process.env.OPENAI_API_KEY!;
// good
const apiKey = process.env.OPENAI_API_KEY;
if (!apiKey) {
throw new Error("Missing OPENAI_API_KEY");
}
If you’re deploying to Docker or Vercel, confirm the variable exists in the runtime environment, not just your build step.
2. Tool function throws during initialization
A common failure is creating tools that access files, databases, or network resources at module load time.
// bad
import { DatabaseTool } from "./tools";
const tool = new DatabaseTool(process.env.DB_URL!); // crashes if DB_URL missing
// good
function createTools() {
const dbUrl = process.env.DB_URL;
if (!dbUrl) throw new Error("Missing DB_URL");
return [new DatabaseTool(dbUrl)];
}
CrewAI agents should be constructed with safe initialization. Don’t connect to external systems until you know config is valid.
3. Model/provider mismatch
You can get production crashes when the model name works in one environment but not another. For example, a local dev model may not exist in prod.
// bad
model: "gpt-4o-mini-dev"
// good
model: process.env.CREW_MODEL ?? "gpt-4o-mini"
Watch for provider-specific errors like:
- •
Model not found - •
401 Unauthorized - •
403 Forbidden - •
Invalid API key provided
4. Serverless timeout or memory limit
Crew workflows can exceed serverless limits even if they work locally.
{
"functions": {
"api/index.ts": {
"maxDuration": 10
}
}
}
If your crew does multi-step reasoning, tool calls, or retries, a short timeout will kill it mid-run. In logs this often looks like:
- •
Function timed out - •
Runtime exited unexpectedly - •
Container killed due to memory limit
How to Debug It
- •
Check whether it fails at startup or during kickoff
- •If it crashes before any request reaches your handler, inspect imports and env loading.
- •If it crashes after
kickoff(), inspect agent/task/tool execution.
- •
Log every required config value early
console.log({ OPENAI_API_KEY: !!process.env.OPENAI_API_KEY, DB_URL: !!process.env.DB_URL, CREW_MODEL: process.env.CREW_MODEL, });If one of these is false in production but true locally, you found your issue.
- •
Wrap crew execution in a top-level try/catch
try { const result = await crew.kickoff(); console.log(result); } catch (err) { console.error("Crew kickoff failed:", err); throw err; }This gives you the real stack trace instead of a generic deployment failure.
- •
Run the same build artifact locally
- •Use Docker or your production Node version.
- •Don’t debug against
npm run devonly. - •If possible, reproduce with:
- •same Node version
- •same env vars
- •same command entrypoint
Prevention
- •Initialize agents and tools inside functions, not at module scope.
- •Fail fast on missing env vars before calling
crew.kickoff(). - •Keep production crews idempotent and bounded:
- •set explicit timeouts where supported
- •avoid unbounded retries
- •keep tool calls deterministic where possible
If you want stable deployments with CrewAI TypeScript, treat it like any other production workflow engine: validate config early, await everything explicitly, and never assume local behavior matches runtime behavior.
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