Repository navigation
fix(agent): honor sampler enable flags in Go LLM and Agent components - #20259
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to No merge-blocking issue is established; the Agent temperature override remains available when enabled. Architecture SummaryArchitecture risk: 🔵 Low · up to The change affects 1 system. Changed systems: Architecture concerns Review details
Pre-merge checks |
|
6ba3i
left a comment
There was a problem hiding this comment.
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.
|
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 Agreed on the penalties: I left them out of this PR and noted it in the description. |
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) appliedtemperatureandtop_punconditionally. OnlymaxTokensEnabledwas checked.LLMcomponent factory (internal/agent/component/llm.go) appliedtemperature,top_p,max_tokens,presence_penaltyandfrequency_penaltywithout checking any switch.mergeLLMParam/mergeAgentParamlayer 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 existingmaxTokensEnabledcase.mergeLLMParamchecked 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 ininternal/agent/templates/*.jsonhavetopPEnabled: falsewith atop_pvalue, and 9 havetemperatureEnabled: 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 withAgentParam.TopP/LLMParam.Temperatureset on the Go side. The same happens when the switch is honoured at build time but the runtime inputs carrytop_p/temperatureagain.Changes
LLMParam/AgentParamrecord the switch state (TemperatureDisabled,TopPDisabled,MaxTokensDisabled, plusPresencePenaltyDisabled/FrequencyPenaltyDisabledonLLMParam).gateSamplerapplies it in the LLM factory,mergeLLMParamandmergeAgentParam: 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
maxTokensEnabledcheck already follows (TestAgentDisabledMaxTokens), so DSLs without the switches keep their current behaviour.Not in scope
presence_penaltyandfrequency_penaltyare parsed intoLLMParamand theChatInvokeRequest, buteinoChatInvokernever copies them intomodels.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): theChatInvokeRequestsent 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 notemperature,top_pormax_tokensin the same setup.