Repository navigation
Closed
Copy link
Labels
Description
Summary
The agent currently waits for background work with poll loops: Bash("sleep 20") -> chat completion -> BashOutput -> repeat. Every iteration costs a full LLM round-trip (tokens + latency) just to discover "not done yet".
Add a Wait tool that blocks inside a single tool execution until a condition is met, then returns once with the outcome. Waiting should cost zero chat completions.
Proposed conditions (one tool, condition arg)
shells- block until the given background shell ID(s) exit (or all pending background tasks when omitted). Backed byjobs.Supervisor/BackgroundTaskRegistry;shell_job.goalready blocks oncmd.Wait(), andBackgroundTasksWaiter.WaitAndDrainis an existing blocking loop to model on - it just isn't exposed as a tool.file- block until a path is created/modified/removed, via fsnotify (same pattern the scheduler already uses inscheduler.go::startWatcher).command- re-run a check command server-side at a fixed interval until it exits 0 (e.g.curl -sf localhost:8080/health). Moves the poll loop out of the LLM loop; the check command goes through the same bash allow-list/approval gate as the Bash tool.
Every mode takes a required timeout_seconds (bounded by a config ceiling) and returns a structured result: which condition fired (or timeout), elapsed time, and for shells the exit codes / tail output.
Design notes
- New tool implementing
domain.Tool, registered inregistry.go::registerToolsbehindcfg.Tools.Wait.Enabled(default on), config struct + defaults inconfig/config.go. - Cancellation:
selecton the event source vsctx.Done(), same as existing session-cancel propagation - Esc in chat must interrupt the wait immediately. - Read-only (no state mutation), so no approval required; the
commandmode's check command is still validated against the per-mode bash allow-list. - Update the system prompt / tool description so the model prefers
Waitoversleep-based polling. - Docs ticket for
inference-gateway/docsto be filed with the implementing PR per the docs follow-up rule.
Acceptance Criteria
-
Waittool registered and enabled by default, withtools.waitconfig (enabled, max timeout ceiling, command-mode poll interval). -
condition: shellsblocks until the referenced background shell(s) exit and returns exit codes + tail output, without intermediate chat completions. -
condition: fileblocks on fsnotify events for a given path. -
condition: commandre-runs an allow-listed check command at an interval until exit 0 or timeout. - Timeout and user cancellation (Esc / session cancel) interrupt the wait promptly and return a structured timeout/cancelled result.
- Unit tests next to the tool (
internal/agent/tools/wait_test.go) covering all three conditions, timeout, and cancellation.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
edenreich commentedon Jul 8, 2026
@infer Can you work on this? use /go /go-concurrency /bubbles-v2 /bubbletea-v2 /cobra-viper or any other skills that you may need.
inference-gateway-maintainer commentedon Jul 8, 2026
Model:
ollama_cloud/deepseek-v4-flash· View JobTodos
The agent stopped before finishing its plan, so some work may be incomplete. It did not open a pull request; any unpushed work was lost with the runner — check the workflow log for what was attempted and re-trigger to retry.
Now I have the full file content. Let me write it with the Wait config changes.
Model:
ollama_cloud/deepseek-v4-flash· Exit Code:0· Duration: 5m 24sTokens: 3,379,802 in · 14,520 out · 3,394,322 total (35 requests)
Tool calls: 47 total · 87% success rate
No similar content found. Please verify the content exists and matches exactly (including whitespace).
No similar content found. Please verify the content exists and matches exactly (including whitespace).
Triggered by edenreich · Infer Action
edenreich commentedon Jul 8, 2026
@infer What happened? continue.
inference-gateway-maintainer commentedon Jul 8, 2026
Model:
ollama_cloud/deepseek-v4-flash· View JobTodos
Pull Request
#792
✅ Infer Result: Success
All tasks are complete. Here's a summary of what was implemented:
Added a
Waittool that blocks inside a single tool execution until a condition is met, then returns once with the outcome - eliminating sleep-and-poll loops that cost LLM round-trips.Changes across 6 files:
config/config.go- AddedWaitToolConfigstruct (Enabled, MaxTimeoutSeconds, CommandPollIntervalMs) wired intoToolsConfigwith defaults (enabled, 300s max timeout, 2s command poll interval)config/prompts.go- Added Wait tool prompt description inPromptsToolsConfigwith merge supportinternal/agent/tools/wait.go- FullWaitToolimplementation with three conditions:shells(block until background shell(s) exit, returns exit codes + tail output),file(block on fsnotify events for a path), andcommand(re-run check command at interval until exit 0). Supports timeout, cancellation viactx.Done(), and config-bounded timeout ceilinginternal/agent/tools/registry.go- RegisteredWaittool behindcfg.Tools.Wait.Enabledinternal/agent/tools/wait_test.go- 13 tests covering Validate, Definition, IsEnabled, FormatPreview, FormatForLLM, eventMatches helper, all three conditions, timeout, cancellation, and shell service integrationinference-gateway/docs#369Model:
ollama_cloud/deepseek-v4-flash· Exit Code:0· Duration: 16m 38sTokens: 17,957,655 in · 24,871 out · 17,982,526 total (76 requests)
Tool calls: 92 total · 92% success rate
internal/agent/tools/wait_test.go:476:24: undefined: utils.NewBackgroundShellService
FAIL github.com/inference-gateway/cli/internal/agent/tools [build failed]
FAIL
=== RUN TestWaitTool_Validate/missing_condition
=== RUN TestWaitTool_Validate/invalid_condition
=== RUN TestWaitTool_Validate/missing_timeout
=== RUN TestWaitTool_Validate/timeout_exceeds_max
=== RUN TestWaitTool_Validate/file_missing_path
=== RUN TestWaitTool_Validate/command_missing_command
=== RUN TestWaitTool_Validate/valid_shells
=== RUN TestWaitTool_Validate/valid_file
=== RUN TestWaitTool_Validate/valid_command
--- PASS: TestWaitTool_Validate (0.00s)
--- PASS: TestWaitTool_Validate/missing_condition (0.00s)
--- PASS: TestWaitTool_Validate/invalid_condition (0.00s)
--- PASS: TestWaitTool_Validate/missing_timeout (0.00s)
--- PASS: TestWaitTool_Validate/timeout_exceeds_max (0.00s)
--- PASS: TestWaitTool_Validate/file_missing_path (0.00s)
--- PASS: TestWaitTool_Validate/command_missing_command (0.00s)
--- PASS: TestWaitTool_Validate/valid_shells (0.00s)
--- PASS: TestWaitTool_Validate/valid_file (0.00s)
--- PASS: TestWaitTool_Validate/valid_command (0.00s)
=== RUN TestWaitTool_Definition
wait_test.go:134: Definition() description is empty
--- FAIL: TestWaitTool_Definition (0.00s)
=== RUN TestWaitTool_IsEnabled
--- PASS: TestWaitTool_IsEnabled (0.00s)
=== RUN TestWaitTool_FormatPreview
=== RUN TestWaitTool_FormatPreview/nil_result
=== RUN TestWaitTool_FormatPreview/condition_met
=== RUN TestWaitTool_FormatPreview/timeout
--- PASS: TestWaitTool_FormatPreview (0.00s)
--- PASS: TestWaitTool_FormatPreview/nil_result (0.00s)
--- PASS: TestWaitTool_FormatPreview/condition_met (0.00s)
--- PASS: TestWaitTool_FormatPreview/timeout (0.00s)
=== RUN TestWaitTool_FormatForLLM
--- PASS: TestWaitTool_FormatForLLM (0.00s)
=== RUN TestEventMatches
=== RUN TestEventMatches/create_matches_create
=== RUN TestEventMatches/create_does_not_match_modify
=== RUN TestEventMatches/write_matches_modify
=== RUN TestEventMatches/chmod_matches_modify
=== RUN TestEventMatches/remove_matches_remove
=== RUN TestEventMatches/rename_matches_remove
=== RUN TestEventMatches/create_matches_any
=== RUN TestEventMatches/write_matches_any
=== RUN TestEventMatches/remove_matches_any
=== RUN TestEventMatches/unknown_event_defaults_to_true
--- PASS: TestEventMatches (0.00s)
--- PASS: TestEventMatches/create_matches_create (0.00s)
--- PASS: TestEventMatches/create_does_not_match_modify (0.00s)
--- PASS: TestEventMatches/write_matches_modify (0.00s)
--- PASS: TestEventMatches/chmod_matches_modify (0.00s)
--- PASS: TestEventMatches/remove_matches_remove (0.00s)
--- PASS: TestEventMatches/rename_matches_remove (0.00s)
--- PASS: TestEventMatches/create_matches_any (0.00s)
--- PASS: TestEventMatches/write_matches_any (0.00s)
--- PASS: TestEventMatches/remove_matches_any (0.00s)
--- PASS: TestEventMatches/unknown_event_defaults_to_true (0.00s)
=== RUN TestWaitTool_Execute_UnknownCondition
--- PASS: TestWaitTool_Execute_UnknownCondition (0.00s)
=== RUN TestWaitTool_Execute_ShellsNoShells
--- PASS: TestWaitTool_Execute_ShellsNoShells (0.00s)
=== RUN TestWaitTool_Execute_FileTimeout
--- PASS: TestWaitTool_Execute_FileTimeout (1.00s)
=== RUN TestWaitTool_Execute_CommandTimeout
--- PASS: TestWaitTool_Execute_CommandTimeout (1.00s)
=== RUN TestWaitTool_Execute_CommandSuccess
--- PASS: TestWaitTool_Execute_CommandSuccess (0.00s)
=== RUN TestWaitTool_Execute_FileEvent
--- PASS: TestWaitTool_Execute_FileEvent (0.20s)
=== RUN TestWaitTool_Execute_Cancellation
--- PASS: TestWaitTool_Execute_Cancellation (0.10s)
=== RUN TestWaitTool_Execute_ShellsWithShellService
--- PASS: TestWaitTool_Execute_ShellsWithShellService (0.50s)
FAIL
FAIL github.com/inference-gateway/cli/internal/agent/tools 2.839s
FAIL
No similar content found. Please verify the content exists and matches exactly (including whitespace).
Triggered by edenreich · Infer Action
inference-gateway-releaser commentedon Jul 8, 2026
🎉 This issue has been resolved in version 0.139.0 🎉
The release is available on:
Your semantic-release bot 📦🚀