read_terms waits for read_invoice, and the check waits for read_terms, so the check runs after both. time.sleep(1) stands in for a reading that takes one second, and the check reports how long the run took. Let's save this as demo.py:
demo.py
1# demo.py2import time
34from crewai.flow.flow import Flow, listen, start
5from pydantic import BaseModel, ConfigDict
678classDeskState(BaseModel):9 model_config = ConfigDict(validate_assignment=True)1011 began:float=0.012 amount:int=013 price:int=0141516classDesk(Flow[DeskState]):17 suppress_flow_events =True1819@start()20defread_document(self):21 self.state.began = time.time()2223@listen(read_document)24defread_invoice(self):25 time.sleep(1)26 self.state.amount =192602728@listen(read_invoice)29defread_terms(self):30 time.sleep(1)31 self.state.price =180003233@listen(read_terms)34defcheck_invoice(self):35 seconds =round(time.time()- self.state.began)36 over = self.state.amount - self.state.price
37returnf"the invoice is {over} over the contract ({seconds} s)"383940print(Desk().kickoff())
Terminal
1(env)$ python demo.py
Output
the invoice is 1260 over the contract (2 s)
The check is right, but read_terms waited a second for read_invoice, though it needs nothing from it: