Skip to content

fix(agent): honor sampler enable flags in Go LLM and Agent components - #20259

Merged
JinHai-CN merged 3 commits into
infiniflow:mainfrom
ekalinin:fix/agent-sampler-enabled-flags
Oct 13, 2026
Merged

JinHai-CN merged 3 commits into
infiniflow:mainfrom
ekalinin:fix/agent-sampler-enabled-flags

Conversation

@ekalinin

@ekalinin ekalinin commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The Go LLM and Agent components ignored the "enabled" switches of the LLM settings and passed sampler values the user had turned off to the model:

  • mergeAgentParam (internal/agent/component/agent.go) applied temperature and top_p unconditionally. Only maxTokensEnabled was checked.
  • The LLM component factory (internal/agent/component/llm.go) applied temperature, top_p, max_tokens, presence_penalty and frequency_penalty without checking any switch.
  • At runtime mergeLLMParam / mergeAgentParam layer the invocation inputs (upstream outputs, component debug params, sub-agent tool arguments) over the built param. A sampler value in those inputs without its switch brought back a value the DSL had turned off, including the existing maxTokensEnabled case. mergeLLMParam checked no switches at all.

Python's LLMParam.gen_conf (agent/component/llm.py, removed in #20289) only sent a value when its switch was on. The shipped templates hit this: 25 of the 26 Agent nodes in internal/agent/templates/*.json have topPEnabled: false with a top_p value, and 9 have temperatureEnabled: false, so the Go backend sent sampling parameters the Python backend did not.

Repro: an Agent node with {"top_p": 0.3, "topPEnabled": false} (or an LLM node with {"temperature": 0.2, "temperatureEnabled": false}) ends up with AgentParam.TopP / LLMParam.Temperature set on the Go side. The same happens when the switch is honoured at build time but the runtime inputs carry top_p / temperature again.

Changes

  • LLMParam / AgentParam record the switch state (TemperatureDisabled, TopPDisabled, MaxTokensDisabled, plus PresencePenaltyDisabled / FrequencyPenaltyDisabled on LLMParam).
  • gateSampler applies it in the LLM factory, mergeLLMParam and mergeAgentParam: a switch present in the inputs updates the state, and a disabled switch keeps the value nil, so a later runtime merge cannot bring it back.

A value without its switch is still applied when the DSL did not turn the switch off. This is the rule the existing maxTokensEnabled check already follows (TestAgentDisabledMaxTokens), so DSLs without the switches keep their current behaviour.

Not in scope

presence_penalty and frequency_penalty are parsed into LLMParam and the ChatInvokeRequest, but einoChatInvoker never copies them into models.ChatConfig, so they do not reach the provider. This is pre-existing and is not fixed by this PR: here they are only gated by their switches.

Tests

  • TestAgentDisabledTemperatureAndTopP (agent_test.go)
  • TestLLMFactory_DisabledSamplerParams (sampler_params_test.go)
  • TestLLM_DisabledSamplersStayOffAtRuntime (sampler_params_test.go): the ChatInvokeRequest sent by an LLM built with all switches off and invoked with sampler values in its inputs carries none of them.
  • TestAgent_DisabledSamplersStayOffAtRuntime (sampler_params_test.go): the request body an Agent sends to a stub provider has no temperature, top_p or max_tokens in the same setup.

The Go LLM and Agent components ignored the LLM-setting switches and
passed sampler values the user had turned off to the model. Python's
LLMParam.gen_conf only sends a value when its switch is on.

- mergeAgentParam: drop temperature / top_p when temperatureEnabled /
  topPEnabled is false, next to the existing maxTokensEnabled check.
- LLM factory: drop temperature, top_p, max_tokens, presence_penalty and
  frequency_penalty when the matching switch is false.

A value without its switch is still applied, the same rule the existing
maxTokensEnabled check follows, so DSLs without the switches keep their
current behaviour.
@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a5ce0f19-087d-4cc0-8e11-83fa92a81e3a

📥 Commits

Reviewing files that changed from the base of the PR and between eae2847 and cac7139.


📒 Files selected for processing (3)
  • internal/agent/component/agent.go
  • internal/agent/component/llm.go
  • internal/agent/component/sampler_params_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.



📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

