on main help sign in
perf: init coder agent in a goroutine (#1289)
f172aaaCarlos Alexandro Becker
internal/agent/coordinator.go+20−5
@@ -289,11 +289,26 @@ func (c *coordinator) buildAgent(ctx context.Context, prompt *prompt.Prompt, age
289 }
289 }
290
290
291 largeProviderCfg, _ := c.cfg.Providers.Get(large.ModelCfg.Provider)
291 largeProviderCfg, _ := c.cfg.Providers.Get(large.ModelCfg.Provider)
292− tools, err := c.buildTools(ctx, agent)
292+ result := NewSessionAgent(SessionAgentOptions{
293− if err != nil {
293+ large,
294− return nil, err
294+ small,
295− }
295+ largeProviderCfg.SystemPromptPrefix,
296− return NewSessionAgent(SessionAgentOptions{large, small, largeProviderCfg.SystemPromptPrefix, systemPrompt, c.cfg.Options.DisableAutoSummarize, c.permissions.SkipRequests(), c.sessions, c.messages, tools}), nil
296+ systemPrompt,
297+ c.cfg.Options.DisableAutoSummarize,
298+ c.permissions.SkipRequests(),
299+ c.sessions,
300+ c.messages,
301+ nil,
302+ })
303+ go func() {
304+ tools, err := c.buildTools(ctx, agent)
305+ if err != nil {
306+ slog.Error("could not init agent tools", "err", err)
307+ return
308+ }
309+ result.SetTools(tools)
310+ }()
311+ return result, nil
297}
312}
298
313
299func (c *coordinator) buildTools(ctx context.Context, agent config.Agent) ([]fantasy.AgentTool, error) {
314func (c *coordinator) buildTools(ctx context.Context, agent config.Agent) ([]fantasy.AgentTool, error) {
internal/app/app.go+5−5
@@ -86,12 +86,12 @@ func New(ctx context.Context, conn *sql.DB, cfg *config.Config) (*App, error) {
86 app.cleanupFuncs = append(app.cleanupFuncs, conn.Close)
86 app.cleanupFuncs = append(app.cleanupFuncs, conn.Close)
87
87
88 // TODO: remove the concept of agent config, most likely.
88 // TODO: remove the concept of agent config, most likely.
89− if cfg.IsConfigured() {
89+ if !cfg.IsConfigured() {
90− if err := app.InitCoderAgent(ctx); err != nil {
91− return nil, fmt.Errorf("failed to initialize coder agent: %w", err)
92− }
93− } else {
94 slog.Warn("No agent configuration found")
90 slog.Warn("No agent configuration found")
91+ return app, nil
92+ }
93+ if err := app.InitCoderAgent(ctx); err != nil {
94+ return nil, fmt.Errorf("failed to initialize coder agent: %w", err)
95 }
95 }
96 return app, nil
96 return app, nil
97}
97}