crewAI
crewAI copied to clipboard
Flow: persists across calls — no automatic reset
Description
In Flow, retry_count accumulates across multiple kickoff() calls. If the state has retry_count: int = 0 and max_retries: int = 3, after one full run (3 attempts) the counter is 3. A second kickoff() call starts from 3, immediately hitting max_retries escalation on the first task.
Steps to reproduce
@persist(...)
class TestFlow(Flow[TestState]):
@start()
def start(self):
pass
@listen("builder")
def builder_plan(self):
# retry_count is already 3 from previous run
pass
@router(builder_code)
def builder_verify(self, code_output):
self.state.retry_count += 1
if self.state.retry_count >= self.state.max_retries:
return "escalated"
return "needs_revision"
- Run flow once → retry_count = 3 after max retries
- Call
flow.kickoff()again → retry_count starts at 3 → immediately escalated
Expected
retry_count should reset to 0 when a flow run starts, or at least when kickoff() is called. Same applies to any counter field used for per-run tracking.
Workaround
Manually reset counters in @start() method:
@start()
def start(self):
self.state.retry_count = 0
Environment
- CrewAI: 1.15.5
- Python: 3.11
Closed — intended behavior. Flow state persists across kickoff() calls by design.