Repository navigation
Description
What happens
agentAsTool starts the nested run with a new TemporalOpenAIRunner and passes it only the
run's sandbox. So, in a run that sets runConfig.model or runConfig.modelSettings, or whose
runner sets defaultModelParams:
- a nested agent that sets no model of its own calls the Worker provider's default model instead
of the run's model, and without the run's model settings; - the nested agent's model Activities lose the runner's
defaultModelParams(timeout, summary,
retry policy, task queue, local Activity). A Workflow started without the plugin's Client, such
as by a Schedule or the CLI, has no other way to set them.
The run completes with no error or warning.
Upstream agent.asTool() passes the parent run's model and modelSettings, without
toolChoice and parallelToolCalls, to the nested run (getInheritedAgentToolRunConfig in
packages/agents-core/src/agentToolRunConfig.ts; its test "inherits only the parent RunConfig
model for nested agent tools by default"). The plugin README presents agentAsTool as the
plugin's form of agents as tools and doesn't mention a difference.
Reproduction
One file, agent_tool_repro.cjs. It runs a lead agent with one agentAsTool tool whose agent
sets no model, under runConfig: { model: 'run-model', modelSettings: { temperature: 0.33 } }
and a runner with defaultModelParams: { startToCloseTimeout: '17 seconds' }. A scripted model
records each call's model name and temperature. The same agents first run natively with the
upstream Runner and agent.asTool() as a control. Exit 0 means the nested call got the run's
model, temperature and timeout.
// agent_tool_repro.cjs: node agent_tool_repro.cjs
// A lead agent calls a nested agent through agentAsTool, in a run with a run model, model settings
// and runner defaults. The nested agent sets no model of its own. Exits 0 when the nested agent's
// model call gets the run's model, temperature and timeout, as upstream agent.asTool() does; 1 if not.
const { Agent } = require('@openai/agents-core');
const { agentAsTool, TemporalOpenAIRunner } = require('@temporalio/openai-agents/workflow');
const RUN_CONFIG = { model: 'run-model', modelSettings: { temperature: 0.33 } };
const RUNNER_DEFAULTS = { startToCloseTimeout: '17 seconds' };
function buildLead(asTool) {
const expert = new Agent({ name: 'Expert', instructions: 'Answer.' });
return new Agent({ name: 'Lead', instructions: 'Ask the expert.', tools: [asTool(expert, { toolName: 'ask_expert' })] });
}
async function leadWorkflow() {
const runner = new TemporalOpenAIRunner({ defaultModelParams: RUNNER_DEFAULTS });
return (await runner.run(buildLead(agentAsTool), 'question', { runConfig: RUN_CONFIG })).finalOutput;
}
module.exports = { leadWorkflow };
async function main() {
const nodeRequire = require('module').createRequire(__filename);
const { Runner, 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 that records each call. The lead (the call with the ask_expert tool) calls the
// tool, then answers with its output; the expert answers with the model name it was asked for.
let seen = [];
const provider = {
getModel(name) {
return {
async getResponse(request) {
const isLead = (request.tools ?? []).some((t) => t.name === 'ask_expert');
seen.push({ agent: isLead ? 'lead' : 'expert', model: name || '(default)', temperature: request.modelSettings?.temperature ?? null });
const input = Array.isArray(request.input) ? request.input : [];
const result = input.find((i) => i.type === 'function_call_result');
const usage = new Usage();
if (isLead && !result) {
return { usage, output: [{ type: 'function_call', name: 'ask_expert', callId: 'call_1', status: 'completed', arguments: '{"input":"q"}' }] };
}
const text = isLead ? `expert said: ${typeof result.output === 'string' ? result.output : result.output.text}` : `answer from ${name || '(default)'}`;
return { usage, output: [{ type: 'message', id: 'msg_1', role: 'assistant', status: 'completed', content: [{ type: 'output_text', text }] }] };
},
async *getStreamedResponse() {
throw new Error('not used');
},
};
},
};
// Native control: upstream Runner and agent.asTool() with the same provider and run config.
const native = await new Runner({ modelProvider: provider, ...RUN_CONFIG }).run(
buildLead((agent, opts) => agent.asTool(opts)),
'question'
);
for (const s of seen) console.log(`native ${JSON.stringify(s)}`);
console.log(`native result: ${JSON.stringify(native.finalOutput)}`);
seen = [];
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: provider })],
});
const handle = await env.client.workflow.start(leadWorkflow, { taskQueue: 'tq', workflowId: 'lead' });
const result = await worker.runUntil(handle.result());
for (const s of seen) console.log(`plugin ${JSON.stringify(s)}`);
console.log(`plugin result: ${JSON.stringify(result)}`);
const { events } = await handle.fetchHistory();
const timeouts = events
.filter((e) => e.activityTaskScheduledEventAttributes?.activityType?.name === 'invokeModelActivity')
.map((e) => Number(e.activityTaskScheduledEventAttributes.startToCloseTimeout.seconds));
console.log(`model Activity timeouts (lead, expert, lead): ${timeouts.join(', ')} s`);
const expert = seen.find((s) => s.agent === 'expert');
process.exitCode = expert?.model === 'run-model' && expert?.temperature === 0.33 && timeouts[1] === 17 ? 0 : 1;
} finally {
await env.teardown();
}
}
if (require.main === module) {
main().catch((err) => {
console.error(err);
process.exitCode = 1;
});
}node agent_tool_repro.cjs with @temporalio/openai-agents 1.24.0 (the latest release) and with
a package built from main at c664a34; @temporalio/worker, @temporalio/testing 1.24.0,
@openai/agents-core 0.14.3, Node 24.22.0. Both print the same (dev server lines removed) and exit 1:
native {"agent":"lead","model":"run-model","temperature":0.33}
native {"agent":"expert","model":"run-model","temperature":0.33}
native {"agent":"lead","model":"run-model","temperature":0.33}
native result: "expert said: answer from run-model"
plugin {"agent":"lead","model":"run-model","temperature":0.33}
plugin {"agent":"expert","model":"(default)","temperature":null}
plugin {"agent":"lead","model":"run-model","temperature":0.33}
plugin result: "expert said: answer from (default)"
model Activity timeouts (lead, expert, lead): 17, 60, 17 s
Expected: the nested expert call goes to run-model with temperature: 0.33, as natively,
and its model Activity gets the runner's 17-second timeout.
Observed: it goes to the Worker provider's default model (getModel('')) with no
temperature, and its model Activity gets the plugin's default 60-second timeout.
Controls:
- The native run above sends the nested call to
run-modelwithtemperature: 0.33. - A nested agent that sets its own model keeps it, natively and through the plugin.
modelParamsset through the plugin's Client header do reach nested agents' model Activities
today. Only the runner'sdefaultModelParamsare lost.
Impact
- The nested agent answers from a model the run did not choose, without its settings, so its
quality, cost and supported features follow the Worker's default model. The run completes. - Runner defaults don't reach nested model calls. With
defaultModelParams.retry: { maximumAttempts: 2 }
and no Client header, a nested model call that keeps failing is scheduled with no attempt limit
and retries until the run's timeout. The same holds for a summary, a task queue or
useLocalActivity.
Workaround: set the model and settings on each agent passed to agentAsTool, and set model
Activity options on the Client's plugin instead of the runner.
Proposed fix
Pass the calling run's runConfig.model (as a default for nested agents that set none, as
upstream does), its runConfig.modelSettings without toolChoice and parallelToolCalls, and
its runner's defaultModelParams to the nested run, the way the plugin already passes the sandbox.
Put it behind patched() so nested runs recorded before the change replay unchanged: with
useLocalActivity in the runner's defaults, an old nested model call would otherwise replay as a
local Activity instead of the recorded Activity. A PR follows.
Activity