feat(agent): per-call timeouts, parallel-tool concurrency cap, max-iteration signal (Wave 5)#42
Closed
urmzd wants to merge 1 commit into
Closed
feat(agent): per-call timeouts, parallel-tool concurrency cap, max-iteration signal (Wave 5)#42urmzd wants to merge 1 commit into
urmzd wants to merge 1 commit into
Conversation
d7d8efe to
1c1018d
Compare
…eration signal
Add GA-hardening limits to the agent loop:
- LLMTimeout/ToolTimeout (+ WithLLMTimeout/WithToolTimeout): derive a child
context.WithTimeout around the provider call in getAssistantMessage and
around each tool step in executeOneTool. A slow provider surfaces a transient
ProviderError; a slow tool surfaces a deadline-exceeded tool error (even if
the tool ignores ctx and completes late). 0 = no timeout (default).
- MaxParallelTools (+ WithMaxParallelTools): bound the parallel-tool goroutines
with a buffered-channel semaphore. 0 = unlimited. Durable-runner sequential
path is unchanged.
- ErrMaxIterations signal: emit types.ErrorDelta{Error: ErrMaxIterations} when
runLoop breaks on the iteration cap while the last assistant turn still had
pending tool calls, so consumers can tell truncated from a clean finish. Not
emitted on a natural text-only/empty finish.
Table-driven tests in agent/limits_test.go cover all three plus the disabled/
unlimited defaults. Existing tests unchanged.
1c1018d to
266a13a
Compare
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wave 5 — GA hardening (bounded slice)
All changes are in the
agentpackage and stay green:go build ./...,go vet ./agent/, andgo test ./agent/pass (race-clean on the affected tests).What landed
(a) Per-call timeouts
AgentConfig.LLMTimeout/AgentConfig.ToolTimeout(time.Duration, 0 = none) +WithLLMTimeout/WithToolTimeoutoptions.context.WithTimeoutwraps the provider call insidegetAssistantMessageand each tool step insideexecuteOneTool.*types.ProviderErrorwrappingcontext.DeadlineExceeded(errors.Is(err, ErrProviderFailed)andIsTransient(err)both hold).ctxand completes after the deadline (checked viastepCtx.Err()after execution).(b) Parallel-tool concurrency cap
AgentConfig.MaxParallelTools(int, 0 = unlimited) +WithMaxParallelTools.executeToolsConcurrentlybounds the fan-out goroutines with a buffered-channel counting semaphore.StepRunner) still runs tools sequentially in the caller's goroutine — unchanged.(c) Max-iteration truncation signal
types.ErrMaxIterationswas defined but never emitted.runLoopnow trackspendingWork: when it breaks on the iteration cap while the last assistant turn still had pending tool calls, it emitstypes.ErrorDelta{Error: ErrMaxIterations}so consumers can distinguish "truncated" from "finished".pendingWorkand does NOT emit the error.Tests (agent/limits_test.go, table-driven)
DeadlineExceeded; disabled-by-default path stays clean.ErrMaxIterationsemitted on a truncated run; NOT emitted on a clean finish nor when the assistant lands its final text turn exactly on the cap.Deferred (TODO, beyond this slice)
NewAgent->(*Agent, error)(currently panics on invalid handoff config).Stacked on #38 (foundation) — merge after #38.