The memo below is wrong, but it argues for its date. It counts the term to March 1, 2027, a day too far. A checker agent reads the memo and the contract, and gives a typed answer. 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, Field
67load_dotenv()89MEMO =(10"Risk: the contract renews on its own for another 12 months. "11"The term ends on March 1, 2027, the anniversary of the Effective Date, "12"so under Section 2.2 notice is due 60 days before that: by December 31, 2026."13)141516classVerdict(BaseModel):17 right:bool= Field(description="Is the notice deadline in the memo right?")18 reason:str192021classDeskState(BaseModel):22 model_config = ConfigDict(validate_assignment=True)2324 text:str=""25 memo:str=""262728classDesk(Flow[DeskState]):29 suppress_flow_events =True3031@start()32defread_document(self):33withopen("inbox/acme-saas-agreement.md")asfile:34 self.state.text =file.read()35 self.state.memo = MEMO
3637@listen(read_document)38defcheck_memo(self):39 checker = Agent(40 role="Fact checker",41 goal="Make every date and number match the contract",42 backstory="You check memos against their sources.",43)44 answer = checker.kickoff(45"Is the notice deadline in this memo right?\n\n"46"Memo: "+ self.state.memo +"\n\nContract:\n"+ self.state.text,47 response_format=Verdict,48)49return answer.pydantic
505152print(Desk().kickoff())
Terminal
1(env)$ python demo.py
Output
...right=True reason="Section 2.2 states the agreement renews automatically at the end of each 12-month term unless notice is given at least 60 days before the end of the then-current term. The Effective Date is March 1, 2026, so the first term ends on March 1, 2027. Sixty days before March 1, 2027 is December 31, 2026. The memo's deadline matches the contract."
... stands for the boxes CrewAI draws. Your agent's words will differ. The checker followed the memo's own sum, and called the wrong date right:
Drawing diagram…
InputAgentResultThe memo's argument wins
The memo gave a reason, and the agent took it. In our five runs before this one, it said right=True every time.
The term starts on March 1, 2026, and lasts 12 months, so its last day is February 28, 2027. timedelta(days=60) counts 60 days back from there. Add the import to demo.py:
Python
1from datetime import date, timedelta
Change check_memo in demo.py:
Python
1@listen(read_document)2defcheck_memo(self):3 deadline = date(2027,2,28)- timedelta(days=60)4 written =f"{deadline:%B}{deadline.day}, {deadline.year}"5if written in self.state.memo:6return"the memo has the deadline"7returnf"Notice is due by {written}, and the memo doesn't say so."
Terminal
1(env)$ python demo.py
Output
Notice is due by December 30, 2026, and the memo doesn't say so.
The same sum runs every time, so the memo's argument never reaches it:
Drawing diagram…
InputToolResultThe check works the date out itself
Let's fix the memo, and write the date the way much of the world does. Change MEMO in demo.py:
Python
1MEMO ="Risk: the contract renews on its own for another 12 months. Send notice by 30 December 2026."
Terminal
1(env)$ python demo.py
Output
Notice is due by December 30, 2026, and the memo doesn't say so.
The memo is right now, and the check still reports it. The check only looks for December 30, 2026, letter for letter:
Drawing diagram…
InputToolResultThe right date, not found
Let's look for each way the date is likely written: 30 December 2026, and 2026-12-30, which is what str(deadline) gives.
Change check_memo in demo.py:
Python
1@listen(read_document)2defcheck_memo(self):3 deadline = date(2027,2,28)- timedelta(days=60)4 written =f"{deadline:%B}{deadline.day}, {deadline.year}"5 forms =[written,f"{deadline.day}{deadline:%B %Y}",str(deadline)]6ifany(form in self.state.memo for form in forms):7return"the memo has the deadline"8returnf"Notice is due by {written}, and the memo doesn't say so."
Terminal
1(env)$ python demo.py
Output
the memo has the deadline
Let's remove the program. The folder, .env and the inbox stay for the next chapter.