fix(agents): reset task state for each run - #924
Open
daleselaji-dev wants to merge 1 commit into
Open
Conversation
daleselaji-dev
marked this pull request as ready for review
August 4, 2026 03:55
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.
Fixes #909.
Root cause
DefaultAgentinitializes its step count, cost, consecutive format-error count, and wall-clock start time only in__init__(). Althoughrun()clears the message history, it keeps those task-scoped values.Reusing an agent therefore gives the next task the previous task's consumed budget. A second run can stop with
LimitsExceededorTimeExceededbefore making a model call, and stale format errors can contribute to an unrelated task.What changed
cost,n_calls, andn_consecutive_format_errorsat the start of everyrun().run().This keeps instance configuration, model/environment objects, global model statistics, and per-run trajectory serialization unchanged.
Validation
The six pytest cases cover the text, tool-call, and Responses API deterministic model fixtures. I did not report the entire
test_default.pyfile as green on this Windows host because several existing tests depend on Bash output semantics; the focused limit/reset cases are platform-independent and pass.Risk and review notes
The behavioral change is intentionally limited to repeated calls to
run()on the same agent instance. The primary review point is whether all four values are task-scoped; they already describe per-run limits and are emitted as per-instance trajectory statistics, while global accounting remains inGLOBAL_MODEL_STATS.