Skip to content

[typescript/openai-agents] add inputProperty to activityAsTool for Activities with a scalar parameter - #216

Draft
campoy wants to merge 2 commits into
mainfrom
fix/openai-agents-typescript-activity-tool-scalar-parameter-misbound
Draft

campoy wants to merge 2 commits into
mainfrom
fix/openai-agents-typescript-activity-tool-scalar-parameter-misbound

Conversation

@campoy

@campoy campoy commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What was changed

activityAsTool gets an optional inputProperty field on its tool definition. It names one property of parameters. When it is set, the Activity gets that property's value as its argument instead of the whole arguments object:

const greetTool = activityAsTool<typeof activities.greet>({
  name: 'greet',
  description: 'Greet a person by name',
  parameters: {
    type: 'object',
    properties: { name: { type: 'string' } },
    required: ['name'],
    additionalProperties: false,
  },
  inputProperty: 'name',
});
  • Without the field, the Activity gets the same input as before.
  • A name that is not in parameters.properties fails the Workflow with a non-retryable AgentsWorkflowError, as convertAgent does for other tool mistakes. A typo would otherwise send undefined, the same kind of silent wrong value. The check runs when TemporalOpenAIRunner.run converts the agent, before the first model call, and again when the tool is invoked. It does not run when activityAsTool is called, so a tool declared at module level cannot stop the Workflow bundle from loading.
  • README: the Activity-backed tools section shows the field.

API change: additive. The new field is optional and existing tools behave the same.

Old runs and rollback: a tool call schedules the same Activity as before; only its input changes when the field is set, and Temporal does not compare Activity inputs on replay. No patched gate is needed, and histories replay on either version. Rolling back is not safe for runs that will still call a tool with inputProperty: the previous release ignores the field, so a tool call scheduled after the rollback sends the whole arguments object again (Hello, [object Object]!). Activities scheduled before the rollback keep their recorded input. Before rolling back, let those runs finish, or remove the field and change the Activity to take the object.

Why?

See #211. An existing Activity with one string parameter, such as greet(name: string), got {"name":"Ada"} as its string, returned Hello, [object Object]!, and the run completed with no error. The plugin knows the Activity only by name, so it needs to be told which value to send.

Checklist

  1. Closes [Bug] openai-agents (TypeScript): activityAsTool gives a one-string Activity the arguments object #211

  2. How was this tested:

    • New test activityAsTool inputProperty gives a scalar Activity one property of the arguments in src/__tests__/test-openai-agents.ts, with its Workflows in workflows/openai-agents.ts: a real Worker and a fake model that calls greet with {"name":"Ada"}. With tools.ts from main it fails on t.deepEqual(received, [['Ada']]) (the Activity got [{ name: 'Ada' }]); with this change it passes. The same Worker runs a Workflow whose tool, declared at module level, has inputProperty: 'nmae'; it fails with a non-retryable AgentsWorkflowError and the Activity never runs. That module-level tool is in the bundle every Workflow test in this file loads, so those tests also show the bundle still loads. With a check in activityAsTool itself, the test fails at import with inputProperty 'nmae' is not a property in parameters.
    • New test in src/__tests__/convert-agent.test.ts: convertAgent and invoke throw AgentsWorkflowError for an unknown name and for an inherited one (toString), and a valid name passes.
    • Locally, in Docker (pnpm 10.27.0, Linux arm64), in typescript/openai-agents: make lint passes (the 8 warnings main has, none in files this PR touches), make test passes (209 tests), make build packs, and scripts/ci/check_conventions.py passes. Prettier with the SDK's settings is clean on the changed files.
    • Rollback: a review run started an opted-in Workflow on this branch, stopped it before the tool call was scheduled, and resumed it on main's tools.ts. The Activity got the whole object (Hello, [object Object]!); resumed on this branch, it returned Hello, Ada!. Both histories replayed on both versions. The rollback paragraph above describes this.

    CI covers the other Node versions and platforms.

  3. Any docs updates needed?
    The README paragraph, included here.

Related: #212 reports the same problem for nexusOperationAsTool; its PR adds the same field with the same name and check. #213's PR adds includeContext to the same tool definition and changes the same invoke code. The PRs don't depend on each other, but they add tests next to each other, so whichever merges second needs a small rebase.

Open questions:

  • Is one property name the shape you want? The other option is a mapper function, such as toArgs: ({ name }) => [name], which would also cover Activities with two or more parameters but runs a callback in Workflow code. This PR keeps the smaller field and uses the same name for nexusOperationAsTool.
  • Should the field live on the definition, as here, or in ActivityAsToolOptions next to the timeouts? It sits next to parameters because it names one of its properties.

Draft while these questions are open.

…meter

activityAsTool passes the model's arguments to the Activity as one object.
An Activity whose parameter is a string, such as greet(name: string), got
that object as the string and returned a wrong value with no error.

The new optional inputProperty field of the tool definition names one
property of the arguments. When it is set, the Activity gets that
property's value instead of the whole object. A name that is not in
parameters fails the Workflow with an AgentsWorkflowError. Without the
field, the Activity gets the same input as before.
@campoy campoy changed the title Add inputProperty to activityAsTool for Activities with a scalar parameter [openai-agents-typescript] add inputProperty to activityAsTool for Activities with a scalar parameter Nov 16, 2026
@campoy campoy changed the title [openai-agents-typescript] add inputProperty to activityAsTool for Activities with a scalar parameter [typescript/openai-agents] add inputProperty to activityAsTool for Activities with a scalar parameter Nov 16, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] openai-agents (TypeScript): activityAsTool gives a one-string Activity the arguments object

1 participant