LLM and Agent parameter handling now preserve disabled sampler states and clear matching values during registration or input merging. Tests cover disabled and enabled flags, runtime LLM requests, and Agent provider request bodies.

Changes

Sampler parameter handling

Layer / File(s) Summary
LLM sampler gating
internal/agent/component/llm.go, internal/agent/component/sampler_params_test.go
LLM parameters store disabled states for five sampler settings. Registration and input merging clear sampler values when those states are disabled. Tests cover factory output and runtime requests.
Agent sampler gating
internal/agent/component/agent.go, internal/agent/component/agent_test.go, internal/agent/component/sampler_params_test.go
Agent parameters store disabled states for temperature, top-p, and max tokens. Merging applies their enable flags. Tests cover merge behavior and provider request bodies.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: harry-hz-zhang


Merge Risk: ⚪ Minimal · up to cac71

No merge-blocking issue is established; the Agent temperature override remains available when enabled.

Architecture Summary

Architecture risk: 🔵 Low · up to eae28

The change affects 1 system.

Changed systems: internal

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — internal (service) was modified; 4 changed files map to changed impact.

Before / after behavior

  • observed — Modified behavior in internal/agent/component/agent_test.go: Added coverage for mergeAgentParam: temperatureEnabled: false and topPEnabled: false leave their respective values unset; values are retained when the enable flags are absent or true.
  • observed — Modified behavior in internal/agent/component/llm.go: The factory clears Temperature, TopP, or MaxTokens when the corresponding *Enabled input parses as false; previously, it retained any parsed value without checking an enable flag.
  • observed — Modified behavior in internal/agent/component/llm.go: The factory clears PresencePenalty or FrequencyPenalty when the corresponding *Enabled input parses as false; previously, it retained any parsed value without checking an enable flag.
  • observed — Modified behavior in internal/agent/component/sampler_params_test.go: Adds the standard-library maps import for cloning the test’s parameter map.

Pre-merge checks | Passed 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 4 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly and concisely states that the change makes Go LLM and Agent components honor sampler enable flags.
Description check Passed The description includes the required Summary section and clearly explains the problem, affected code, implementation, scope limits, and tests.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks each sampler’s state,
Disabled values stay out of the gate.
Temperature rests, top-p too,
Max tokens and penalties follow through.
Tests watch each request take flight.

Comment @coderabbitai help to get the list of available commands.

@JinHai-CN
JinHai-CN requested a review from 6ba3i October 8, 2026 10:24

@6ba3i 6ba3i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The fix makes sense, but there's still an issue with runtime parameter merging. Both mergeLLMParam and mergeAgentParam can reintroduce sampler values even when their enable flags are disabled. We should preserve the disabled state through runtime merging and add tests that verify the final model request.

Also, presence_penalty and frequency_penalty are parsed but never forwarded to the provider. This is pre-existing, so it can be handled separately, but it shouldn't be considered fixed by this PR.

The *Enabled checks only fired when the switch was in the same map as the
value. At runtime mergeLLMParam / mergeAgentParam layer inputs (upstream
outputs, debug params, sub-agent tool arguments) over the built param, so
a temperature / top_p / max_tokens / penalty value without its switch
brought back a value the DSL had turned off. mergeLLMParam had no checks
at all.

- Record the switch state on LLMParam / AgentParam (*Disabled fields).
- gateSampler applies it in the LLM factory, mergeLLMParam and
  mergeAgentParam: a switch present in inputs updates the state, and a
  disabled switch keeps the value nil.
- Tests check the final request: the ChatInvokeRequest for LLM and the
  provider request body for Agent.
@ekalinin

Copy link
Copy Markdown
Contributor Author

Thanks for the review, good catch. Fixed in cac7139: the switch state is now kept on the param and applied in the factory and in both runtime merges, so runtime inputs can no longer bring a disabled value back. The new tests check the final request (the ChatInvokeRequest for LLM, the provider request body for Agent).

Agreed on the penalties: I left them out of this PR and noted it in the description.

@6ba3i 6ba3i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@6ba3i 6ba3i added the ci Continue Integration label Oct 13, 2026
@JinHai-CN
JinHai-CN merged commit fb59ffc into infiniflow:main Oct 13, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants