Skip to content
/

Ask a person first

Ready for real workChapter 12 of 155 min read

The desk finds what's wrong, then files the report with no one looking, so this chapter answers: how does the flow ask a person before it acts?


The flow shows the report, waits for an answer, and lets the answer pick the folder:

Drawing diagram…
InputToolResultA person between the report and the folder
  • @human_feedback: shows a step's result to a person, and waits for them to type an answer.
  • self.last_human_feedback: what the person typed, for the next step to read.

Set up#

If you closed the terminal, go back into the folder and switch the environment on:

Terminal
$ cd document-desk
$ source env/bin/activate

This chapter needs no model: the finding is written in, as chapter 10 found it.

Way 1: file it straight away#

file_report writes the report into a folder called filed. Let's save this as demo.py:

demo.py
# demo.py
from pathlib import Path

from crewai.flow.flow import Flow, listen, start
from pydantic import BaseModel, ConfigDict


class DeskState(BaseModel):
    model_config = ConfigDict(validate_assignment=True)

    finding: str = ""
    report: str = ""


class Desk(Flow[DeskState]):
    suppress_flow_events = True

    @start()
    def check_memo(self):
        self.state.finding = "Notice is due by December 30, 2026, and the memo doesn't say so."

    @listen(check_memo)
    def write_report(self):
        self.state.report = "acme-saas-agreement.md: " + self.state.finding
        return self.state.report

    @listen(write_report)
    def file_report(self):
        folder = Path("filed")
        folder.mkdir(exist_ok=True)
        place = folder / "acme-saas-agreement.md"
        place.write_text(self.state.report)
        return str(place)


print(Desk().kickoff())
Terminal
(env)$ python demo.py
Output
filed/acme-saas-agreement.md

The report went into filed straight away. Nobody read it first, and a report filed by mistake is hard to take back:

Drawing diagram…
ToolResultNobody looks before it's filed

Way 2: wait for a person#

@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
from crewai.flow import human_feedback

Change write_report and file_report in demo.py:

Python
    @listen(check_memo)
    @human_feedback(message="Type approve to file this report, or press Enter to hold it.")
    def write_report(self):
        self.state.report = "acme-saas-agreement.md: " + self.state.finding
        return self.state.report

    @listen(write_report)
    def file_report(self):
        answer = self.last_human_feedback.feedback.strip().lower()
        folder = Path("filed" if answer == "approve" else "held")
        folder.mkdir(exist_ok=True)
        place = folder / "acme-saas-agreement.md"
        place.write_text(self.state.report)
        return str(place)

Run it, and type approve at the prompt. echo approve | below types it for you:

Terminal
(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
(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.

An answer it doesn't know#

Let's type yes, which a person might well mean as approval:

Terminal
(env)$ echo yes | 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.

Terminal
(env)$ rm demo.py
(env)$ rm -r filed held

The two ways side by side#

Compare what happens before the report is filed:

Drawing diagram…
InputResultBefore the report is filed

When a step does something that's hard to undo, put @human_feedback on the step before it, and let only a clear yes go ahead.

Drawing diagram…
InputResultAsk a person first?

What comes next#

While the flow waits for an answer, it's only a program sitting at a prompt:

Drawing diagram…
InputToolResultWaiting at the prompt

The program stops while it waits. What's lost?