feat: add MaxTokens and Temperature options to SubagentManager and update tool loop logic
This commit is contained in:
parent
989959c2eb
commit
989b989fb0
3 changed files with 49 additions and 12 deletions
|
|
@ -119,6 +119,7 @@ func registerSharedTools(cfg *config.Config, msgBus *bus.MessageBus, registry *A
|
||||||
|
|
||||||
// Spawn tool with allowlist checker
|
// Spawn tool with allowlist checker
|
||||||
subagentManager := tools.NewSubagentManager(provider, agent.Model, agent.Workspace, msgBus)
|
subagentManager := tools.NewSubagentManager(provider, agent.Model, agent.Workspace, msgBus)
|
||||||
|
subagentManager.SetLLMOptions(agent.MaxTokens, agent.Temperature)
|
||||||
spawnTool := tools.NewSpawnTool(subagentManager)
|
spawnTool := tools.NewSpawnTool(subagentManager)
|
||||||
currentAgentID := agentID
|
currentAgentID := agentID
|
||||||
spawnTool.SetAllowlistChecker(func(targetAgentID string) bool {
|
spawnTool.SetAllowlistChecker(func(targetAgentID string) bool {
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,10 @@ type SubagentManager struct {
|
||||||
workspace string
|
workspace string
|
||||||
tools *ToolRegistry
|
tools *ToolRegistry
|
||||||
maxIterations int
|
maxIterations int
|
||||||
|
maxTokens int
|
||||||
|
temperature float64
|
||||||
|
hasMaxTokens bool
|
||||||
|
hasTemperature bool
|
||||||
nextID int
|
nextID int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,6 +51,16 @@ func NewSubagentManager(provider providers.LLMProvider, defaultModel, workspace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetLLMOptions sets max tokens and temperature for subagent LLM calls.
|
||||||
|
func (sm *SubagentManager) SetLLMOptions(maxTokens int, temperature float64) {
|
||||||
|
sm.mu.Lock()
|
||||||
|
defer sm.mu.Unlock()
|
||||||
|
sm.maxTokens = maxTokens
|
||||||
|
sm.hasMaxTokens = true
|
||||||
|
sm.temperature = temperature
|
||||||
|
sm.hasTemperature = true
|
||||||
|
}
|
||||||
|
|
||||||
// SetTools sets the tool registry for subagent execution.
|
// SetTools sets the tool registry for subagent execution.
|
||||||
// If not set, subagent will have access to the provided tools.
|
// If not set, subagent will have access to the provided tools.
|
||||||
func (sm *SubagentManager) SetTools(tools *ToolRegistry) {
|
func (sm *SubagentManager) SetTools(tools *ToolRegistry) {
|
||||||
|
|
@ -125,17 +139,29 @@ After completing the task, provide a clear summary of what was done.`
|
||||||
sm.mu.RLock()
|
sm.mu.RLock()
|
||||||
tools := sm.tools
|
tools := sm.tools
|
||||||
maxIter := sm.maxIterations
|
maxIter := sm.maxIterations
|
||||||
|
maxTokens := sm.maxTokens
|
||||||
|
temperature := sm.temperature
|
||||||
|
hasMaxTokens := sm.hasMaxTokens
|
||||||
|
hasTemperature := sm.hasTemperature
|
||||||
sm.mu.RUnlock()
|
sm.mu.RUnlock()
|
||||||
|
|
||||||
|
var llmOptions map[string]any
|
||||||
|
if hasMaxTokens || hasTemperature {
|
||||||
|
llmOptions = map[string]any{}
|
||||||
|
if hasMaxTokens {
|
||||||
|
llmOptions["max_tokens"] = maxTokens
|
||||||
|
}
|
||||||
|
if hasTemperature {
|
||||||
|
llmOptions["temperature"] = temperature
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
loopResult, err := RunToolLoop(ctx, ToolLoopConfig{
|
loopResult, err := RunToolLoop(ctx, ToolLoopConfig{
|
||||||
Provider: sm.provider,
|
Provider: sm.provider,
|
||||||
Model: sm.defaultModel,
|
Model: sm.defaultModel,
|
||||||
Tools: tools,
|
Tools: tools,
|
||||||
MaxIterations: maxIter,
|
MaxIterations: maxIter,
|
||||||
LLMOptions: map[string]any{
|
LLMOptions: llmOptions,
|
||||||
"max_tokens": 4096,
|
|
||||||
"temperature": 0.7,
|
|
||||||
},
|
|
||||||
}, messages, task.OriginChannel, task.OriginChatID)
|
}, messages, task.OriginChannel, task.OriginChatID)
|
||||||
|
|
||||||
sm.mu.Lock()
|
sm.mu.Lock()
|
||||||
|
|
@ -283,17 +309,29 @@ func (t *SubagentTool) Execute(ctx context.Context, args map[string]interface{})
|
||||||
sm.mu.RLock()
|
sm.mu.RLock()
|
||||||
tools := sm.tools
|
tools := sm.tools
|
||||||
maxIter := sm.maxIterations
|
maxIter := sm.maxIterations
|
||||||
|
maxTokens := sm.maxTokens
|
||||||
|
temperature := sm.temperature
|
||||||
|
hasMaxTokens := sm.hasMaxTokens
|
||||||
|
hasTemperature := sm.hasTemperature
|
||||||
sm.mu.RUnlock()
|
sm.mu.RUnlock()
|
||||||
|
|
||||||
|
var llmOptions map[string]any
|
||||||
|
if hasMaxTokens || hasTemperature {
|
||||||
|
llmOptions = map[string]any{}
|
||||||
|
if hasMaxTokens {
|
||||||
|
llmOptions["max_tokens"] = maxTokens
|
||||||
|
}
|
||||||
|
if hasTemperature {
|
||||||
|
llmOptions["temperature"] = temperature
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
loopResult, err := RunToolLoop(ctx, ToolLoopConfig{
|
loopResult, err := RunToolLoop(ctx, ToolLoopConfig{
|
||||||
Provider: sm.provider,
|
Provider: sm.provider,
|
||||||
Model: sm.defaultModel,
|
Model: sm.defaultModel,
|
||||||
Tools: tools,
|
Tools: tools,
|
||||||
MaxIterations: maxIter,
|
MaxIterations: maxIter,
|
||||||
LLMOptions: map[string]any{
|
LLMOptions: llmOptions,
|
||||||
"max_tokens": 4096,
|
|
||||||
"temperature": 0.7,
|
|
||||||
},
|
|
||||||
}, messages, t.originChannel, t.originChatID)
|
}, messages, t.originChannel, t.originChatID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -55,12 +55,10 @@ func RunToolLoop(ctx context.Context, config ToolLoopConfig, messages []provider
|
||||||
// 2. Set default LLM options
|
// 2. Set default LLM options
|
||||||
llmOpts := config.LLMOptions
|
llmOpts := config.LLMOptions
|
||||||
if llmOpts == nil {
|
if llmOpts == nil {
|
||||||
llmOpts = map[string]any{
|
llmOpts = map[string]any{}
|
||||||
"max_tokens": 4096,
|
|
||||||
"temperature": 0.7,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 3. Call LLM
|
// 3. Call LLM
|
||||||
response, err := config.Provider.Chat(ctx, messages, providerToolDefs, config.Model, llmOpts)
|
response, err := config.Provider.Chat(ctx, messages, providerToolDefs, config.Model, llmOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue