One agent is asked to write the memo, then check its own dates. Let's save this as demo.py:
demo.py
1# demo.py2from crewai import Agent
3from crewai.flow.flow import Flow, listen, start
4from dotenv import load_dotenv
5from pydantic import BaseModel, ConfigDict
67load_dotenv()8910classDeskState(BaseModel):11 model_config = ConfigDict(validate_assignment=True)1213 text:str=""14 memo:str=""151617classDesk(Flow[DeskState]):18 suppress_flow_events =True1920@start()21defread_document(self):22withopen("inbox/acme-saas-agreement.md")asfile:23 self.state.text =file.read()2425@listen(read_document)26defreview_contract(self):27 writer = Agent(28 role="Contract analyst",29 goal="Tell a manager what could cost them money",30 backstory="You read contracts for a small company.",31)32 answer = writer.kickoff(33"Write a memo of at most 60 words about the risks in this contract. "34"Give the last day to send notice that stops the renewal, as a full date. "35"Then check every date in your memo against the contract.\n\n"+ self.state.text
36)37 self.state.memo = answer.raw
383940desk = Desk()41desk.kickoff()42print(desk.state.memo)
Terminal
1(env)$ python demo.py
Output
...MEMO:Risks: Automatic renewal could obligate a new 12-month term and higher fees (up to 7%). Fees are non-refundable except for breach. Service credits must be requested within 15 days of month-end. Notice to stop renewal must be sent by December 31, 2026, to avoid renewal. All dates have been checked against the contract.
CrewAI draws a box as the agent starts and ends, and ... stands for it. Your agent's words will differ. The memo says its dates were checked, but you only have its word for it:
Drawing diagram…
InputAgentResultOne answer, one agent
The check happened inside the same answer, by the agent that wrote the date. Nothing shows what it checked, or whether it did.
A Task gives each agent its own job, and a Crew runs the tasks in order. The check task sees the draft, because a task sees the tasks before it. Change the import in demo.py:
Python
1from crewai import Agent, Crew, Task
Change review_contract in demo.py:
Python
1@listen(read_document)2defreview_contract(self):3 writer = Agent(4 role="Contract analyst",5 goal="Tell a manager what could cost them money",6 backstory="You read contracts for a small company.",7)8 checker = Agent(9 role="Fact checker",10 goal="Make every date and number match the contract",11 backstory="You check memos against their sources.",12)13 draft = Task(14 description="Write a memo of at most 60 words about the risks in this contract. "15"Give the last day to send notice that stops the renewal, as a full date.\n\n{text}",16 expected_output="A short memo",17 agent=writer,18)19 check = Task(20 description="Work out every date in the memo again from this contract, and correct the memo:\n\n{text}",21 expected_output="The corrected memo, and nothing else",22 agent=checker,23)24 crew = Crew(agents=[writer, checker], tasks=[draft, check])25 result = crew.kickoff(inputs={"text": self.state.text})26print("draft:", draft.output.raw)27 self.state.memo = result.raw
Terminal
1(env)$ python demo.py
Output
draft: MEMO: Risks in Software Subscription Agreement- Annual fee ($18,000) auto-renews unless you give written non-renewal notice at least 60 days before term ends—last day to send notice is January 1, 2027....MEMO: Risks in Software Subscription Agreement- Annual fee ($18,000) auto-renews unless you give written non-renewal notice at least 60 days before term ends—last day to send notice is January 30, 2027....
... stands for lines that didn't change. draft.output.raw is what the writer handed on, and the memo is the checker's. The draft named January 1, 2027, and the checker changed it to January 30:
Drawing diagram…
InputAgentResultThe crew inside review_contract
Now each job has its own agent, and you can see what each one handed on.
Neither memo said December 30. Way 1 was a day late. In Way 2, the checker moved the draft's wrong date a month further away:
Drawing diagram…
AgentToolResultThree dates, one right answer
The checker reads well and sounds sure, like the writer. Both are guessing at a sum Python does exactly. Your run's dates may differ, but in our runs neither agent named December 30.
Let's remove the program. The folder, .env and the inbox stay for the next chapter.