ai 5.0.266, @openai/agents 0.18.0 and zod
4.6.5 on Node 24. The OpenAI Agents SDK requires zod 4; the AI SDK accepts
3.25 or 4, so use 4 for both.
The function
Framework-neutral: a task in, a result out. Three behaviours worth having are built in.
The question check reads the session, not the turn: while a question is
pending the turn still reports
working, and the session reports
requires_action. A loop that watched the turn alone would never return.
Vercel AI SDK
OpenAI Agents SDK
session_id is nullable() rather than optional() here: the Agents SDK
sends tool schemas to OpenAI in strict mode, where every property must be
present and absence is spelled null.
Cleaning up
These tools do not delete their sessions, because the next call may continue on them. Delete them when the conversation ends — or, for a request-scoped agent, in afinally after the framework’s run returns:
What was verified
Run against production. The outer model was the AI SDK’s ownMockLanguageModelV2 — a scripted stand-in that emits a real tool call — so the
framework’s tool loop ran for real and only the model’s choice was fixed:
- A computed answer, checked independently. The tool was asked for the
SHA-256 of the string
gobare, written to/workspace/outputs/hash.txt. The digest in the tool result matched one computed locally, andfileslisted/workspace/outputs/hash.txt. The AI SDK recorded two steps: the tool call, then the answer. - Continuation. The OpenAI Agents SDK tool, invoked with the previous
session_id, printed the same file back — same computer, file intact. - A question passed up and answered. Asked to check with the caller
before choosing csv or json, the inner agent’s call returned
status: "waiting"with its question; calling again withjsonand the samesession_idcompleted with/workspace/outputs/data.json.
Next
- sessions — what else a session can be given at creation
- required actions — questions, approvals and function calls
- Put an agent behind your own API — the same idea without a framework