fix(agent-loop): rematerialize adapter defaults

This commit is contained in:
Yichen Jiang
2026-07-30 21:49:58 +08:00
parent 95824545a6
commit 5fd34f9109
47 changed files with 348 additions and 100 deletions

View File

@@ -244,7 +244,7 @@ export class DeepSeekAdapter extends LlmAdapter {
}
private async * request(options: GenerateOptions, signal: AbortSignal): AsyncIterable<StreamChunk> {
const body = serializeRequest(options, this.options.defaults, this.maxTokens)
const body = serializeRequest(options, this.options.defaults)
// Prepared outside the try so the TRANSPORT label below covers exactly the
// transport boundary, never a serialization failure.
const payload = JSON.stringify(body)

View File

@@ -137,13 +137,11 @@ export function serializeMessages(messages: Message[]): WireMessage[] {
* provider defaults apply.
* @param options - the harness request (model, history, system, tools, sampling).
* @param defaults - adapter-level thinking defaults; undefined fields put nothing on the wire.
* @param defaultMaxTokens - adapter output default used only when the request omits a cap.
* @returns the chat-completions request body.
*/
export function serializeRequest(
options: GenerateOptions,
defaults: RequestDefaults = {},
defaultMaxTokens?: number,
): WireRequest {
const messages: WireMessage[] = []
if (options.system !== undefined) {
@@ -162,7 +160,6 @@ export function serializeRequest(
// A short title budget must produce visible text; conversation and
// compaction calls continue to inherit the adapter's thinking defaults.
const resolvedThinking = resolveThinking(options, defaults)
const maxTokens = options.maxTokens ?? defaultMaxTokens
return {
model: options.model,
@@ -175,7 +172,7 @@ export function serializeRequest(
: {},
...tools !== undefined && tools.length > 0 ? { tools } : {},
...options.temperature !== undefined ? { temperature: options.temperature } : {},
...maxTokens === undefined ? {} : { max_tokens: maxTokens },
...options.maxTokens === undefined ? {} : { max_tokens: options.maxTokens },
...options.stop !== undefined ? { stop: options.stop } : {},
}
}