Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix: unable to pass Temperature and MaxTokens in agent (#18223)

Haruko386a6f2eac4965f
diff --git a/internal/agent/component/agent.go b/internal/agent/component/agent.go
index 1ac7847dc6..60542569e5 100644
--- a/internal/agent/component/agent.go
+++ b/internal/agent/component/agent.go
@@ -82,7 +82,9 @@ type AgentParam struct {
SystemPrompt string
UserPrompt string
Thinking string
+ MaxTokens *int
TopP *float64
+ Temperature *float64
Tools []string // Agent-visible tool names resolved into Eino BaseTool instances
ToolParams map[string]map[string]any // node-level tool constructor params keyed by tool name
SubAgents []SubAgentTool
@@ -1041,15 +1043,14 @@ func buildAgentChatModel(ctx context.Context, p AgentParam) (*models.EinoChatMod
apiKey := p.APIKey
cfg := &models.APIConfig{ApiKey: &apiKey}
cm := models.NewChatModel(d, &modelID, cfg)
- // ChatConfig construction is conditional on TopP being set, unlike
- // the LLM path which always builds a ChatConfig (Temperature/MaxTokens
- // pass-through). The asymmetry is intentional: AgentParam has no
- // Temperature/MaxTokens yet, so building a zero-config ChatConfig
- // would be dead weight. When AgentParam grows Temperature/
- // MaxTokens, switch to always-build.
+ // Build ChatConfig when a generation parameter or Thinking is set.
var chatCfg *models.ChatConfig
- if p.TopP != nil || p.Thinking != "" {
- chatCfg = &models.ChatConfig{TopP: p.TopP}
+ if p.TopP != nil || p.Thinking != "" || p.MaxTokens != nil || p.Temperature != nil {
+ chatCfg = &models.ChatConfig{
+ TopP: p.TopP,
+ MaxTokens: p.MaxTokens,
+ Temperature: p.Temperature,
+ }
switch p.Thinking {
case "enabled":
t := true
@@ -1370,6 +1371,14 @@ func mergeAgentParam(base AgentParam, inputs map[string]any) AgentParam {
f := v
p.TopP = &f
}
+ if v, ok := intFrom(inputs, "max_tokens"); ok {
+ f := v
+ p.MaxTokens = &f
+ }
+ if v, ok := floatFrom(inputs, "temperature"); ok {
+ f := v
+ p.Temperature = &f
+ }
if v, ok := stringFrom(inputs, "thinking"); ok && v != "" && v != "default" {
p.Thinking = v
}