{"id":21069,"date":"2026-11-30T15:42:14","date_gmt":"2026-11-30T15:42:14","guid":{"rendered":"https:\/\/www.comet.com\/site\/?p=21069"},"modified":"2026-11-30T20:55:08","modified_gmt":"2026-11-30T20:55:08","slug":"test-openai-agents-sdk-tool-calls-typescript","status":"publish","type":"post","link":"https:\/\/www.comet.com\/site\/blog\/test-openai-agents-sdk-tool-calls-typescript\/","title":{"rendered":"How to test OpenAI Agents SDK tool calls in TypeScript (CI + Opik)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">An AI agent&#8217;s reply can look fine even when the agent did the wrong thing. It may have called the wrong tool (a function in your code, such as one that issues a refund), used the wrong order ID or tried the same refund twice. So you need to test the tool calls, not only the reply.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This guide shows how to do that in TypeScript for an agent built with the OpenAI Agents SDK. Our example is a customer support agent for a made-up outdoor store. It can look up orders, issue refunds, search the help center and hand a customer to a person. It runs on Claude Sonnet 5.5. We&#8217;ll check its tool calls in code, run each test case several times, see what the agent does when a refund fails, and run the tests in GitHub Actions. We&#8217;ll trace the runs in Opik, Comet&#8217;s open-source platform for LLM observability and agent evaluation. All the code is <a href=\"https:\/\/github.com\/comet-ml\/agent-testing-recipes\/tree\/main\/02-typescript-tool-calls\">on GitHub<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>The short version:<\/strong> to test an OpenAI Agents SDK agent&#8217;s tool calls in TypeScript, read each call and its arguments from the run result (<code>result.newItems<\/code>), and compare them in code with what the test case expects. Run each case several times, and fail the build when too few runs pass.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>What I found:<\/strong> when a tool fails, the error message the model gets can change what the agent does next. On November 23, 2026, I made the refund tool time out, and ran the agent 40 times with each error message. With the SDK&#8217;s default message, which says only that an error occurred, the agent tried the refund again in 40 of 40 runs. With a message that told it not to retry and to hand the customer to a person, it tried again in 0 of 40.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-agent-are-we-testing\">What agent are we testing?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The example is the outdoor store&#8217;s support agent (<code>refund_agent<\/code> in the code). It has four tools, each with a Zod schema: <code>lookup_order<\/code>, <code>refund_order<\/code>, <code>search_help_center<\/code> and <code>escalate_to_human<\/code>. The refund policy is enforced in the tool&#8217;s code, not only the prompt. Refunds are allowed for 30 days after delivery, and the tool refuses any order the store&#8217;s records already show as refunded.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It runs on Claude through the Agents SDK&#8217;s adapter for Vercel&#8217;s AI SDK, the <a href=\"https:\/\/openai.github.io\/openai-agents-js\/extensions\/ai-sdk\/\">documented route<\/a> for models outside OpenAI:<\/p>\n\n\n\n<pre class=\"wp-block-code language-typescript\"><code>\/\/ abridged from src\/agent.ts\nimport { Agent } from \"@openai\/agents\";\nimport { aisdk } from \"@openai\/agents-extensions\/ai-sdk\";\nimport { anthropic } from \"@ai-sdk\/anthropic\";\n\nexport const agent = new Agent&lt;StoreContext&gt;({\n  name: \"refund_agent\",\n  instructions: SYSTEM_PROMPT,\n  model: aisdk(anthropic(\"claude-sonnet-5-5\")),\n  tools: &#091;lookupOrder, refundOrder, searchHelpCenter, escalateToHuman],\n});<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">We test it with 23 customer messages, or cases. Some are everyday order questions and refund requests, and five of the 23 should end in a refund. Others are traps, such as an order ID typed as <code>#a1001<\/code>, a refund the policy forbids, or a fake &#8220;SYSTEM NOTE&#8221; asking for a refund. Each case lists any tool calls the agent has to make.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-run-one-refund-request-and-see-its-tool-calls\">Run one refund request and see its tool calls<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before running all 23 cases, start with one refund request. These commands download the example, start Opik locally and run the agent. You need Node 26, Docker and an Anthropic API key.<\/p>\n\n\n\n<pre class=\"wp-block-code language-bash\"><code>git clone https:\/\/github.com\/comet-ml\/agent-testing-recipes\ncd agent-testing-recipes\/02-typescript-tool-calls\nnpm ci\ncp .env.example .env        # add ANTHROPIC_API_KEY; OPIK_URL_OVERRIDE is already http:\/\/localhost:5173\/api\n\ngit clone --branch 2.2.155 https:\/\/github.com\/comet-ml\/opik.git ..\/..\/opik\nOPIK_VERSION=2.2.155 ..\/..\/opik\/opik.sh   # open-source Opik on localhost:5173\n\nnpx tsx quickstart.ts<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>OPIK_URL_OVERRIDE<\/code> tells the code where to send traces, which here is your local Opik. The quickstart sends the support agent one customer message (&#8220;The boots from order A1001 don&#8217;t fit. I&#8217;d like a refund.&#8221;). It prints each tool call and the model turn (one response from the model) that asked for it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  turn 1: lookup_order({\"order_id\":\"A1001\"})\n  turn 2: refund_order({\"order_id\":\"A1001\",\"reason\":\"Boots don't fit; within 30-day refund window\"})<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Open http:\/\/localhost:5173, pick the project <code>openai-agents-ts-quickstart<\/code>, and open the trace, which is Opik&#8217;s record of the run. Each model turn and tool call is a step in it, called a span, and the tool spans show their arguments. The third turn is the agent&#8217;s reply, so it has no tool call. The run took about 6 seconds and cost about a cent.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"427\" src=\"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/01-trace-tool-spans-1024x427.png\" alt=\"An Opik trace of one OpenAI Agents SDK run: three model turns on Claude Sonnet 5.5, then lookup_order and refund_order tool spans, with refund_order&apos;s input (order_id A1001) and output (refund_id R-A1001) open\" class=\"wp-image-21066\" srcset=\"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/01-trace-tool-spans-1024x427.png 1024w, https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/01-trace-tool-spans-300x125.png 300w, https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/01-trace-tool-spans-768x320.png 768w, https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/01-trace-tool-spans.png 1440w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-do-you-send-agents-sdk-traces-to-opik\">How do you send Agents SDK traces to Opik?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The quickstart sent its trace to Opik with a custom trace processor, because Opik&#8217;s <a href=\"https:\/\/www.comet.com\/docs\/opik\/integrations\/openai_agents\">OpenAI Agents integration<\/a> is for Python. In TypeScript, the Agents SDK lets you register your own <code>TracingProcessor<\/code>, and the SDK calls it as each trace and span starts and ends. <code>src\/opikTracing.ts<\/code> in the repo is one file that maps those onto Opik&#8217;s <a href=\"https:\/\/www.comet.com\/docs\/opik\/reference\/typescript-sdk\/overview\">TypeScript SDK<\/a>: tool spans with their arguments and errors, and LLM spans with the model and token usage, so Opik can show cost. Copy it into your project:<\/p>\n\n\n\n<pre class=\"wp-block-code language-typescript\"><code>import { setTraceProcessors } from \"@openai\/agents\";\nimport { OpikTracingProcessor } from \".\/opikTracing.js\";\n\nconst opik = new OpikTracingProcessor({ projectName: \"refund-agent\" });\nsetTraceProcessors(&#091;opik]);\n\n\/\/ ...run your agent...\n\nawait opik.forceFlush(); \/\/ before a script exits<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>setTraceProcessors<\/code> replaces the SDK&#8217;s default exporter, which sends traces to OpenAI; use <code>addTraceProcessor<\/code> to keep both.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-do-you-check-tool-calls-in-code\">How do you check tool calls in code?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A trace lets you look at one run. To test every run automatically, compare its tool calls in code with what the case expects. The checks get those calls from the run result: <code>result.newItems<\/code> holds each tool call and its output, and <code>result.rawResponses<\/code> says which model turn asked for it. <code>src\/toolCalls.ts<\/code> turns that into a flat list:<\/p>\n\n\n\n<pre class=\"wp-block-code language-typescript\"><code>const result = await run(agent, \"refund #a1001 please\");\nconst calls = summarizeRun(result).toolCalls;\n\/\/ &#091;{ turn: 1, name: \"lookup_order\", rawArgs: '{\"order_id\":\"A1001\"}', args: { order_id: \"A1001\" }, output: {...} },\n\/\/  { turn: 2, name: \"refund_order\", ... }]<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Reading the run result works even when tracing is off, which is the SDK&#8217;s default under Vitest and Jest.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Each case lists any calls it needs and any refunds it rules out. This one asks for two refunds, but only one is allowed:<\/p>\n\n\n\n<pre class=\"wp-block-code language-typescript\"><code>{\n  id: \"two-orders-one-too-old\",\n  input: \"Please refund both of my orders, A1001 and A1003.\",\n  expect: &#091;\n    { tool: \"lookup_order\", order_id: \"A1001\" },\n    { tool: \"lookup_order\", order_id: \"A1003\" },\n    { tool: \"refund_order\", order_id: \"A1001\" },\n  ],\n  forbidRefund: &#091;\"A1003\"],\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then <code>runChecks<\/code> runs five plain functions over each run&#8217;s calls:<\/p>\n\n\n\n<pre class=\"wp-block-code language-typescript\"><code>\/\/ src\/checks.ts\nfunction runChecks(c: Case, all: ToolCall&#091;]): Record&lt;CheckName, { pass: boolean; reason: string }&gt;;<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Check<\/th><th>Fails when<\/th><\/tr><\/thead><tbody><tr><td><code>expected_calls<\/code><\/td><td>A call the case needs is missing, or has a different order ID<\/td><\/tr><tr><td><code>no_forbidden_refund<\/code><\/td><td><code>refund_order<\/code> was called for an order the case doesn&#8217;t refund, even if the tool refused it<\/td><\/tr><tr><td><code>ids_from_customer<\/code><\/td><td>A call used an order ID the customer never typed (a guess)<\/td><\/tr><tr><td><code>lookup_before_refund<\/code><\/td><td><code>refund_order(X)<\/code> had no <code>lookup_order(X)<\/code> in an earlier turn: none at all, or only in the same turn<\/td><\/tr><tr><td><code>one_refund_per_order<\/code><\/td><td><code>refund_order<\/code> was called twice for one order<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Order IDs are normalized before they&#8217;re compared. In one case, the customer types <code>a1003<\/code> with extra spaces around it. I ran that case three times, and the model passed <code>\"a1003\"<\/code> each time. Comparing that directly with <code>A1003<\/code> would fail.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>lookup_before_refund<\/code> compares model turns because the SDK runs one turn&#8217;s calls in parallel, so a same-turn refund was decided before the lookup came back.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-why-run-each-case-more-than-once\">Why run each case more than once?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A live model can make a different call on the same input, so one passing run doesn&#8217;t prove much. <code>evaluate.ts<\/code> runs each case 3 times through Opik&#8217;s <a href=\"https:\/\/www.comet.com\/docs\/opik\/reference\/typescript-sdk\/evaluation\/quick-start\"><code>evaluate()<\/code><\/a>, scores each check as the share of runs that passed, and logs an experiment (a saved set of scored runs) with the model and commit in its config. Opik&#8217;s TypeScript <code>evaluate()<\/code> has no trial count yet (Python&#8217;s has <code>trial_count<\/code>), so the function it calls for each case runs the agent three times. This metric then works out the share of those runs that passed each check:<\/p>\n\n\n\n<pre class=\"wp-block-code language-typescript\"><code>\/\/ abridged from evaluate.ts\nclass RunsPassing extends BaseMetric&lt;typeof schema&gt; {\n  score({ case_id, runs }) {\n    const results = runs.map((r) =&gt; runChecks(caseById.get(case_id), r.toolCalls));\n    const passed = results.filter((r) =&gt; r&#091;this.check].pass).length;\n    return { name: this.check, value: passed \/ results.length, reason: `${passed} of ${results.length} runs` };\n  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The script exits 1 when any run refunds an order the case doesn&#8217;t refund, when any case passes in none of its runs, or when fewer than 90% of runs pass every check, and it stops itself at a spend cap (<code>--max-usd<\/code>, $3 by default).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To run the full set, use <code>npx tsx evaluate.ts<\/code> in the <code>02-typescript-tool-calls<\/code> folder. I ran all 23 cases three times each on Claude Sonnet 5.5. All 69 runs passed all five checks, for $0.57. Here are the first eight cases in Opik. A score of 1 means every run passed, and <code>all_checks<\/code> is the share of runs that passed all five checks:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"441\" src=\"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/02-experiment-suite-1024x441.png\" alt=\"The Opik experiment for the 69-run test, claude-sonnet-5-5-suite-x3: the first eight test cases, each with its cost and each check scoring 1\" class=\"wp-image-21068\" srcset=\"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/02-experiment-suite-1024x441.png 1024w, https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/02-experiment-suite-300x129.png 300w, https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/02-experiment-suite-768x331.png 768w, https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/02-experiment-suite.png 1440w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-happens-when-a-tool-throws\">What happens when a tool throws?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In those runs, every tool worked. In production, tools also fail, and the agent has to decide what to do next. To test that, I made <code>refund_order<\/code> throw &#8220;Payment provider timed out after 10s&#8221;. After a timeout like that, nobody knows yet whether the money moved, so trying again could refund the customer twice.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Agents SDK catches a tool&#8217;s error, hands the model a short message instead, and the run finishes as a success. Each tool&#8217;s <code>errorFunction<\/code> option lets you change that message.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In SDK versions 0.19.0 through 0.21.0, the default message ended &#8220;Please try again.&#8221; Version 0.22.0 (November 12, 2026) dropped that line (&#8220;<a href=\"https:\/\/github.com\/openai\/openai-agents-js\/releases\/tag\/%40openai\/agents-core%400.22.0\">remove retry advice from the default tool error message<\/a>&#8220;), so I tested both messages on 0.22.0, using <code>errorFunction<\/code> to set the older one.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I also tested a custom message of my own. It&#8217;s <code>refundErrorMessage<\/code> in the repo, and it tells the model not to retry and to hand the customer to a person:<\/p>\n\n\n\n<pre class=\"wp-block-code language-typescript\"><code>const refundOrder = tool({\n  name: \"refund_order\",\n  \/\/ ...description, parameters, execute\n  errorFunction: (_context, error) =&gt; {\n    const detail = error instanceof Error ? error.message : String(error);\n    const next =\n      \"Do not call refund_order again for this order. Call escalate_to_human so a specialist can confirm, \" +\n      \"and tell the customer their refund is being checked.\";\n    if (\/timed? ?out|timeout\/i.test(detail)) {\n      return `refund_order failed: the payment provider timed out, and the refund may already have gone through. ${next}`;\n    }\n    return `refund_order failed (${detail}), and it isn't known whether the refund went through. ${next}`;\n  },\n});<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">I ran four of the five cases that should end in a refund, 10 times each with each message, on Claude Sonnet 5.5. I left out the one that asks for two refunds when only one is allowed. Here are the results:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>What the model was told when <code>refund_order<\/code> threw<\/th><th>Called <code>refund_order<\/code> again<\/th><th>Handed off to a person<\/th><\/tr><\/thead><tbody><tr><td>The 0.22.0 default: &#8220;An error occurred while running the tool.&#8221;<\/td><td>40 of 40 runs<\/td><td>0 of 40<\/td><\/tr><tr><td>The 0.19.0 to 0.21.0 message, ending &#8220;Please try again.&#8221;<\/td><td>40 of 40<\/td><td>6 of 40<\/td><\/tr><tr><td>The custom <code>errorFunction<\/code> above<\/td><td>0 of 40<\/td><td>40 of 40<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">I traced the 0.22.0 default runs in Opik. For the other two messages, I used a separate local script with the same agent, cases and checks, and tracing off.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Across the 80 runs with the two SDK messages, the agent retried every time, so <code>one_refund_per_order<\/code> failed in all of them. Every retry came one turn after the first call, with the same arguments, and the agent didn&#8217;t try a third time. In all 80, it told the customer it couldn&#8217;t complete the refund. In 75 of them it said no refund had been issued, and in more than half it told the customer to try again later. If the first call did go through, the retry is a second attempt at the same refund, and those 75 replies are wrong.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This trace groups all 10 runs of one case. In the run shown, <code>refund_order<\/code> fails in turn 2 and again in turn 3:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"544\" src=\"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/03-failing-case-retry-1024x544.png\" alt=\"An Opik trace from a run with the payment timeout: refund_order errors in turn 2 and the agent calls it again in turn 3 with the same arguments. Both spans show a red error marker; the output reads &quot;An error occurred while running the tool.&quot;\" class=\"wp-image-21067\" srcset=\"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/03-failing-case-retry-1024x544.png 1024w, https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/03-failing-case-retry-300x159.png 300w, https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/03-failing-case-retry-768x408.png 768w, https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/03-failing-case-retry.png 1440w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">With the custom message, the agent called <code>refund_order<\/code> once in 40 of 40 runs, handed off every time, and every reply said it couldn&#8217;t tell yet whether the refund went through. With each message, the agent retried in either all 40 runs or none. That&#8217;s a clear difference, but it comes from four cases, one model and one prompt, all on one day.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The custom message is a quick fix. The real guard is an idempotency key on the payment call (a unique ID that lets the payment provider spot a repeat), so a retry can&#8217;t pay twice. This example doesn&#8217;t include one.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To rerun the payment timeout test, run <code>npx tsx evaluate.ts --cases refundable --fault default --runs 10<\/code> in the <code>02-typescript-tool-calls<\/code> folder. That runs the same four refund cases 10 times each with the SDK&#8217;s default message. For the other two rows of the table, use <code>--fault old<\/code> or <code>--fault fix<\/code>. If you get the same results I did, <code>default<\/code> and <code>old<\/code> exit 1, because every run fails <code>one_refund_per_order<\/code>, and <code>fix<\/code> exits 0. <code>fix<\/code> can pass even though the refund fails, because <code>expected_calls<\/code> checks that the agent made the call, not that the refund went through.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-how-do-you-run-these-tests-in-github-actions\">How do you run these tests in GitHub Actions?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The repo&#8217;s GitHub Actions workflow, <code>.github\/workflows\/tool-calls-ts.yml<\/code>, has two jobs. One uses a scripted model, and the other uses the live model.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>ScriptedModel, on every pull request that changes the <code>02-typescript-tool-calls<\/code> folder.<\/strong> The Agents SDK ships a fake model, <code>ScriptedModel<\/code> in <code>@openai\/agents\/testing<\/code>, that returns the turns you script. The tests in <code>test\/wiring.test.ts<\/code> use it to check the tools, schemas, policy code and the checks themselves in a few seconds, with no API key and no Opik:<\/p>\n\n\n\n<pre class=\"wp-block-code language-typescript\"><code>\/\/ abridged from test\/wiring.test.ts\nconst model = new ScriptedModel(&#091;\n  &#091;functionCall(\"lookup_order\", { order_id: \"A1001\" }, { callId: \"c1\" })],\n  &#091;functionCall(\"refund_order\", { order_id: \"A1001\", reason: \"fit\" }, { callId: \"c2\" })],\n  &#091;functionCall(\"refund_order\", { order_id: \"A1001\", reason: \"fit\" }, { callId: \"c3\" })],\n  &#091;assistantMessage(\"Done.\")],\n]);\nconst result = await run(buildAgent({ model }), \"refund A1001\");\nexpect(runChecks(refundCase, summarizeRun(result).toolCalls).one_refund_per_order.pass).toBe(false);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>buildAgent<\/code> creates the support agent with the model you give it. Here the scripted model refunds the same order twice, and the test passes only if <code>one_refund_per_order<\/code> catches it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Live model, by hand and on pull requests labeled <code>run-live<\/code>.<\/strong> It runs <code>evaluate.ts<\/code> and writes a results table to the job summary. It needs <code>ANTHROPIC_API_KEY<\/code> as a repository secret and an Opik instance to log to: <code>OPIK_URL_OVERRIDE<\/code> for a self-hosted Opik, or <code>OPIK_API_KEY<\/code> and <code>OPIK_WORKSPACE<\/code> for Opik Cloud. Pull requests from forks don&#8217;t get secrets. To run it nightly in your own repo, add <code>schedule: &#091;{ cron: \"30 7 * * *\" }]<\/code> to the workflow&#8217;s <code>on:<\/code> block.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-changes-when-you-move-to-claude-sonnet-5-5\">What changes when you move to Claude Sonnet 5.5?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These tests also help when you change models, because a setting can stop working without an error. Anthropic <a href=\"https:\/\/platform.claude.com\/docs\/en\/about-claude\/model-deprecations\">retired Claude Sonnet 4.5<\/a> on November 30, 2026. If you&#8217;re moving an agent to Sonnet 5.5, check whether it forces tool use (a setting that makes the model call a tool), because Sonnet 5.5 doesn&#8217;t support that. Forcing tool use in a direct call to Anthropic&#8217;s API returns a 400 error: <code>tool_choice: type \"tool\" and \"any\" are not supported for this model.<\/code> <a href=\"https:\/\/www.comet.com\/site\/blog\/test-langgraph-agent-tool-calls\/\">Our guide to testing a LangGraph agent&#8217;s tool calls<\/a> has more on that error.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Through the AI SDK adapter this agent uses, you don&#8217;t get that error. The matching setting is <code>toolChoice: \"required\"<\/code>. The adapter passes it to <code>@ai-sdk\/anthropic<\/code>, the AI SDK&#8217;s package for Claude. Version 4.0.107 of that package changes it to <code>auto<\/code> and raises a warning, but the adapter never reads the warning. To confirm this, I captured the request with <code>check-tool-choice.ts<\/code> (in the repo). It contained <code>tool_choice: {\"type\": \"auto\"}<\/code>, and no warning appeared on screen.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If your agent relied on <code>\"required\"<\/code> to force a lookup, the lookup is now optional. Leave tool choice on auto, say in the prompt when each tool is required, and let <code>expected_calls<\/code> tell you when the model skips one.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-should-you-watch-out-for\">What should you watch out for?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Three SDK details can trip you up when you write these tests. I checked them on the versions listed at the end of this post.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Traces are empty under Vitest and Jest.<\/strong> The Agents SDK turns tracing off when <code>NODE_ENV<\/code> is <code>test<\/code> (<a href=\"https:\/\/openai.github.io\/openai-agents-js\/guides\/tracing\/\">tracing guide<\/a>). Read tool calls from the run result, or call <code>setTracingDisabled(false)<\/code> in the test.<\/li>\n\n\n\n<li><strong>Arguments are a JSON string.<\/strong> <code>rawItem.arguments<\/code> is <code>'{\"order_id\":\"a1003\"}'<\/code>, not an object. Parse it, then normalize.<\/li>\n\n\n\n<li><strong>Zod parameters are strict.<\/strong> Every field becomes required, with no extra properties. When a value may not exist, ask for an empty string in the tool description, as <code>escalate_to_human<\/code> does for <code>order_id<\/code>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-s-the-next-step-in-opik\">What&#8217;s the next step in Opik?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Similar checks can run on live traffic. Opik&#8217;s <a href=\"https:\/\/www.comet.com\/docs\/opik\/production\/online-evaluation\/rules\">online evaluation rules<\/a> score new traces as they&#8217;re logged, with an LLM judge or a code metric; the code option is Python, so these checks would need a short port. And because the trace processor records tool errors on their spans, you can filter production traces for a failed <code>refund_order<\/code> and look at those first, before the customer writes in.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The code is at <a href=\"https:\/\/github.com\/comet-ml\/agent-testing-recipes\">github.com\/comet-ml\/agent-testing-recipes<\/a>, folder <code>02-typescript-tool-calls<\/code>. There&#8217;s also <a href=\"https:\/\/github.com\/comet-ml\/agent-testing-recipes\/tree\/main\/01-langgraph-tool-calls\">a Python version of this agent, built with LangGraph<\/a>, tested with the same 23 messages. Opik is <a href=\"https:\/\/github.com\/comet-ml\/opik\">open source<\/a> and runs locally (<a href=\"https:\/\/www.comet.com\/docs\/opik\/self-host\/local_deployment\">setup guide<\/a>); no account needed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-faq\">FAQ<\/h2>\n\n\n<div class=\"saswp-faq-block-section\"><ol style=\"list-style-type:none\"><li style=\"list-style-type: none\"><h5 class=\"saswp-faq-question-title \">How do I trace the OpenAI Agents SDK in TypeScript with Opik?<\/h5><p class=\"saswp-faq-answer-text\">Register a <code>TracingProcessor<\/code> that writes to Opik&#8217;s TypeScript SDK: <code>setTraceProcessors(&#091;new OpikTracingProcessor()])<\/code>. Opik&#8217;s packaged Agents SDK integration is Python only, so the example repo has the processor as one file you can copy.<\/p><li style=\"list-style-type: none\"><h5 class=\"saswp-faq-question-title \">How do I test that my agent called the right tool with the right arguments?<\/h5><p class=\"saswp-faq-answer-text\">Read the calls from <code>result.newItems<\/code> (each <code>tool_call_item<\/code> has the tool name and its arguments as a JSON string), parse the arguments, normalize IDs, and compare them in code with what the test case expects. Run each case several times and gate on the pass rate.<\/p><li style=\"list-style-type: none\"><h5 class=\"saswp-faq-question-title \">Can I use Claude with the OpenAI Agents SDK?<\/h5><p class=\"saswp-faq-answer-text\">Yes. Install <code>@openai\/agents-extensions<\/code> and <code>@ai-sdk\/anthropic<\/code>, then pass <code>aisdk(anthropic(\"claude-sonnet-5-5\"))<\/code> as the agent&#8217;s model. The SDK docs call the adapter beta and say it&#8217;s &#8220;worth testing carefully with your chosen provider&#8221;, which is what the tests here do.<\/p><li style=\"list-style-type: none\"><h5 class=\"saswp-faq-question-title \">How do I run agent tests in GitHub Actions without an API key?<\/h5><p class=\"saswp-faq-answer-text\">Use <code>ScriptedModel<\/code> from <code>@openai\/agents\/testing<\/code> to script the model&#8217;s turns. It tests your tools, schemas and checks for free. Run the real model in a separate job that has the key as a secret.<\/p><li style=\"list-style-type: none\"><h5 class=\"saswp-faq-question-title \">Does <code>toolChoice: \"required\"<\/code> work with Claude Sonnet 5.5?<\/h5><p class=\"saswp-faq-answer-text\">Not as forced tool use. Through the AI SDK adapter, <code>@ai-sdk\/anthropic<\/code> sends it as <code>auto<\/code> and raises a warning that the adapter doesn&#8217;t pass on, so the run succeeds with nothing on screen. Called directly, the Messages API rejects forced tool choice for Sonnet 5.5 with a 400.<\/p><\/ul><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-which-versions-did-i-test\">Which versions did I test?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I tested this example on November 23, 2026, with Node 26.13.1, TypeScript 7.0.2, <code>@openai\/agents<\/code> 0.22.0, <code>@openai\/agents-extensions<\/code> 0.22.0, <code>ai<\/code> 7.0.180, <code>@ai-sdk\/anthropic<\/code> 4.0.107, <code>opik<\/code> 2.2.155 (SDK and local server), Vitest 5.1.1 and tsx 4.23.15.<\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>An OpenAI Agents SDK agent retried a failing refund tool in 40 of 40 runs. Test tool calls and arguments in TypeScript with CI and Opik.<\/p>\n","protected":false},"author":156,"featured_media":21133,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"customer_name":"","customer_description":"","customer_industry":"","customer_technologies":"","customer_logo":"","_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":true,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[65,7],"tags":[],"coauthors":[377],"class_list":["post-21069","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-llmops","category-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to test OpenAI Agents SDK tool calls in TypeScript (CI + Opik)<\/title>\n<meta name=\"description\" content=\"An OpenAI Agents SDK agent retried a failing refund tool in 40 of 40 runs. Test tool calls and arguments in TypeScript with CI and Opik.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.comet.com\/site\/blog\/test-openai-agents-sdk-tool-calls-typescript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to test OpenAI Agents SDK tool calls in TypeScript (CI + Opik)\" \/>\n<meta property=\"og:description\" content=\"An OpenAI Agents SDK agent retried a failing refund tool in 40 of 40 runs. Test tool calls and arguments in TypeScript with CI and Opik.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.comet.com\/site\/blog\/test-openai-agents-sdk-tool-calls-typescript\/\" \/>\n<meta property=\"og:site_name\" content=\"Comet\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/cometdotml\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-30T15:42:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-11-30T20:55:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/test-openai-agents-sdk-tool-calls-featured.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Brian Wones\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Cometml\" \/>\n<meta name=\"twitter:site\" content=\"@Cometml\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Brian Wones\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to test OpenAI Agents SDK tool calls in TypeScript (CI + Opik)","description":"An OpenAI Agents SDK agent retried a failing refund tool in 40 of 40 runs. Test tool calls and arguments in TypeScript with CI and Opik.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.comet.com\/site\/blog\/test-openai-agents-sdk-tool-calls-typescript\/","og_locale":"en_US","og_type":"article","og_title":"How to test OpenAI Agents SDK tool calls in TypeScript (CI + Opik)","og_description":"An OpenAI Agents SDK agent retried a failing refund tool in 40 of 40 runs. Test tool calls and arguments in TypeScript with CI and Opik.","og_url":"https:\/\/www.comet.com\/site\/blog\/test-openai-agents-sdk-tool-calls-typescript\/","og_site_name":"Comet","article_publisher":"https:\/\/www.facebook.com\/cometdotml","article_published_time":"2026-11-30T15:42:14+00:00","article_modified_time":"2026-11-30T20:55:08+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/test-openai-agents-sdk-tool-calls-featured.jpg","type":"image\/jpeg"}],"author":"Brian Wones","twitter_card":"summary_large_image","twitter_creator":"@Cometml","twitter_site":"@Cometml","twitter_misc":{"Written by":"Brian Wones","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.comet.com\/site\/blog\/test-openai-agents-sdk-tool-calls-typescript\/#article","isPartOf":{"@id":"https:\/\/www.comet.com\/site\/blog\/test-openai-agents-sdk-tool-calls-typescript\/"},"author":{"name":"Brian Wones","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/612a6a3dc91749532dc64606c3bcd8d5"},"headline":"How to test OpenAI Agents SDK tool calls in TypeScript (CI + Opik)","datePublished":"2026-11-30T15:42:14+00:00","dateModified":"2026-11-30T20:55:08+00:00","mainEntityOfPage":{"@id":"https:\/\/www.comet.com\/site\/blog\/test-openai-agents-sdk-tool-calls-typescript\/"},"wordCount":2311,"commentCount":0,"publisher":{"@id":"https:\/\/www.comet.com\/site\/#organization"},"image":{"@id":"https:\/\/www.comet.com\/site\/blog\/test-openai-agents-sdk-tool-calls-typescript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/test-openai-agents-sdk-tool-calls-featured.jpg","articleSection":["LLMOps","Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.comet.com\/site\/blog\/test-openai-agents-sdk-tool-calls-typescript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.comet.com\/site\/blog\/test-openai-agents-sdk-tool-calls-typescript\/","url":"https:\/\/www.comet.com\/site\/blog\/test-openai-agents-sdk-tool-calls-typescript\/","name":"How to test OpenAI Agents SDK tool calls in TypeScript (CI + Opik)","isPartOf":{"@id":"https:\/\/www.comet.com\/site\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.comet.com\/site\/blog\/test-openai-agents-sdk-tool-calls-typescript\/#primaryimage"},"image":{"@id":"https:\/\/www.comet.com\/site\/blog\/test-openai-agents-sdk-tool-calls-typescript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/test-openai-agents-sdk-tool-calls-featured.jpg","datePublished":"2026-11-30T15:42:14+00:00","dateModified":"2026-11-30T20:55:08+00:00","description":"An OpenAI Agents SDK agent retried a failing refund tool in 40 of 40 runs. Test tool calls and arguments in TypeScript with CI and Opik.","breadcrumb":{"@id":"https:\/\/www.comet.com\/site\/blog\/test-openai-agents-sdk-tool-calls-typescript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.comet.com\/site\/blog\/test-openai-agents-sdk-tool-calls-typescript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/blog\/test-openai-agents-sdk-tool-calls-typescript\/#primaryimage","url":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/test-openai-agents-sdk-tool-calls-featured.jpg","contentUrl":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/test-openai-agents-sdk-tool-calls-featured.jpg","width":1280,"height":720,"caption":"Test OpenAI Agents SDK Tool Calls in TypeScript. When a refund timed out, the agent tried it again in 40 of 40 runs with the default error message and 0 of 40 with a custom one. It handed off to a person in 0 of 40 and 40 of 40."},{"@type":"BreadcrumbList","@id":"https:\/\/www.comet.com\/site\/blog\/test-openai-agents-sdk-tool-calls-typescript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.comet.com\/site\/"},{"@type":"ListItem","position":2,"name":"How to test OpenAI Agents SDK tool calls in TypeScript (CI + Opik)"}]},{"@type":"WebSite","@id":"https:\/\/www.comet.com\/site\/#website","url":"https:\/\/www.comet.com\/site\/","name":"Comet","description":"Build Better Models Faster","publisher":{"@id":"https:\/\/www.comet.com\/site\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.comet.com\/site\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.comet.com\/site\/#organization","name":"Comet ML, Inc.","alternateName":"Comet","url":"https:\/\/www.comet.com\/site\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/#\/schema\/logo\/image\/","url":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2025\/01\/logo_comet_square.png","contentUrl":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2025\/01\/logo_comet_square.png","width":310,"height":310,"caption":"Comet ML, Inc."},"image":{"@id":"https:\/\/www.comet.com\/site\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/cometdotml","https:\/\/x.com\/Cometml","https:\/\/www.youtube.com\/channel\/UCmN63HKvfXSCS-UwVwmK8Hw"]},{"@type":"Person","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/612a6a3dc91749532dc64606c3bcd8d5","name":"Brian Wones","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.comet.com\/site\/#\/schema\/person\/image\/3a43fa168da527fef78867536bae3cbe","url":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/brian-wones-headshot-96x96.jpeg","contentUrl":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/brian-wones-headshot-96x96.jpeg","caption":"Brian Wones"},"description":"Brian Wones works with Comet on developer marketing and builds open-source kits that help teams test LLM apps with Opik.","url":"https:\/\/www.comet.com\/site\/blog\/author\/brianwcomet-com\/"}]}},"jetpack_featured_media_url":"https:\/\/www.comet.com\/site\/wp-content\/uploads\/2026\/11\/test-openai-agents-sdk-tool-calls-featured.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/21069","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/users\/156"}],"replies":[{"embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/comments?post=21069"}],"version-history":[{"count":3,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/21069\/revisions"}],"predecessor-version":[{"id":21131,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/posts\/21069\/revisions\/21131"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/media\/21133"}],"wp:attachment":[{"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/media?parent=21069"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/categories?post=21069"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/tags?post=21069"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.comet.com\/site\/wp-json\/wp\/v2\/coauthors?post=21069"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}