Repository navigation
Add Agent.on_idle wake dispatched as a deferred low-priority event - #3833
Conversation
|
tests are failing, see widgetti/solara#1199 |
|
Performance benchmarks:
|
72840d7 to
e52c846
Compare
quaquel
left a comment
There was a problem hiding this comment.
This looks fine to me. Just one clarifying question: why schedule the wake instead of calling it synchronously?
|
Three failure modes pushed me to defer it:
|
|
Agents won't get a second wake at the same time step with a "once per time" guard on. This makes sense, but will this fail silently? Maybe a docstring for hint to users? |
|
The
The suppression does have to be quiet: the only agent that hits it is one chaining zero-duration actions within a single instant, and the alternative to stopping quietly is spinning forever without time advancing. A debug aid is cheap, though, I can emit a |
|
Ty for the docstring. I missed it. |
Co-Authored-By: Claude Fable 5 <[email protected]>
d9ed470 to
d8c0ec3
Compare
|
LGTM. Thank you! |
Summary
Adds
Agent.on_idle(previous): called whenever the agent's action has ended — completion, interruption, cancellation, or failure — and nothing has replaced it. Dispatched as a zero-delayPriority.LOWevent. Completes section 3 of #3798.Motive
After #3801 and #3805 an action can fail or be preempted, but nothing tells the agent afterwards; models must poll or schedule around it.
on_idleis the "body became free" half of the wake contract: one place to chain the next action or resume an interrupted one. The default is a no-op, and nothing is resumed automatically.Implementation
Action._release_agent(), which clears the agent's slot and schedules the wake.Agent.remove()bypasses it and cancels a pending wake — a removed agent never wakes._do_complete: a zero-duration action started fromon_idlecannot recurse, and every agent finishing at time t decides after all completions at t have run.previousreporting the latest. A wake that finds the agent busy again (interrupt_forrefilled the slot synchronously) is skipped.TestOnIdle);test_start_failure_schedules_nothingsharpened intotest_start_failure_schedules_no_completion.Usage Examples
Each completion wakes the worker once, after all other completions at that time, and the next task begins, no external driver.
Additional Notes
Docs and the task-driven example are section 5 of #3798 and follow separately.
on_idlesits onAgentnext to the existing action cluster, pending the mixin question raised in #3805.