Human in the loop for the Vercel AI SDK.
Add human approval to any AI SDK agent as a tool. The model calls askHumans when a decision needs a person, and the tool returns the consensus of ID verified people with plain guidance on whether to act.
npm install ai zod pluresHow it works
- 1
Define the tool
Describe when to use it, and take a question, two to eight options and the context to judge.
- 2
Call verify
plures.verify sends the task and waits up to the timeout. Test keys answer at once.
- 3
Return guidance, not just a label
Tell the model whether the answer is unanimous and safe to act on, or should go to a person.
The code
Runs as is with a free pk_test_ key, which answers instantly without reaching people.
import { generateText, stepCountIs, tool } from "ai";
import { z } from "zod";
import { Plures } from "plures";
const plures = new Plures(); // reads PLURES_API_KEY
export const askHumans = tool({
description:
"Ask ID verified people to decide a judgment call before acting on it, such as a customer's tone, " +
"a refund, or whether two documents match. Returns their answer and how strongly they agreed.",
inputSchema: z.object({
question: z.string().describe("What people should decide, answerable from the context alone"),
options: z.array(z.string()).min(2).max(8),
context: z.string().describe("The material to judge, as plain text"),
}),
execute: async ({ question, options, context }) => {
const task = await plures.verify({ question, options, context, verifiers: 3 }, { timeoutMs: 5 * 60_000 });
const r = task.result;
return {
status: task.status,
answer: r?.label ?? null,
agreement: r?.agreement ?? 0,
guidance: r?.answer != null && r.agreement >= 1 ? "Unanimous: safe to act on." : "Not unanimous: escalate to a person.",
};
},
});
const { text } = await generateText({ model, tools: { askHumans }, stopWhen: stepCountIs(5), prompt });In a serverless route, create the task with a webhook_url instead of waiting, and continue when Plures posts task.completed. Plures.verifyWebhook checks the signature for you.
What your agent gets back
The answer, how strongly people agreed from 0 to 1, and each vote. Act on a unanimous answer; send anything less to your team.
{
"status": "completed",
"result": {
"answer": "Yes",
"label": "Yes",
"agreement": 1,
"answers": 3,
"votes": { "Yes": 3, "No": 0 }
}
}Questions
Does it work with streamText and the useChat hook?
Yes. It's an ordinary tool, so it works anywhere the AI SDK accepts tools.
Will a serverless function time out while it waits?
It can, if people take longer than the function's limit. Send the task with a webhook_url and finish the work in the webhook handler instead.
How do I start?
Get a free API key at plures.si. Test keys (pk_test_) answer instantly without reaching people, so you can build the whole flow first. Then send your own team up to 50 decisions a month for free, and add credit when you want ID verified people on the rest.
Other integrations
Product names and logos are trademarks of their owners, shown only to name the tools these pages are about.