Skip to content

chat_completions breaks handoffs #26

@Manouchehri

Description

@Manouchehri

Describe the bug

setOpenAIAPI('chat_completions'); seems to break handoffs.

Debug information

  • Agents SDK version: (e.g. v0.0.2)
  • Runtime environment (e.g. Node.js 23.11.0)

Repro steps

import { Agent, run, setDefaultOpenAIClient, setTracingExportApiKey, setOpenAIAPI  } from '@openai/agents';
import { OpenAI } from 'openai';

const customClient = new OpenAI({ 
  baseURL: "https://api.openai.com/v1",
  apiKey: process.env.OPENAI_API_KEY_OFFICIAL
});

setDefaultOpenAIClient(customClient);
setTracingExportApiKey(process.env.OPENAI_API_KEY_OFFICIAL);

setOpenAIAPI('chat_completions');

const chosen_model = 'gpt-4.1-2025-04-14';

const historyTutorAgent = new Agent({
  model: chosen_model,
  name: 'History Tutor',
  instructions:
    'You provide assistance with historical queries. Explain important events and context clearly.',
});

const mathTutorAgent = new Agent({
  model: chosen_model,
  name: 'Math Tutor',
  instructions:
    'You provide help with math problems. Explain your reasoning at each step and include examples',
});

const triageAgent = new Agent({
  model: chosen_model,
  name: 'Triage Agent',
  instructions:
    "You determine which agent to use based on the user's homework question. You must never answer the question directly, as you are not an expert in any subject. Instead, you will route the question to the appropriate agent based on the subject matter.",
  handoffs: [historyTutorAgent, mathTutorAgent],
});

async function main() {
  const result = await run(triageAgent, 'What is the capital of France?');
  console.log(result.finalOutput);
}

main().catch((err) => console.error(err));

Expected behavior

Handoffs should work instead of going into a loop.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions