How i can execute tool on client side? #3882
Zain-ul-din
started this conversation in
General
Replies: 1 comment 1 reply
|
The issue is that you have two pauses stacked on one tool.
The Fix: drop the approval. export default defineWorkflowTool({
description: "Returns map polygons and bounds in feet",
inputSchema: z.object({}),
async execute(_, ctx) {
"use workflow";
const answer = await ctx.ask({ prompt: "map-state", allowFreeform: true });
return answer.status === "answered" ? answer.text : "Map state unavailable";
},
});On the client, answer based on state instead of lifecycle callbacks: const answered = useRef(new Set<string>());
useEffect(() => {
if (agent.status !== "ready") return;
for (const part of agent.data.messages.flatMap((m) => m.parts)) {
if (part.type !== "dynamic-tool" || part.state !== "approval-requested") continue;
const req = part.toolMetadata?.eve?.inputRequest;
if (!req || req.kind !== "question" || part.toolName !== "get-map-state") continue;
if (answered.current.has(req.requestId)) continue;
answered.current.add(req.requestId);
void agent.respond([{ requestId: req.requestId, text: JSON.stringify({ polygons }) }]);
}
}, [agent.data.messages, agent.status]);Notes:
|
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Even though this is a simple requirement, but i'm trying so hard for the last 3 hours to figure out how to execute the tool on the client side. I know there is a workaround using listening to events like
onFinishandonEvent. Both seem not to be working for me.Here is my code:
Things I have tried:
onEvent: always returns an error due to a race condition (turn is already in process; set turnPolicy: "steer") i tried setting it but i'm still getting the error.onFinish: this is indeed sending the tool response back but after that agents got stuck, no response back.Things i don't want:
All reactions