Skip to content

[Bug] openai-agents (TypeScript): nexusOperationAsTool gives a string-input Operation the arguments object #212

Open

Description

@campoy

What happens

nexusOperationAsTool (@temporalio/openai-agents/workflow) parses the model's tool arguments and
sends that one object as the Operation's input. An Operation whose input is a string, such as
confirm: nexus.operation<string, string>(), gets the object. Its handler returns a wrong value
(confirmed [object Object]), the model gets that as a normal tool result, and the run completes
with no error.

The README says to use nexusOperationAsTool to expose a Nexus Operation as a tool and does not
limit the input type. Nexus inputs can be any serializable value, and the TypeScript SDK's own
tests often use string inputs. The helper accepts any Operation of the service, and
JsonObjectSchema<_T> never uses _T and only allows type: 'object', so the model always sends
an object and no schema can give the Operation a string. An Operation definition carries no input
type at run time, so the plugin cannot tell a string input from an object one.

Reproduction

One file. It starts a local test server with @temporalio/testing, creates an endpoint for a
handler on the same Worker, runs a scripted model that calls confirm with {"ref":"BK-7"}, and
exits 1 when the handler gets anything other than "BK-7". --input-property sets the field
proposed below.

// nexus_repro.cjs: node nexus_repro.cjs [--input-property]
// A Nexus Operation whose input is a string, exposed with nexusOperationAsTool.
// Exits 0 when the handler gets "BK-7", 1 when it gets something else.
const nexus = require('nexus-rpc');
const { Agent } = require('@openai/agents-core');
const { nexusOperationAsTool, TemporalOpenAIRunner } = require('@temporalio/openai-agents/workflow');

// In TypeScript: confirm: nexus.operation<string, string>()
const bookingService = nexus.service('booking', { confirm: nexus.operation() });

async function confirmWorkflow(useInputProperty) {
  const confirmTool = nexusOperationAsTool(
    bookingService.operations.confirm,
    {
      name: 'confirm',
      description: 'Confirm a booking by its reference.',
      parameters: { type: 'object', properties: { ref: { type: 'string' } }, required: ['ref'], additionalProperties: false },
      ...(useInputProperty ? { inputProperty: 'ref' } : {}),
    },
    { service: bookingService, endpoint: 'booking-endpoint' }
  );
  const agent = new Agent({ name: 'Booker', instructions: 'Confirm the booking.', model: 'scripted', tools: [confirmTool] });
  return (await new TemporalOpenAIRunner().run(agent, 'Confirm BK-7.')).finalOutput;
}
module.exports = { confirmWorkflow };

async function main() {
  const nodeRequire = require('module').createRequire(__filename);
  const { Usage, setTracingDisabled } = nodeRequire('@openai/agents-core');
  const { OpenAIAgentsPlugin } = nodeRequire('@temporalio/openai-agents');
  const { TestWorkflowEnvironment } = nodeRequire('@temporalio/testing');
  const { DefaultLogger, Runtime, Worker } = nodeRequire('@temporalio/worker');
  setTracingDisabled(true);
  Runtime.install({ logger: new DefaultLogger('WARN') });

  // A scripted model: call confirm with {"ref":"BK-7"}, then answer with the tool's output.
  const model = {
    async getResponse(request) {
      const usage = new Usage();
      const result = (Array.isArray(request.input) ? request.input : []).find((i) => i.type === 'function_call_result');
      if (!result) {
        return { usage, output: [{ type: 'function_call', name: 'confirm', callId: 'call_1', status: 'completed',
          arguments: JSON.stringify({ ref: 'BK-7' }) }] };
      }
      const text = typeof result.output === 'string' ? result.output : result.output.text;
      return { usage, output: [{ type: 'message', id: 'msg_1', role: 'assistant', status: 'completed',
        content: [{ type: 'output_text', text }] }] };
    },
    async *getStreamedResponse() {
      throw new Error('not used');
    },
  };

  let received;
  const handler = nexus.serviceHandler(bookingService, {
    async confirm(_ctx, ref) {
      received = ref;
      return `confirmed ${ref}`;
    },
  });
  const env = await TestWorkflowEnvironment.createLocal();
  try {
    await env.createNexusEndpoint('booking-endpoint', 'tq');
    const worker = await Worker.create({
      connection: env.nativeConnection,
      taskQueue: 'tq',
      workflowsPath: __filename,
      bundlerOptions: { ignoreModules: ['module'] },
      plugins: [new OpenAIAgentsPlugin({ modelProvider: { getModel: () => model } })],
      nexusServices: [handler],
    });
    const useInputProperty = process.argv.includes('--input-property');
    const result = await worker.runUntil(
      env.client.workflow.execute(confirmWorkflow, { taskQueue: 'tq', workflowId: 'confirm', args: [useInputProperty] })
    );
    console.log(`inputProperty: ${useInputProperty ? "'ref'" : 'not set'}`);
    console.log(`confirm got: ${JSON.stringify(received)} (${typeof received})`);
    console.log(`run result: ${JSON.stringify(result)}`);
    process.exitCode = received === 'BK-7' ? 0 : 1;
  } finally {
    await env.teardown();
  }
}

if (require.main === module) {
  main().catch((err) => {
    console.error(err);
    process.exitCode = 1;
  });
}

With @temporalio/openai-agents 1.24.0 (npm) and with the package built from this repository's
main (c664a34), both with @temporalio/* 1.24.0, @openai/agents-core 0.14.3, nexus-rpc
0.0.3 and Node 24.22:

$ node nexus_repro.cjs
inputProperty: not set
confirm got: {"ref":"BK-7"} (object)
run result: "confirmed [object Object]"
exit=1

The local test server's startup banner is left out. Both versions print the same lines.

Controls: the same Operation called from a Workflow with createNexusServiceClient(...) and
executeOperation(confirm, 'BK-7') gets "BK-7" and returns confirmed BK-7. Operations whose
input is one object, like the README's getWeather({ location }), work.

Expected

A supported way to expose a Nexus Operation with a scalar input as a tool, so that it gets the
model's value, "BK-7".

Impact

Any Operation with a string, number or boolean input gets an object and returns a wrong result
with no error. A handler that calls a string method on the input throws, and the SDK retries it as
an internal handler error until the Operation times out. A handler that writes data would act on
the wrong value. Workaround: give the Operation an object input, or add one that calls the
original.

Proposed fix

An optional inputProperty field on the tool definition that names one property of parameters.
When it is set, the Operation gets that property's value as its input instead of the whole object.
Without it, the Operation gets the same input as before. A name that is not in parameters fails
the Workflow with AgentsWorkflowError. This matches the field proposed for activityAsTool in
#211. A PR follows.

Activity

  1. added
    bug
    on Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions