Skip to content

Commit b000ac0

Browse files
authored
Merge pull request #2323 from dgageot/board/emittoolschanged-timeout-races-with-rag-2061feeb
fix: avoid triggering toolset startup from emitToolsChanged callback
2 parents e8080b7 + 509643b commit b000ac0

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

pkg/agent/agent.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,23 @@ func (a *Agent) Hooks() *latest.HooksConfig {
209209
// Tools returns the tools available to this agent
210210
func (a *Agent) Tools(ctx context.Context) ([]tools.Tool, error) {
211211
a.ensureToolSetsAreStarted(ctx)
212+
return a.collectTools(ctx)
213+
}
214+
215+
// StartedTools returns tools only from toolsets that have already been started,
216+
// without triggering initialization of unstarted toolsets. This is useful for
217+
// notifications (e.g. MCP tool list changes) that should not block on slow
218+
// toolset startup such as RAG file indexing.
219+
func (a *Agent) StartedTools(ctx context.Context) ([]tools.Tool, error) {
220+
return a.collectTools(ctx)
221+
}
212222

223+
// collectTools gathers tools from all started toolsets plus static tools.
224+
func (a *Agent) collectTools(ctx context.Context) ([]tools.Tool, error) {
213225
var agentTools []tools.Tool
214226
for _, toolSet := range a.toolsets {
215227
if !toolSet.IsStarted() {
216-
// Toolset failed to start; skip it
228+
// Toolset not started; skip it
217229
continue
218230
}
219231
ta, err := toolSet.Tools(ctx)

pkg/runtime/runtime.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -808,7 +808,8 @@ func (r *LocalRuntime) emitToolsChanged() {
808808
}
809809
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
810810
defer cancel()
811-
agentTools, err := r.CurrentAgentTools(ctx)
811+
a := r.CurrentAgent()
812+
agentTools, err := a.StartedTools(ctx)
812813
if err != nil {
813814
return
814815
}

0 commit comments

Comments
 (0)