How to Fix 'chain execution stuck' in CrewAI (Python)
What “chain execution stuck” usually means
In CrewAI, chain execution stuck usually means the agent/task pipeline is waiting on something that never completes. In practice, it shows up when a task can’t advance because of a bad tool call, a deadlock in delegation, an invalid LLM response format, or a loop that keeps re-triggering the same step.
You’ll typically see it when running multi-agent crews with tools, memory, or delegation enabled. The symptom is the same: the process hangs, no useful output arrives, and the run never reaches CrewOutput.
The Most Common Cause — infinite tool/agent loop
The #1 cause I see is a task definition that lets the agent keep delegating or retrying without a hard stop. In CrewAI, this often happens when allow_delegation=True is enabled for an agent that also has vague instructions or a tool that returns incomplete data.
Here’s the broken pattern:
| Broken | Fixed |
|---|---|
| Agent can delegate endlessly | Agent has a bounded role and explicit output |
| Task has no strict completion criteria | Task requires a final answer format |
| Tool returns free-form text | Tool returns structured data |
# BROKEN
from crewai import Agent, Task, Crew, Process
from crewai_tools import SerperDevTool
search_tool = SerperDevTool()
researcher = Agent(
role="Researcher",
goal="Find information",
backstory="You research everything.",
tools=[search_tool],
allow_delegation=True,
verbose=True,
)
task = Task(
description="Research CrewAI errors and figure out what's wrong.",
expected_output="Useful findings",
agent=researcher,
)
crew = Crew(
agents=[researcher],
tasks=[task],
process=Process.sequential,
verbose=True,
)
crew.kickoff()
# FIXED
from crewai import Agent, Task, Crew, Process
from crewai_tools import SerperDevTool
search_tool = SerperDevTool()
researcher = Agent(
role="Researcher",
goal="Identify the root cause of CrewAI runtime errors",
backstory="You produce concise debugging notes with evidence.",
tools=[search_tool],
allow_delegation=False,
verbose=True,
)
task = Task(
description=(
"Diagnose the cause of the failure.\n"
"Return:\n"
"1. likely root cause\n"
"2. evidence from logs\n"
"3. exact fix\n"
"4. one-line validation step"
),
expected_output="A concise diagnostic report in bullet points.",
agent=researcher,
)
crew = Crew(
agents=[researcher],
tasks=[task],
process=Process.sequential,
verbose=True,
)
result = crew.kickoff()
print(result)
If you’re seeing repeated tool calls or logs like AgentExecutor cycling without progress, this is usually where to look first.
Other Possible Causes
1) Invalid LLM response format
CrewAI can stall if the model keeps returning malformed output instead of the expected structured response. This is common when using function-calling models with mismatched schema expectations.
# Problematic: model may return plain text when structured output is expected
llm_config = {
"model": "gpt-4o-mini",
"temperature": 0.7,
}
Fix by tightening instructions and lowering ambiguity:
task = Task(
description="Return only valid JSON with keys: root_cause, fix, validation",
expected_output='{"root_cause": "...", "fix": "...", "validation": "..."}',
agent=researcher,
)
2) A tool hangs or never returns
If you wrapped your own Python tool and it blocks on network I/O or waits forever, CrewAI will look stuck even though the agent is fine.
from crewai.tools import BaseTool
class MyTool(BaseTool):
name: str = "my_tool"
description: str = "Calls internal API"
def _run(self, query: str) -> str:
# BAD: no timeout on requests.get()
response = requests.get("https://internal-api.local/search")
return response.text
Use timeouts and fail fast:
def _run(self, query: str) -> str:
response = requests.get(
"https://internal-api.local/search",
params={"q": query},
timeout=10,
)
response.raise_for_status()
return response.text
3) Recursive delegation between agents
Two agents delegating to each other can create a deadlock-style loop. This happens when both are allowed to delegate and neither has a hard completion boundary.
analyst = Agent(..., allow_delegation=True)
reviewer = Agent(..., allow_delegation=True)
If one agent should decide and another should review, keep delegation one-way:
analyst = Agent(..., allow_delegation=False)
reviewer = Agent(..., allow_delegation=False)
Then connect them through explicit tasks instead of open-ended delegation.
4) Memory/context grows too large
Long-running crews with memory enabled can bog down when context becomes huge. The run doesn’t always fail loudly; it just appears stuck while tokens explode.
crew = Crew(
agents=[researcher],
tasks=[task],
memory=True,
)
If you don’t need memory for the run, disable it. If you do need it, trim task outputs and summarize between steps.
How to Debug It
- •
Turn on verbose logging
- •Set
verbose=Trueon bothAgentandCrew. - •Look for repeated lines like tool retries, delegation loops, or identical prompts being reissued.
- •Set
- •
Run one task at a time
- •Remove all but one
Task. - •If the hang disappears, the issue is in task chaining or inter-agent handoff.
- •Remove all but one
- •
Disable tools first
- •Run the same crew with
tools=[]. - •If it completes cleanly, your custom tool or external API call is blocking.
- •Run the same crew with
- •
Remove delegation and memory
- •Set
allow_delegation=False. - •Set
memory=False. - •If that fixes it, add those features back one by one until it breaks again.
- •Set
A useful rule: if you see ChainOfThought-style repetition or repeated “thinking” without final output in logs from Crew, assume either delegation recursion or an unbounded task spec.
Prevention
- •
Keep every task bounded:
- •clear deliverable
- •max one objective per task
- •explicit output format
- •
Treat tools like production services:
- •add timeouts
- •validate inputs
- •handle exceptions cleanly
- •
Avoid open-ended delegation unless you really need it:
- •default to
allow_delegation=False - •use sequential task flow for most business workflows
- •default to
If you want this class of bug to disappear in production crews for banking or insurance workflows, design for determinism first. CrewAI works best when each agent has a narrow job and every step has a visible exit condition.
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