Repository navigation
Description
What happens
activityAsTool (@temporalio/openai-agents/workflow) parses the model's tool arguments and calls
the Activity with that one object. An existing Activity whose only parameter is a string, such as
the Temporal docs' basic greet(name: string), gets the object as its string. It returns a wrong
value (Hello, [object Object]!), the model gets that as a normal tool result, and the run
completes with no error.
The README says to use activityAsTool for I/O and that the tool name must match a registered
Activity. It does not limit the Activity's parameters. The types accept the Activity too: the
constraint (input: any) => Promise<any> accepts (name: string) => Promise<string>, and
JsonObjectSchema<_T> never uses _T, so activityAsTool<typeof greet>(...) compiles under
tsc --strict. The plugin knows the Activity only by name, so it cannot tell a one-string Activity
from a one-object one at run time.
Reproduction
One file. It starts a local test server with @temporalio/testing, runs a scripted model that
calls greet with {"name":"Ada"}, and exits 1 when greet gets anything other than "Ada".
--input-property sets the field proposed below.
// activity_repro.cjs: node activity_repro.cjs [--input-property]
// An Activity whose parameter is a string, exposed with activityAsTool.
// Exits 0 when greet gets "Ada", 1 when it gets something else.
const { Agent } = require('@openai/agents-core');
const { activityAsTool, TemporalOpenAIRunner } = require('@temporalio/openai-agents/workflow');
async function greetWorkflow(useInputProperty) {
const greetTool = activityAsTool({
name: 'greet',
description: 'Greet a person by name.',
parameters: { type: 'object', properties: { name: { type: 'string' } }, required: ['name'], additionalProperties: false },
...(useInputProperty ? { inputProperty: 'name' } : {}),
});
const agent = new Agent({ name: 'Greeter', instructions: 'Greet the person.', model: 'scripted', tools: [greetTool] });
return (await new TemporalOpenAIRunner().run(agent, 'Greet Ada.')).finalOutput;
}
module.exports = { greetWorkflow };
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 greet with {"name":"Ada"}, 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: 'greet', callId: 'call_1', status: 'completed',
arguments: JSON.stringify({ name: 'Ada' }) }] };
}
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 env = await TestWorkflowEnvironment.createLocal();
try {
const worker = await Worker.create({
connection: env.nativeConnection,
taskQueue: 'tq',
workflowsPath: __filename,
bundlerOptions: { ignoreModules: ['module'] },
plugins: [new OpenAIAgentsPlugin({ modelProvider: { getModel: () => model } })],
activities: {
async greet(name) {
received = name;
return `Hello, ${name}!`;
},
},
});
const useInputProperty = process.argv.includes('--input-property');
const result = await worker.runUntil(
env.client.workflow.execute(greetWorkflow, { taskQueue: 'tq', workflowId: 'greet', args: [useInputProperty] })
);
console.log(`inputProperty: ${useInputProperty ? "'name'" : 'not set'}`);
console.log(`greet got: ${JSON.stringify(received)} (${typeof received})`);
console.log(`run result: ${JSON.stringify(result)}`);
process.exitCode = received === 'Ada' ? 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 and Node 24.22:
$ node activity_repro.cjs
inputProperty: not set
greet got: {"name":"Ada"} (object)
run result: "Hello, [object Object]!"
exit=1
The local test server's startup banner is left out. Both versions print the same lines.
Controls: the same Activity called from a Workflow with proxyActivities gets "Ada" and returns
Hello, Ada!. Activities that take one object, like the README's getWeather({ location }),
work.
Expected
A supported way to expose an existing Activity with one scalar parameter as a tool, so that it
gets the model's value, "Ada".
Impact
Any existing Activity with one string, number or boolean parameter gets an object and returns a
wrong result with no error. An Activity that writes data would act on the wrong value. Workaround:
change the Activity to take one object, or register a wrapper Activity that does.
Proposed fix
An optional inputProperty field on the tool definition that names one property of parameters.
When it is set, the Activity gets that property's value instead of the whole object. Without it,
the Activity gets the same input as before. A name that is not in parameters fails the Workflow
with AgentsWorkflowError. A PR follows.
nexusOperationAsTool has the same problem with Operations whose input is a scalar; I'm filing it
separately.
Activity