The open-source agent harness - the runtime layer that turns an LLM into a working agent.
fix: switching models with reasoning enabled (#192)
Srajan Asthanaceb4064d2605
diff --git a/packages/harness/src/core/llm/LLMTypes.ts b/packages/harness/src/core/llm/LLMTypes.tsindex 790a488c9..065aea70e 100644--- a/packages/harness/src/core/llm/LLMTypes.ts+++ b/packages/harness/src/core/llm/LLMTypes.ts@@ -88,6 +88,8 @@ export const RawAssistantMessageSchema = ChatCompletionAssistantMessageParamSchethinking_blocks: z.array(ThinkingBlockUnionSchema).optional(),/** Plain-text thinking content streamed incrementally for frontend display; redundant with thinking_blocks[].thinking. */reasoning_content: z.string().optional(),+ /** Source of the message: which provider/model sent it (`provider_type/provider_name/model_name`). */+ source: z.string().optional(),}).openapi('RawAssistantMessage');@@ -97,10 +99,11 @@ export const InternalEnrichedAssistantMessageSchema = RawAssistantMessageSchema.tool_calls: z.array(InternalEnrichedToolCallSchema).optional(),});-// `thinking_blocks` omitted: kept on the internal message for Redis replay, hidden from the client event.+// `thinking_blocks` / `source` omitted: kept on the internal message for context replay, hidden from the client event.export const EnrichedAssistantMessageSchema = RawAssistantMessageSchema.omit({tool_calls: true,thinking_blocks: true,+ source: true,}).extend({tool_calls: z.array(EnrichedToolCallSchema).optional(),diff --git a/packages/harness/src/core/llm/VercelAILLM.ts b/packages/harness/src/core/llm/VercelAILLM.tsindex d6f5c444f..60f026f31 100644--- a/packages/harness/src/core/llm/VercelAILLM.ts+++ b/packages/harness/src/core/llm/VercelAILLM.ts@@ -73,7 +73,7 @@ export type VercelAIProviderName = (typeof VERCEL_AI_PROVIDER_NAMES)[number];*/export interface VercelAIProviderConfig {provider: VercelAIProviderName;- /** Display name / alias, used for logs and errors. Often provider-qualified, so never sent. */+ /** Display name / alias, used for logs and errors. Often a provider/model FQN when set by the host. */name: string;/** Provider-facing model identifier. */modelId: string;@@ -614,18 +614,32 @@ export function toUserContent(content: string | ChatCompletionContentPart[]): Us* - `'anthropic'` → `anthropic.signature`* - `'google-gemini'` → per-tool-call `google.thoughtSignature`, no standalone reasoning block* - `'custom'` → OpenAI-compatible ignores providerOptions, so the token has nowhere to go+ *+ * Signatures attach when `source` (`type/name/model`) matches both provider type and+ * provider name. Missing/foreign source → reasoning text only.*/export function toAssistantModelMessage({msg,provider,+ providerName,+ logger,}: {msg: Extract<ChatCompletionMessageParam, { role: 'assistant' }>;provider: VercelAIProviderName;+ /** Configured provider resource name (FQN prefix). */+ providerName: string;+ logger?: Logger | undefined;}): ModelMessage {const parts: AssistantContent = [];- // `thinking_blocks` is attached at runtime by AgentThread and absent from the OpenAI SDK type.+ // `thinking_blocks` / `source` are attached at runtime by AgentThread and absent from the OpenAI SDK type.const rawThinking: unknown = Reflect.get(msg, 'thinking_blocks');+ const attachSignature = shouldAttachReasoningSignature({+ source: Reflect.get(msg, 'source'),+ provider,+ providerName,+ logger,+ });// Alibaba appends replayed thinking to the visible answer, and Qwen signs nothing to preserve.if (Array.isArray(rawThinking) && provider !== 'alibaba') {// Widen any[] → unknown[] so the in-guards below narrow safely.@@ -641,7 +655,7 @@ export function toAssistantModelMessage({) {const signature = 'signature' in tb && typeof tb.signature === 'string' ? tb.signature : undefined;let reasoningProviderOptions: ProviderOptions | undefined;- if (signature !== undefined) {+ if (signature !== undefined && attachSignature) {if (provider === 'openai') {reasoningProviderOptions = { openai: { reasoningEncryptedContent: signature } };} else if (provider === 'anthropic') {@@ -711,6 +725,44 @@ export function toAssistantModelMessage({};}+/** Parse `provider_type/provider_name/model_name`. */+function parseAssistantMessageSource(+ source: string,+): { providerType: string; providerName: string; modelName: string } | undefined {+ const [providerType, providerName, modelName, ...rest] = source.split('/');+ if (rest.length > 0 || !providerType || !providerName || !modelName) {+ return undefined;+ }+ return { providerType, providerName, modelName };+}++/** Attach when both provider type and configured provider name match `source`. */+export function shouldAttachReasoningSignature({+ source,+ provider,+ providerName,+ logger,+}: {+ source: unknown;+ provider: VercelAIProviderName;+ providerName: string;+ logger?: Logger | undefined;+}): boolean {+ if (source === undefined) {+ return false;+ }+ if (typeof source !== 'string') {+ logger?.warn('Ignoring non-string assistant message source; skipping reasoning signature replay', { source });+ return false;+ }+ const parsed = parseAssistantMessageSource(source);+ if (parsed === undefined) {+ logger?.warn('Ignoring malformed assistant message source; skipping reasoning signature replay', { source });+ return false;+ }+ return parsed.providerType === provider && parsed.providerName === providerName;+}+export interface ConvertedMessages {instructions: string | undefined;messages: ModelMessage[];@@ -724,9 +776,13 @@ export interface ConvertedMessages {export function convertMessages({messages,provider,+ providerName,+ logger,}: {messages: ChatCompletionMessageParam[];provider: VercelAIProviderName;+ providerName: string;+ logger?: Logger | undefined;}): ConvertedMessages {const toolNameById = new Map<string, string>();for (const msg of messages) {@@ -753,7 +809,7 @@ export function convertMessages({continue;}if (msg.role === 'assistant') {- result.push(toAssistantModelMessage({ msg, provider }));+ result.push(toAssistantModelMessage({ msg, provider, providerName, logger }));continue;}if (msg.role === 'tool') {@@ -1282,6 +1338,18 @@ export async function* mapStreamToChunks({return { usage: finalUsage, output, finish_reason: finalFinishReason };}+/** Split `provider/model` FQN. Returns undefined when the shape is not exactly one slash. */+function parseModelFqn(name: string): { providerName: string; modelName: string } | undefined {+ const slash = name.indexOf('/');+ if (slash <= 0 || slash === name.length - 1) {+ return undefined;+ }+ if (name.includes('/', slash + 1)) {+ return undefined;+ }+ return { providerName: name.slice(0, slash), modelName: name.slice(slash + 1) };+}+// ---------------------------------------------------------------------------// VercelAILLM// ---------------------------------------------------------------------------@@ -1303,8 +1371,15 @@ export class VercelAILLM implements ILLM {): AsyncGenerator<ExtendedChatCompletionChunk, RawAssistantMessageWithUsage, unknown> {const { providerConfig } = this.config;const model = buildLanguageModel(providerConfig);-- const { instructions, messages } = convertMessages({ messages: body.messages, provider: providerConfig.provider });+ const parsedFqn = parseModelFqn(providerConfig.name);+ const providerName = parsedFqn?.providerName ?? providerConfig.provider;++ const { instructions, messages } = convertMessages({+ messages: body.messages,+ provider: providerConfig.provider,+ providerName,+ logger: this.logger,+ });const tools = convertTools(body.tools ?? undefined);const structuredOutputSpec = toStructuredOutputSpec(body.response_format);const output = buildOutput(structuredOutputSpec);@@ -1383,7 +1458,11 @@ export class VercelAILLM implements ILLM {};try {- return yield* mapStreamToChunks({ stream: streamResult.stream, chunkMeta });+ const result = yield* mapStreamToChunks({ stream: streamResult.stream, chunkMeta });+ if (parsedFqn) {+ result.output.source = `${providerConfig.provider}/${parsedFqn.providerName}/${parsedFqn.modelName}`;+ }+ return result;} catch (error) {if (this.signal?.aborted) {this.logger.debug('LLM stream aborted', extractErrorLogFields(error));diff --git a/packages/harness/src/core/runtime/AgentThread.ts b/packages/harness/src/core/runtime/AgentThread.tsindex 98caa91e5..8445a3819 100644--- a/packages/harness/src/core/runtime/AgentThread.ts+++ b/packages/harness/src/core/runtime/AgentThread.ts@@ -227,10 +227,11 @@ function buildModelMessageEvent({usage: ModelMessageUsage | undefined;id: string;}): ModelMessageEvent {- // `thinking_blocks` is persisted to the Redis context for replay; strip it from the client event.- const { role, tool_calls, thinking_blocks, ...rest } = assistantMessage;+ // `thinking_blocks` / `source` stay on the context message for replay; strip them from the client event.+ const { role, tool_calls, thinking_blocks, source, ...rest } = assistantMessage;void role;void thinking_blocks;+ void source;const event: ModelMessageEvent = {...rest,tool_calls: tool_calls?.map(toEnrichedToolCall),diff --git a/packages/harness/tests/core/llm/VercelAILLM.messages.test.ts b/packages/harness/tests/core/llm/VercelAILLM.messages.test.tsindex 85eb37b4d..589a28004 100644--- a/packages/harness/tests/core/llm/VercelAILLM.messages.test.ts+++ b/packages/harness/tests/core/llm/VercelAILLM.messages.test.ts@@ -8,6 +8,7 @@ import {convertMessages,convertTools,parseMimeFromDataUri,+ shouldAttachReasoningSignature,toAssistantModelMessage,toFilePart,toUserContent,@@ -121,7 +122,7 @@ describe('toAssistantModelMessage', () => {role: 'assistant',content: 'hello',};- const result = toAssistantModelMessage({ msg: msg, provider: 'google-gemini' });+ const result = toAssistantModelMessage({ msg: msg, provider: 'google-gemini', providerName: 'google-gemini' });expect(result.role).toBe('assistant');expect(result.content).toEqual([{ type: 'text', text: 'hello' }]);});@@ -134,7 +135,7 @@ describe('toAssistantModelMessage', () => {{ type: 'text', text: 'b' },],};- const result = toAssistantModelMessage({ msg: msg, provider: 'google-gemini' });+ const result = toAssistantModelMessage({ msg: msg, provider: 'google-gemini', providerName: 'google-gemini' });expect(result.content).toEqual([{ type: 'text', text: 'ab' }]);});@@ -143,7 +144,7 @@ describe('toAssistantModelMessage', () => {role: 'assistant',content: null,};- const result = toAssistantModelMessage({ msg: msg, provider: 'google-gemini' });+ const result = toAssistantModelMessage({ msg: msg, provider: 'google-gemini', providerName: 'google-gemini' });expect(result.content).toEqual([{ type: 'text', text: '' }]);});@@ -153,7 +154,7 @@ describe('toAssistantModelMessage', () => {content: null,tool_calls: [{ id: 'call-1', type: 'function', function: { name: 'my_tool', arguments: '{"x":1}' } }],};- const result = toAssistantModelMessage({ msg: msg, provider: 'google-gemini' });+ const result = toAssistantModelMessage({ msg: msg, provider: 'google-gemini', providerName: 'google-gemini' });const toolCallPart = (result.content as Array<{ type: string }>).find(p => p.type === 'tool-call');expect(toolCallPart).toMatchObject({type: 'tool-call',@@ -169,7 +170,7 @@ describe('toAssistantModelMessage', () => {content: null,tool_calls: [{ id: 'call-2', type: 'function', function: { name: 'bad', arguments: 'not-json' } }],};- const result = toAssistantModelMessage({ msg: msg, provider: 'google-gemini' });+ const result = toAssistantModelMessage({ msg: msg, provider: 'google-gemini', providerName: 'google-gemini' });const toolCallPart = (result.content as Array<{ type: string; input?: unknown }>).find(p => p.type === 'tool-call');expect(toolCallPart?.input).toEqual({});});@@ -180,8 +181,9 @@ describe('toAssistantModelMessage', () => {content: null,};Reflect.set(msg, 'thinking_blocks', [{ type: 'thinking', thinking: 'step one', signature: 'sig-openai' }]);+ Reflect.set(msg, 'source', 'openai/openai/test');- const result = toAssistantModelMessage({ msg: msg, provider: 'openai' });+ const result = toAssistantModelMessage({ msg: msg, provider: 'openai', providerName: 'openai' });const reasoningPart = (result.content as Array<{ type: string; text?: string; providerOptions?: unknown }>).find(p => p.type === 'reasoning',);@@ -196,8 +198,9 @@ describe('toAssistantModelMessage', () => {content: null,};Reflect.set(msg, 'thinking_blocks', [{ type: 'thinking', thinking: 'step two', signature: 'sig-ant' }]);+ Reflect.set(msg, 'source', 'anthropic/anthropic/test');- const result = toAssistantModelMessage({ msg: msg, provider: 'anthropic' });+ const result = toAssistantModelMessage({ msg: msg, provider: 'anthropic', providerName: 'anthropic' });const reasoningPart = (result.content as Array<{ type: string; providerOptions?: unknown }>).find(p => p.type === 'reasoning',);@@ -211,7 +214,7 @@ describe('toAssistantModelMessage', () => {};Reflect.set(msg, 'thinking_blocks', [{ type: 'thinking', thinking: 'step', signature: 'sig-gen' }]);- const result = toAssistantModelMessage({ msg: msg, provider: 'custom' });+ const result = toAssistantModelMessage({ msg: msg, provider: 'custom', providerName: 'custom' });const reasoningPart = (result.content as Array<{ type: string; text?: string; providerOptions?: unknown }>).find(p => p.type === 'reasoning',);@@ -227,7 +230,7 @@ describe('toAssistantModelMessage', () => {};Reflect.set(msg, 'thinking_blocks', [{ type: 'thinking', thinking: 'step', signature: 'sig' }]);- const result = toAssistantModelMessage({ msg: msg, provider: 'google-gemini' });+ const result = toAssistantModelMessage({ msg: msg, provider: 'google-gemini', providerName: 'google-gemini' });const reasoningPart = (result.content as Array<{ type: string; providerOptions?: unknown }>).find(p => p.type === 'reasoning',);@@ -244,7 +247,7 @@ describe('toAssistantModelMessage', () => {tool_calls: [toolCall],};- const result = toAssistantModelMessage({ msg: msg, provider: 'google-gemini' });+ const result = toAssistantModelMessage({ msg: msg, provider: 'google-gemini', providerName: 'google-gemini' });const toolCallPart = (result.content as Array<{ type: string; providerOptions?: unknown }>).find(p => p.type === 'tool-call',);@@ -258,10 +261,88 @@ describe('toAssistantModelMessage', () => {tool_calls: [{ id: 'call-1', type: 'function', function: { name: 'fn', arguments: '{}' } }],};- const result = toAssistantModelMessage({ msg: msg, provider: 'google-gemini' });+ const result = toAssistantModelMessage({ msg: msg, provider: 'google-gemini', providerName: 'google-gemini' });const toolCallPart = (result.content as Array<{ type: string }>).find(p => p.type === 'tool-call');expect(toolCallPart).not.toHaveProperty('providerOptions');});++ it('attaches signature when source type and provider name match, ignoring model_name', () => {+ const msg: Extract<ChatCompletionMessageParam, { role: 'assistant' }> = {+ role: 'assistant',+ content: null,+ };+ Reflect.set(msg, 'thinking_blocks', [{ type: 'thinking', thinking: 'step', signature: 'sig' }]);+ Reflect.set(msg, 'source', 'openai/openai/old-model');++ const result = toAssistantModelMessage({ msg: msg, provider: 'openai', providerName: 'openai' });+ const reasoningPart = (result.content as Array<{ type: string; providerOptions?: unknown }>).find(+ p => p.type === 'reasoning',+ );+ expect(reasoningPart?.providerOptions).toEqual({ openai: { reasoningEncryptedContent: 'sig' } });+ });++ it('omits signature providerOptions when source provider type differs', () => {+ const msg: Extract<ChatCompletionMessageParam, { role: 'assistant' }> = {+ role: 'assistant',+ content: null,+ };+ Reflect.set(msg, 'thinking_blocks', [{ type: 'thinking', thinking: 'step', signature: 'ant-sig' }]);+ Reflect.set(msg, 'source', 'anthropic/anthropic/opus');++ const result = toAssistantModelMessage({ msg: msg, provider: 'openai', providerName: 'openai' });+ const reasoningPart = (result.content as Array<{ type: string; text?: string; providerOptions?: unknown }>).find(+ p => p.type === 'reasoning',+ );+ expect(reasoningPart?.text).toBe('step');+ expect(reasoningPart).not.toHaveProperty('providerOptions');+ });++ it('requires matching provider name for any provider type', () => {+ expect(+ shouldAttachReasoningSignature({+ source: 'custom/gateway-a/model',+ provider: 'custom',+ providerName: 'gateway-a',+ }),+ ).toBe(true);+ expect(+ shouldAttachReasoningSignature({+ source: 'custom/gateway-a/model',+ provider: 'custom',+ providerName: 'gateway-b',+ }),+ ).toBe(false);+ expect(+ shouldAttachReasoningSignature({+ source: 'openai/other-name/model',+ provider: 'openai',+ providerName: 'openai',+ }),+ ).toBe(false);+ });++ it('does not attach when provider type differs even if provider_name matches', () => {+ expect(+ shouldAttachReasoningSignature({+ source: 'openai/shared/model',+ provider: 'anthropic',+ providerName: 'shared',+ }),+ ).toBe(false);+ });++ it('omits signature providerOptions when source is missing', () => {+ const msg: Extract<ChatCompletionMessageParam, { role: 'assistant' }> = {+ role: 'assistant',+ content: null,+ };+ Reflect.set(msg, 'thinking_blocks', [{ type: 'thinking', thinking: 'step', signature: 'sig' }]);++ const result = toAssistantModelMessage({ msg: msg, provider: 'openai', providerName: 'openai' });+ const reasoningPart = (result.content as Array<{ type: string; text?: string }>).find(p => p.type === 'reasoning');+ expect(reasoningPart?.text).toBe('step');+ expect(reasoningPart).not.toHaveProperty('providerOptions');+ });});// ─────────── convertMessages ───────────@@ -273,7 +354,11 @@ describe('convertMessages', () => {{ role: 'system', content: 'Prompt B' },{ role: 'user', content: 'hi' },];- const { instructions, messages: result } = convertMessages({ messages: messages, provider: 'google-gemini' });+ const { instructions, messages: result } = convertMessages({+ messages: messages,+ provider: 'google-gemini',+ providerName: 'google-gemini',+ });expect(instructions).toBe('Prompt A\n\nPrompt B');expect(result).toHaveLength(1);expect(result[0]).toMatchObject({ role: 'user' });@@ -283,6 +368,7 @@ describe('convertMessages', () => {const { instructions } = convertMessages({messages: [{ role: 'user', content: 'hi' }],provider: 'google-gemini',+ providerName: 'google-gemini',});expect(instructions).toBeUndefined();});@@ -297,7 +383,11 @@ describe('convertMessages', () => {},{ role: 'tool', tool_call_id: 'c1', content: 'result' },];- const { messages: result } = convertMessages({ messages: messages, provider: 'google-gemini' });+ const { messages: result } = convertMessages({+ messages: messages,+ provider: 'google-gemini',+ providerName: 'google-gemini',+ });expect(result).toHaveLength(3);expect(result[0]?.role).toBe('user');expect(result[1]?.role).toBe('assistant');@@ -313,14 +403,22 @@ describe('convertMessages', () => {},{ role: 'tool', tool_call_id: 'c1', content: 'found it' },];- const { messages: result } = convertMessages({ messages: messages, provider: 'google-gemini' });+ const { messages: result } = convertMessages({+ messages: messages,+ provider: 'google-gemini',+ providerName: 'google-gemini',+ });const toolMsg = result.find(m => m.role === 'tool');expect(toolMsg?.content).toEqual([expect.objectContaining({ toolName: 'search' })]);});it('falls back to empty string toolName for unresolvable tool_call_id', () => {const messages: ChatCompletionMessageParam[] = [{ role: 'tool', tool_call_id: 'unknown-id', content: 'data' }];- const { messages: result } = convertMessages({ messages: messages, provider: 'google-gemini' });+ const { messages: result } = convertMessages({+ messages: messages,+ provider: 'google-gemini',+ providerName: 'google-gemini',+ });expect(result[0]?.content).toEqual([expect.objectContaining({ toolName: '' })]);});@@ -330,7 +428,11 @@ describe('convertMessages', () => {// eslint-disable-next-line @typescript-eslint/no-explicit-any -- simulating unrecognised roles at runtime{ role: 'developer', content: 'internal' } as any,];- const { messages: result } = convertMessages({ messages: messages, provider: 'google-gemini' });+ const { messages: result } = convertMessages({+ messages: messages,+ provider: 'google-gemini',+ providerName: 'google-gemini',+ });expect(result).toHaveLength(1);expect(result[0]?.role).toBe('user');});@@ -338,8 +440,9 @@ describe('convertMessages', () => {it('threads the provider into assistant message reasoning parts', () => {const msg: ChatCompletionMessageParam = { role: 'assistant', content: null };Reflect.set(msg, 'thinking_blocks', [{ type: 'thinking', thinking: 'thought', signature: 'sig' }]);+ Reflect.set(msg, 'source', 'anthropic/anthropic/test');- const { messages: result } = convertMessages({ messages: [msg], provider: 'anthropic' });+ const { messages: result } = convertMessages({ messages: [msg], provider: 'anthropic', providerName: 'anthropic' });const assistantMsg = result.find(m => m.role === 'assistant');const reasoningPart = (assistantMsg?.content as Array<{ type: string; providerOptions?: unknown }> | undefineddiff --git a/packages/harness/tests/core/llm/VercelAILLM.replay.test.ts b/packages/harness/tests/core/llm/VercelAILLM.replay.test.tsindex fe96e4e7a..2ad2eef1c 100644--- a/packages/harness/tests/core/llm/VercelAILLM.replay.test.ts+++ b/packages/harness/tests/core/llm/VercelAILLM.replay.test.ts@@ -98,7 +98,11 @@ describe('Gemini tool thoughtSignature replay round-trip', () => {content: null,...(output.tool_calls !== undefined ? { tool_calls: output.tool_calls } : {}),};- const replayMsg = toAssistantModelMessage({ msg: assistantMsg, provider: 'google-gemini' });+ const replayMsg = toAssistantModelMessage({+ msg: assistantMsg,+ provider: 'google-gemini',+ providerName: 'google-gemini',+ });const toolCallPart = (replayMsg.content as Array<{ type: string; providerOptions?: unknown }>).find(p => p.type === 'tool-call',);@@ -124,7 +128,11 @@ describe('Gemini tool thoughtSignature replay round-trip', () => {content: null,...(output.tool_calls !== undefined ? { tool_calls: output.tool_calls } : {}),};- const replayMsg = toAssistantModelMessage({ msg: assistantMsg, provider: 'google-gemini' });+ const replayMsg = toAssistantModelMessage({+ msg: assistantMsg,+ provider: 'google-gemini',+ providerName: 'google-gemini',+ });const toolCallPart = (replayMsg.content as Array<{ type: string }>).find(p => p.type === 'tool-call');expect(toolCallPart).not.toHaveProperty('providerOptions');});@@ -201,8 +209,9 @@ describe.each(REASONING_CASES)(content: null,};Reflect.set(assistantMsg, 'thinking_blocks', output.thinking_blocks);+ Reflect.set(assistantMsg, 'source', `${provider}/${provider}/test`);- const replayMsg = toAssistantModelMessage({ msg: assistantMsg, provider });+ const replayMsg = toAssistantModelMessage({ msg: assistantMsg, provider, providerName: provider });const reasoningPart = (replayMsg.content as Array<{ type: string; providerOptions?: unknown }>).find(p => p.type === 'reasoning',);@@ -236,7 +245,9 @@ describe('anthropic reasoning replay, on the shape Anthropic actually sends', ()...(output.tool_calls !== undefined ? { tool_calls: output.tool_calls } : {}),};Reflect.set(assistantMsg, 'thinking_blocks', output.thinking_blocks);- const parts = toAssistantModelMessage({ msg: assistantMsg, provider: 'anthropic' }).content as Array<{+ Reflect.set(assistantMsg, 'source', 'anthropic/anthropic/test');+ const parts = toAssistantModelMessage({ msg: assistantMsg, provider: 'anthropic', providerName: 'anthropic' })+ .content as Array<{type: string;providerOptions?: unknown;}>;@@ -244,6 +255,39 @@ describe('anthropic reasoning replay, on the shape Anthropic actually sends', ()expect(parts.map(p => p.type)).toEqual(['reasoning', 'tool-call']);expect(parts[0]?.providerOptions).toEqual({ anthropic: { signature: 'ant-delta' } });});++ it('does not attach an Anthropic signature when replaying to OpenAI', async () => {+ const { output } = await drainStream(+ mapStreamToChunks({+ stream: makeStream([+ { type: 'reasoning-start', id: 'r1' },+ { type: 'reasoning-delta', id: 'r1', text: 'thought' },+ { type: 'reasoning-delta', id: 'r1', text: '', providerMetadata: { anthropic: { signature: 'ant-sig' } } },+ { type: 'reasoning-end', id: 'r1' },+ makeFinishStep('stop'),+ ]),+ chunkMeta: CHUNK_META,+ }),+ );++ const assistantMsg: Extract<ChatCompletionMessageParam, { role: 'assistant' }> = {+ role: 'assistant',+ content: null,+ };+ Reflect.set(assistantMsg, 'thinking_blocks', output.thinking_blocks);+ Reflect.set(assistantMsg, 'source', 'anthropic/anthropic/opus');++ const reasoningPart = (+ toAssistantModelMessage({ msg: assistantMsg, provider: 'openai', providerName: 'openai' }).content as Array<{+ type: string;+ text?: string;+ providerOptions?: unknown;+ }>+ ).find(p => p.type === 'reasoning');++ expect(reasoningPart?.text).toBe('thought');+ expect(reasoningPart).not.toHaveProperty('providerOptions');+ });});describe('google-gemini reasoning replay round-trip', () => {@@ -272,7 +316,11 @@ describe('google-gemini reasoning replay round-trip', () => {};Reflect.set(assistantMsg, 'thinking_blocks', output.thinking_blocks);- const replayMsg = toAssistantModelMessage({ msg: assistantMsg, provider: 'google-gemini' });+ const replayMsg = toAssistantModelMessage({+ msg: assistantMsg,+ provider: 'google-gemini',+ providerName: 'google-gemini',+ });const reasoningPart = (replayMsg.content as Array<{ type: string }>).find(p => p.type === 'reasoning');expect(reasoningPart).toBeDefined();expect(reasoningPart).not.toHaveProperty('providerOptions');diff --git a/packages/harness/tests/core/llm/toOpenAIChatMessage.test.ts b/packages/harness/tests/core/llm/toOpenAIChatMessage.test.tsindex 808c0afef..a20251ba4 100644--- a/packages/harness/tests/core/llm/toOpenAIChatMessage.test.ts+++ b/packages/harness/tests/core/llm/toOpenAIChatMessage.test.ts@@ -32,6 +32,7 @@ function makeAssistantWithReplayFields(): InternalEnrichedAssistantMessage {{ type: 'redacted_thinking', data: 'redacted-blob' },],reasoning_content: 'plain reasoning',+ source: 'anthropic/anthropic/opus',tool_calls: [{id: 'call-1',@@ -53,6 +54,7 @@ describe('toOpenAIChatMessage', () => {expect(mapped['content']).toBe('hello');expect(mapped['thinking_blocks']).toEqual(msg.thinking_blocks);expect(mapped['reasoning_content']).toBe('plain reasoning');+ expect(mapped['source']).toBe('anthropic/anthropic/opus');const toolCalls = mapped['tool_calls'] as Record<string, unknown>[];expect(toolCalls).toHaveLength(1);