mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
394d1d1197
* fix: add MaxTokens and Temperature fields to AgentInstance and update related logic * feat: add MaxTokens and Temperature options to SubagentManager and update tool loop logic * feat: add default temperature handling and update related tests * feat: allow temperature 0 and distinguish unset * fix: format MockLLMProvider struct in subagent_tool_test.go
96 lines
2.2 KiB
Go
96 lines
2.2 KiB
Go
package agent
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/sipeed/picoclaw/pkg/config"
|
|
)
|
|
|
|
func TestNewAgentInstance_UsesDefaultsTemperatureAndMaxTokens(t *testing.T) {
|
|
tmpDir, err := os.MkdirTemp("", "agent-instance-test-*")
|
|
if err != nil {
|
|
t.Fatalf("Failed to create temp dir: %v", err)
|
|
}
|
|
defer os.RemoveAll(tmpDir)
|
|
|
|
cfg := &config.Config{
|
|
Agents: config.AgentsConfig{
|
|
Defaults: config.AgentDefaults{
|
|
Workspace: tmpDir,
|
|
Model: "test-model",
|
|
MaxTokens: 1234,
|
|
MaxToolIterations: 5,
|
|
},
|
|
},
|
|
}
|
|
|
|
configuredTemp := 1.0
|
|
cfg.Agents.Defaults.Temperature = &configuredTemp
|
|
|
|
provider := &mockProvider{}
|
|
agent := NewAgentInstance(nil, &cfg.Agents.Defaults, cfg, provider)
|
|
|
|
if agent.MaxTokens != 1234 {
|
|
t.Fatalf("MaxTokens = %d, want %d", agent.MaxTokens, 1234)
|
|
}
|
|
if agent.Temperature != 1.0 {
|
|
t.Fatalf("Temperature = %f, want %f", agent.Temperature, 1.0)
|
|
}
|
|
}
|
|
|
|
func TestNewAgentInstance_DefaultsTemperatureWhenZero(t *testing.T) {
|
|
tmpDir, err := os.MkdirTemp("", "agent-instance-test-*")
|
|
if err != nil {
|
|
t.Fatalf("Failed to create temp dir: %v", err)
|
|
}
|
|
defer os.RemoveAll(tmpDir)
|
|
|
|
cfg := &config.Config{
|
|
Agents: config.AgentsConfig{
|
|
Defaults: config.AgentDefaults{
|
|
Workspace: tmpDir,
|
|
Model: "test-model",
|
|
MaxTokens: 1234,
|
|
MaxToolIterations: 5,
|
|
},
|
|
},
|
|
}
|
|
|
|
configuredTemp := 0.0
|
|
cfg.Agents.Defaults.Temperature = &configuredTemp
|
|
|
|
provider := &mockProvider{}
|
|
agent := NewAgentInstance(nil, &cfg.Agents.Defaults, cfg, provider)
|
|
|
|
if agent.Temperature != 0.0 {
|
|
t.Fatalf("Temperature = %f, want %f", agent.Temperature, 0.0)
|
|
}
|
|
}
|
|
|
|
func TestNewAgentInstance_DefaultsTemperatureWhenUnset(t *testing.T) {
|
|
tmpDir, err := os.MkdirTemp("", "agent-instance-test-*")
|
|
if err != nil {
|
|
t.Fatalf("Failed to create temp dir: %v", err)
|
|
}
|
|
defer os.RemoveAll(tmpDir)
|
|
|
|
cfg := &config.Config{
|
|
Agents: config.AgentsConfig{
|
|
Defaults: config.AgentDefaults{
|
|
Workspace: tmpDir,
|
|
Model: "test-model",
|
|
MaxTokens: 1234,
|
|
MaxToolIterations: 5,
|
|
},
|
|
},
|
|
}
|
|
|
|
provider := &mockProvider{}
|
|
agent := NewAgentInstance(nil, &cfg.Agents.Defaults, cfg, provider)
|
|
|
|
if agent.Temperature != 0.7 {
|
|
t.Fatalf("Temperature = %f, want %f", agent.Temperature, 0.7)
|
|
}
|
|
}
|