Skip to content

feat(workflow): add hook support#75

Open
fantix wants to merge 7 commits intomainfrom
fantix/workflow-hook
Open

feat(workflow): add hook support#75
fantix wants to merge 7 commits intomainfrom
fantix/workflow-hook

Conversation

@fantix
Copy link
Copy Markdown
Member

@fantix fantix commented Mar 27, 2026

Demo code from docs, workflow:

from vercel.workflow import HookMixin, workflow


# Human approval for AI-generated drafts
class Approval(BaseModel, HookMixin):
    decision: Literal["approved", "changes"]
    notes: str | None


@workflow
async def ai_approval_workflow(topic: str):
    draft = await generate_draft(topic)

    # Wait for human approval events
    events = Approval.wait(token="draft-123")

    async for event in events:
        if event["decision"] == "approved":
            await publish_draft(draft)
            break
        else:
            revised = await refine_draft(draft, event.get("notes"))
            await publish_draft(revised)
            break

App:

@app.post("/api/resume")
async def resume_workflow(approval: Approval):
    await approval.resume("draft-123")

    return {"ok": True}

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
vercel-py Ready Ready Preview Mar 28, 2026 3:38am

Request Review

@fantix fantix marked this pull request as ready for review March 28, 2026 03:42
@fantix fantix requested a review from a team March 28, 2026 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant