Repository navigation
docs: add agent actions tutorial and API reference - #3960
Conversation
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
Thanks for the PR! Would be nice to have Actions in the tutorial, can I help in any way? |
|
Thanks for documenting timed actions and resumption, @codebreaker32. The failing Please rebase onto main to refresh CI. Related work to keep in view while finishing the draft: #4120 discusses Event and Action lifecycle conventions. Automated note by an AI model; it can be wrong, and maintainers make the decisions. About this bot. |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Thanks! It's nearly there. While finishing it I checked it against #4120, since that will change how actions pay for partial work and it turned out fine. |
|
Performance benchmarks:
|
|
Thanks for refreshing the branch and fixing the interrupted-forage example, @codebreaker32. All seven tutorial code cells run against current Mesa, and the earlier stale check is resolved. @EwoutH, the author answered your offer with a request for a read for flow. Please review that next; I recommend landing this documentation of the current API and adding examples for #4120’s future lifecycle changes alongside their implementation PRs. Automated note by an AI model; it can be wrong, and maintainers make the decisions. About this bot. |
|
@codebreaker32 agreed, let's land this first. I'll rebase #4172 on it afterwards and update the |
EwoutH
left a comment
There was a problem hiding this comment.
Thanks @codebreaker32, this reads really well. It builds up step by step, and the thirsty sheep example ties the two wake sources together nicely. I ran all cells on the PR head and the outputs match the text.
Three small corrections inline (the current_action reason, the 20% comment, the CellAgent sentence), plus a few optional suggestions. Happy for this to merge once those three are fixed; I'll update the tutorial for the #4172 renames afterwards.
|
@codebreaker32, whenever you have time, can you resolve the conflict and then go ahead and merge this. |
|
Sure, doing. |
Merge main, which brings the action lifecycle rework (mesa#4172). The module docstring conflict resolves to main's version, which already drops the double-paying on_interrupt example; the HasActions example from this branch is kept. Tutorial updates for mesa#4172: - Resume with resuming.resume(); start_action() now only starts a PENDING action and raised ValueError in the thirsty-sheep example. - is_resumable means INTERRUPTED, and resume() on a final action raises. - List the current hooks, including on_progress, on_stop and on_cancel. Review fixes: - interrupt_for() leaves the new action in current_action, it doesn't clear it. - The recipe resumes the remaining third, not 20%. - Drop the CellAgent sentence, which has Agent first. - INTERRUPTED isn't final, and on_idle doesn't fire when interrupt_for() refills the slot. - Rename "Interruption, Priority and Resumption" and point to the recipe. - State that the tutorial needs Mesa 4.0, or main until it's released.
* Update release notes and version for 4.0.0a1 Add the 4.0.0a1 release notes to HISTORY.md, leaving out changes already released in Mesa 3.5.1 to 3.5.4, and bump the version to 4.0.0a1. Move the #4182 replication id fix, which was added under 4.0.0a0, into the 4.0.0a1 notes where it was released. Assisted-by: Claude Opus 5.5 * Leave dependabot and pre-commit.ci bumps out of the 4.0.0a1 notes Assisted-by: Claude Opus 5.5 * Add PRs merged on 2026-11-30 to the 4.0.0a1 notes Seven PRs were merged after the notes were drafted: #4284, #3960, #4261, #3979, #4286, #4216 and #4301. Also moves the release date to 2026-11-30. Assisted-by: Claude Code
Summary
Adds a tutorial for
mesa.experimental.actions, documents the module in the API reference, and adds a runnableHasActionsexample to it.Motive
Actions arrived across #3801 (requirements and a FAILED state), #3805 (priority driven preemption) and #3833 (the
on_idlewake), and none of it has been documented. The wake contract needs it most. An agent wakes on exactly two triggers, its action ending or aThresholdcrossing, and two consequences are not obvious from the API:on_idle(previous)receives the action that just ended, which after an interruption is the interrupting one, and nothing is resumed automatically, so the model has to remember the interrupted action itself.Implementation
13_agent_actions.ipynb, working up from a single action: lifecycle and liveprogress, start and completion requirements, interruption withpriorityandshould_interrupt,on_idle, the two wake sources, and resuming the remainder.## Actionsadded todocs/apis/experimental.md, plus an entry ingetting_started.mdand theoverview.mdtoctree.HasActionsgets an example of chaining throughon_idle.on_interruptto pay30 * progresson top of the 30 fromon_complete, so a forage interrupted halfway and resumed paid 45 instead of 30, as described in Lifecycle conventions for Event, EventGenerator and Action #4120. Rework the action lifecycle: final cancel, completion wins, on_progress/on_stop, removal #4172 rewrote that docstring and dropped the pattern, so the API reference no longer ships it.resume(),is_resumablemeans INTERRUPTED, and the summary lists the current hooks.Usage Examples
Both wake sources together. Thirst rises continuously, a
Thresholdinterrupts grazing when the sheep gets too thirsty, andon_idleresumes the graze once drinking is done:In the tutorial this logs: