crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

Flow: persists across calls — no automatic reset

Open akrhin opened this issue 4 months ago • 1 comments

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"
  1. Run flow once → retry_count = 3 after max retries
  2. 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

akrhin avatar Jul 25 '26 00:07 akrhin

Closed — intended behavior. Flow state persists across kickoff() calls by design.

akrhin avatar Jul 25 '26 00:07 akrhin