Skip to content

fix(routing): force tool_choice=required in OneStepForwardReasoner to eliminate format drift#1347

Merged
iceljc merged 3 commits into
SciSharp:masterfrom
ywang1110:master
May 8, 2026
Merged

fix(routing): force tool_choice=required in OneStepForwardReasoner to eliminate format drift#1347
iceljc merged 3 commits into
SciSharp:masterfrom
ywang1110:master

Conversation

@ywang1110
Copy link
Copy Markdown
Contributor

@ywang1110 ywang1110 commented May 7, 2026

Due to format drift, LLMs may complete with finishReason=stop and return free text or JSON in Content instead of a structured function call, causing instruction parsing failures in OneStepForwardReasoner.

  • Set tool_choice=required as a scoped state around the single completion call in OneStepForwardReasoner.GetNextInstruction, ensuring the LLM always returns the instruction as a function call and the state is cleaned up immediately after
  • Extract GetChatCompletionsWithScopedState helper with try/finally to guarantee state cleanup even if the completion throws
  • Parse response.FunctionArgs directly instead of Content, since tool_choice=required guarantees a function call response
  • Apply ToolChoice in PrepareOptions after tools are rendered, guarded by !options.Tools.IsNullOrEmpty() to avoid API rejection on toolless agents

@qodo-code-review
Copy link
Copy Markdown
Contributor

ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one.

@ywang1110 ywang1110 changed the title fix(routing): improve OneStepForwardReasoner instruction parsing and add logging fix(routing): force tool_choice=required in OneStepForwardReasoner to eliminate format drift May 8, 2026
@ywang1110
Copy link
Copy Markdown
Contributor Author

@Oceania2018 Ready for review. Thank you!

@iceljc iceljc merged commit dba92a2 into SciSharp:master May 8, 2026
4 checks passed
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.

3 participants