Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

BUG: ResponseReasoningItem in input items causes error #29

Open
@bakikucukcakiroglu

Description

@bakikucukcakiroglu

This occurs in two scenarios:

  • during the run if the run executes a reasoning agent and handoff to a non-reasoning agent
  • during the next run if the run executes a reasoning agent as the last agent

Since the reasoning item is in the input items of the non reasoning agent during the cases above, API returns an error.

Related issue in the original SDK:

Activity

yusuf-eren

yusuf-eren commented on Jun 1, 2025

@yusuf-eren
Owner

Hi @bakikucukcakiroglu , Thanks for creating reasoning issues. For that issue, can we wait for the original implementation? In this library, I aim to follow the original patterns of implementation. Whenever they implement the feature, I will also implement it.

However, I can provide you with the TypeScript version of the workaround code. I tested it and it filters the reasoning_item ;

import { Agent, HandoffInputData, handoff, Runner } from 'openai-agents-js';

/**
 * Filters out all reasoning items from the handoff data.
 */
function removeReasoningItems(handoffInputData: HandoffInputData): HandoffInputData {
  console.log('----handoffInputData----', handoffInputData);
  const history = handoffInputData.inputHistory;

  // Filter out reasoning items from new_items
  const filteredNewItems = handoffInputData.newItems.filter(item => item?.type !== 'reasoning_item');

  // Filter out reasoning items from pre_handoff_items
  const filteredPreHandoffItems = handoffInputData.preHandoffItems.filter(item => item?.type !== 'reasoning_item');
  console.log('----preHandoffItems----', handoffInputData.preHandoffItems, '\n----');
  console.log('----filteredPreHandoffItems----', filteredPreHandoffItems, '\n----');
  console.log('----filteredNewItems----', filteredNewItems, '\n----');
  console.log('----history----', history, '\n----');

  return new HandoffInputData(history, filteredPreHandoffItems, filteredNewItems);
}

const routingAgent = new Agent({
  name: 'RoutingAgent',
  instructions: 'You are a routing agent. Route the user to the correct agent.',
  tools: [],
  model: 'gpt-4.1',
});

const nighthawkAgent = new Agent({
  name: 'NighthawkChatbot',
  instructions: 'You are a good chatbot. Route to the routing agent if routing needed.',
  handoffs: [handoff(routingAgent, { inputFilter: removeReasoningItems })],
  tools: [],
  model: 'o1', // Reasoning Model here. It will route to `routingAgent`(gpt-4.1), which is not a reasoning model
});

async function main() {
  const result = await Runner.run(nighthawkAgent, 'What should i do today? Route me to a suggestion master!');
  console.log(result.finalOutput, result.lastAgent.name);
}

main();
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

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @yusuf-eren@bakikucukcakiroglu

        Issue actions

          BUG: ResponseReasoningItem in input items causes error · Issue #29 · yusuf-eren/openai-agents-js