---
url: >-
  https://adk.nht.io/api/@nhtio/adk/batteries/llm/openai_chat_completions/helpers/functions/extractReasoningFields.md
---

# Function: extractReasoningFields()

```ts
function extractReasoningFields(
  src: Partial<Record<ReasoningField, string | null | undefined>> | undefined,
  precedence: ReasoningFieldPrecedence,
): ReasoningExtract[];
```

Defined in: [batteries/llm/openai\_chat\_completions/helpers.ts:80](https://github.com/NHTIO/ADK/blob/v1.20260605.0/src/batteries/llm/openai_chat_completions/helpers.ts#L80)

Pulls model reasoning/thinking text out of a Chat Completions response message or stream delta,
reading every wire field named in `precedence` that carries a non-empty string.

## Parameters

| Parameter    | Type                                                                                                                                                                                                                                                                                                           | Description                                                                  |
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| `src`        | | [`Partial`](https://www.typescriptlang.org/docs/handbook/utility-types.html#partialtype)<[`Record`](https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type)<[`ReasoningField`](../../types/type-aliases/ReasoningField.md), `string` | `null` | `undefined`>> | `undefined` | The response `message` or stream `delta` to read from.                       |
| `precedence` | [`ReasoningFieldPrecedence`](../../types/type-aliases/ReasoningFieldPrecedence.md)                                                                                                                                                                                                                             | Ordered, de-duplicated field names to read (see `reasoningFieldPrecedence`). |

## Returns

[`ReasoningExtract`](../../types/interfaces/ReasoningExtract.md)\[]

The present, content-deduplicated reasoning traces in precedence order.

## Remarks

Reasoning is not part of OpenAI's official Chat Completions spec, so OpenAI-compatible providers
disagree on the field name (`reasoning` for Ollama and current vLLM; `reasoning_content` for
legacy vLLM and DeepSeek). This reads the union, in `precedence` order, and de-duplicates by
content value: a field whose text exactly matches one already kept is dropped.

The result length encodes the emission rule the callers follow:

* `0` — no reasoning present.
* `1` — a single thought (covers "only one field present" AND "several present but identical").
* `≥2` — divergent fields; each surfaces as its own thought rather than silently dropping one.
