AIhero

    unlisted workshop

    Human-in-the-Loop Skill Building

    Matt Pocock
    Matt Pocock
    Human-in-the-Loop Skill Building

    Your AI agent just sent an email to your entire company. It seemed helpful at the time, you asked to "send a quick update to the team," but now HR is involved and you're explaining why an LLM had unsupervised access to your email system.

    This is the core tension with agentic AI: the more capable your agent becomes, the more dangerous it is to let it act autonomously. Real-world tools have real-world consequences. Sending emails, booking flights, modifying databases, these actions can't be undone with a simple "regenerate response."

    The solution is human-in-the-loop: instead of executing sensitive tools immediately, the agent pauses and asks for approval first. The user sees exactly what's about to happen, decides whether to proceed, and can provide feedback if the agent got it wrong. This pattern is essential for any AI system that interacts with the real world.

    In this workshop, you'll build a complete human-in-the-loop system from scratch using AI SDK's custom data parts. While AI SDK v6 adds built-in approval flows, building it yourself teaches you how powerful custom data parts are as an abstraction AND once you've done this, you can build almost anything.

    You will:

    • Replace direct tool execution with approval requests
    • Configure stopWhen with hasToolCall() to pause the agent after requesting approval
    • Build the frontend approval flow, tracking which tools have pending decisions and collecting feedback when users reject requests
    • Convert custom data parts into LLM-readable text using convertDataPart in convertToModelMessages(), so the model understands what was requested, approved, or rejected
    • Validate incoming messages to ensure users can't bypass approval
    • Execute approved tools and write results back to both the stream and message history
    • Handle rejection feedback, allowing users to explain why they rejected a request so the agent can try a different approach

    By the end of this workshop, you'll have a production-ready approval system where users control what your agent actually does in the world. More importantly, you'll understand custom data parts as a bidirectional messaging system between frontend and backend which is a pattern you can extend to follow-up suggestions, custom UI rendering, or any interaction your application needs.

    Human-in-the-Loop Skill Building

    Matt Pocock
    Matt Pocock