@human_feedback goes under @listen. When write_report finishes, CrewAI prints its result and waits for an answer. file_report reads it from self.last_human_feedback.feedback. Add the import to demo.py:
Python
1from crewai.flow import human_feedback
Change write_report and file_report in demo.py:
Python
1@listen(check_memo)2@human_feedback(message="Type approve to file this report, or press Enter to hold it.")3defwrite_report(self):4 self.state.report ="acme-saas-agreement.md: "+ self.state.finding
5return self.state.report
67@listen(write_report)8deffile_report(self):9 answer = self.last_human_feedback.feedback.strip().lower()10 folder = Path("filed"if answer =="approve"else"held")11 folder.mkdir(exist_ok=True)12 place = folder /"acme-saas-agreement.md"13 place.write_text(self.state.report)14returnstr(place)
Run it, and type approve at the prompt. echo approve | below types it for you:
Terminal
1(env)$ echo approve | python demo.py
Output
══════════════════════════════════════════════════ OUTPUT FOR REVIEW══════════════════════════════════════════════════acme-saas-agreement.md: Notice is due by December 30, 2026, and the memo doesn'tsay so.══════════════════════════════════════════════════Type approve to file this report, or press Enter to hold it.(Press Enter to skip, or type your feedback)Your feedback: filed/acme-saas-agreement.md
CrewAI showed the report in a box, printed the message, and waited at Your feedback:. When you type approve yourself, you see it after Your feedback:. Piped in, it isn't shown, so the path follows straight on. The answer reached file_report, which picked filed:
Drawing diagram…
InputToolResultThe answer picks the folder
Now run it again, and press Enter without typing anything:
Terminal
1(env)$ echo| python demo.py
Output
══════════════════════════════════════════════════ OUTPUT FOR REVIEW══════════════════════════════════════════════════acme-saas-agreement.md: Notice is due by December 30, 2026, and the memo doesn'tsay so.══════════════════════════════════════════════════Type approve to file this report, or press Enter to hold it.(Press Enter to skip, or type your feedback)Your feedback: held/acme-saas-agreement.md
Pressing Enter gives an empty answer, which isn't approve, so the report went to held, where a person can read it later.
Let's type yes, which a person might well mean as approval:
Terminal
1(env)$ echoyes| python demo.py
Output
══════════════════════════════════════════════════ OUTPUT FOR REVIEW══════════════════════════════════════════════════acme-saas-agreement.md: Notice is due by December 30, 2026, and the memo doesn'tsay so.══════════════════════════════════════════════════Type approve to file this report, or press Enter to hold it.(Press Enter to skip, or type your feedback)Your feedback: held/acme-saas-agreement.md
The person meant yes, and the report was held. file_report files only when the answer is the word approve, in any capitals, and yes isn't it:
Drawing diagram…
InputToolResultOnly one word files the report
That's the safe side to fail on. A report held by mistake costs a person one more look, while one filed by mistake has already gone. The message tells the person the one word to type.
Let's remove the program and the two folders. .env and the inbox stay for the next chapter.