Skip to content

feat(ai): auto-strip <think> reasoning tags in OpenAI adapter#47

Merged
best merged 1 commit into
masterfrom
feature/strip-think-tags
Feb 23, 2026
Merged

feat(ai): auto-strip <think> reasoning tags in OpenAI adapter#47
best merged 1 commit into
masterfrom
feature/strip-think-tags

Conversation

@best
Copy link
Copy Markdown
Contributor

@best best commented Feb 23, 2026

Summary

  • Add stripThinkTags() utility to strip <think>...</think> reasoning blocks from model output (handles multiple blocks, unclosed tags, case-insensitive matching)
  • Integrate into OpenAIAdapter.doGenerate() — strips think tags from response.text and extracts reasoning into optional response.reasoning field
  • Add ReasoningDelta stream event type and integrate into parseSSEStream() — think content is emitted as reasoning_delta events instead of text_delta
  • Add optional reasoning field to ModelResponse type
  • Export stripThinkTags, StripThinkTagsResult, and ReasoningDelta from package index

Test plan

  • 12 unit tests for stripThinkTags() utility (single block, multiple blocks, unclosed tag, case-insensitive, multiline, empty, whitespace-only, etc.)
  • 5 integration tests for doGenerate() (strips tags, no tags, null content, all-reasoning content, generateWithTools)
  • 3 integration tests for streaming (reasoning_delta events, no think tags, tags split across chunks)
  • pnpm test — all 1018 tests pass (70 files, 0 failures)
  • pnpm --filter @openlinkos/ai typecheck — passes

Closes #45

Models like DeepSeek emit <think>...</think> blocks containing
chain-of-thought reasoning. This commit strips those tags from
response text and exposes the reasoning content separately:

- Add stripThinkTags() utility for non-streaming responses
- Add optional `reasoning` field to ModelResponse type
- Add ReasoningDelta stream event type for streaming responses
- Handle edge cases: multiple blocks, unclosed tags, case-insensitive
- 20 new unit tests covering utility, generate, and stream paths

Closes #45
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Code Review

Automated review for PR #47informational only, does not block merge.

Checklist

Item Notes
⚠️ Type Safety 2 use(s) of any detected
⚠️ Error Handling async code added without visible error handling
Test Coverage 1 test file(s) updated
⚠️ API Consistency 4 new export(s) added; 1 export(s) removed — potential breaking change
⚠️ Breaking Changes Public exports removed; check downstream consumers

Stats

  • 📁 Files changed: 5 (5 TypeScript)
  • ➕ Lines added: 535
  • 🧪 Test files updated: 1

4 check(s) need attention.

Powered by openlinkos/agent · AI PR Review workflow

@best best merged commit a9d7616 into master Feb 23, 2026
5 checks passed
@best best deleted the feature/strip-think-tags branch February 23, 2026 04:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Auto-strip <think> reasoning tags in OpenAI adapter

1 participant