Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"model": "glm-4.7",
"max_tokens": 8192,
"temperature": 0.7,
"max_tool_iterations": 20
"max_tool_iterations": 20,
"timeout": 120
}
},
"channels": {
Expand Down
8 changes: 7 additions & 1 deletion pkg/agent/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type AgentLoop struct {
contextBuilder *ContextBuilder
tools *tools.ToolRegistry
running atomic.Bool
timeout int
summarizing sync.Map // Tracks which sessions are currently being summarized
}

Expand Down Expand Up @@ -143,6 +144,7 @@ func NewAgentLoop(cfg *config.Config, msgBus *bus.MessageBus, provider providers
maxIterations: cfg.Agents.Defaults.MaxToolIterations,
sessions: sessionsManager,
state: stateManager,
timeout: cfg.Agents.Defaults.Timeout,
contextBuilder: contextBuilder,
tools: toolsRegistry,
summarizing: sync.Map{},
Expand Down Expand Up @@ -674,7 +676,11 @@ func formatToolsForLog(tools []providers.ToolDefinition) string {

// summarizeSession summarizes the conversation history for a session.
func (al *AgentLoop) summarizeSession(sessionKey string) {
ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
summarizeTimeout := al.timeout
if summarizeTimeout <= 0 {
summarizeTimeout = 120
}
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(summarizeTimeout)*time.Second)
defer cancel()

history := al.sessions.GetHistory(sessionKey)
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type AgentDefaults struct {
MaxTokens int `json:"max_tokens" env:"PICOCLAW_AGENTS_DEFAULTS_MAX_TOKENS"`
Temperature float64 `json:"temperature" env:"PICOCLAW_AGENTS_DEFAULTS_TEMPERATURE"`
MaxToolIterations int `json:"max_tool_iterations" env:"PICOCLAW_AGENTS_DEFAULTS_MAX_TOOL_ITERATIONS"`
Timeout int `json:"timeout" env:"PICOCLAW_AGENTS_DEFAULTS_TIMEOUT"`
}

type ChannelsConfig struct {
Expand Down Expand Up @@ -225,6 +226,7 @@ func DefaultConfig() *Config {
MaxTokens: 8192,
Temperature: 0.7,
MaxToolIterations: 20,
Timeout: 120,
},
},
Channels: ChannelsConfig{
Expand Down
9 changes: 6 additions & 3 deletions pkg/providers/http_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ type HTTPProvider struct {
httpClient *http.Client
}

func NewHTTPProvider(apiKey, apiBase, proxy string) *HTTPProvider {
func NewHTTPProvider(apiKey, apiBase, proxy string, timeout int) *HTTPProvider {
if timeout <= 0 {
timeout = 120
}
client := &http.Client{
Timeout: 120 * time.Second,
Timeout: time.Duration(timeout) * time.Second,
}

if proxy != "" {
Expand Down Expand Up @@ -429,5 +432,5 @@ func CreateProvider(cfg *config.Config) (LLMProvider, error) {
return nil, fmt.Errorf("no API base configured for provider (model: %s)", model)
}

return NewHTTPProvider(apiKey, apiBase, proxy), nil
return NewHTTPProvider(apiKey, apiBase, proxy, cfg.Agents.Defaults.Timeout), nil
}