langchain.js
    Preparing search index...

    Variable convertReasoningSummaryToResponsesReasoningItemConst

    convertReasoningSummaryToResponsesReasoningItem: BaseDynamicToolInput<
        ChatOpenAIReasoningSummary,
        OpenAIClient.Responses.ResponseReasoningItem,
    > = ...

    Converts a LangChain ChatOpenAI reasoning summary to an OpenAI Responses API reasoning item.

    This converter transforms reasoning summaries that have been accumulated during streaming (where summary parts may arrive in multiple chunks with the same index) into the final consolidated format expected by OpenAI's Responses API. It combines summary parts that share the same index and removes the index field from the final output.

    A ChatOpenAI reasoning summary object containing:

    • id: The reasoning item ID
    • type: The type of reasoning (typically "reasoning")
    • summary: Array of summary parts, each with:
      • text: The summary text content
      • type: The summary type (e.g., "summary_text")
      • index: The index used to group related summary parts during streaming

    An OpenAI Responses API ResponseReasoningItem with:

    • All properties from the input reasoning object
    • summary: Consolidated array of summary objects with:
      • text: Combined text from all parts with the same index
      • type: The summary type
      • No index field (removed after consolidation)
    // Input: Reasoning summary with multiple parts at the same index
    const reasoning = {
    id: "reasoning_123",
    type: "reasoning",
    summary: [
    { text: "First ", type: "summary_text", index: 0 },
    { text: "part", type: "summary_text", index: 0 },
    { text: "Second part", type: "summary_text", index: 1 }
    ]
    };

    const result = convertReasoningSummaryToResponsesReasoningItem(reasoning);
    // Returns:
    // {
    // id: "reasoning_123",
    // type: "reasoning",
    // summary: [
    // { text: "First part", type: "summary_text" },
    // { text: "Second part", type: "summary_text" }
    // ]
    // }
    • This converter is primarily used when reconstructing complete reasoning items from streaming chunks, where summary parts may arrive incrementally with index markers
    • Summary parts with the same index are concatenated in the order they appear
    • If the reasoning summary contains only one part, no reduction is performed
    • The index field is used internally during streaming to track which summary parts belong together, but is removed from the final output as it's not part of the OpenAI Responses API schema
    • This is the inverse operation of the streaming accumulation that happens in convertResponsesDeltaToChatGenerationChunk