Route AgentTask creation through emit - #1114
Open
johnpooch wants to merge 2 commits into
Open
Conversation
Make agent a third emit consumer alongside notification and channel event, so bot work is triggered by domain events instead of Django signals: - New agent/registry.py holds AgentTaskSpec classes registered per event — PhaseStartedSpec (plan), PhaseStateConfirmedSpec (finalize), and ChannelMessageSpec (reply) — mirroring notification.registry and channel.registry. AgentTask.objects.create_from_event(event_type, context) looks up the spec and enqueues the tasks it returns. - emit/dispatch.py gains the AgentTask consumer; emit/context.py carries the message object so the reply spec can key on it. - New phase_started and phase_state_confirmed events are emitted where a phase becomes active (game start, resolution, revert) and where orders are confirmed. reply reuses the existing channel_message event. phase_started at resolution only fires when the new phase stays active, so a game-ending phase no longer spawns plan tasks. - agent/signals.py and agent/decorators.py are deleted; their trigger logic moves into the specs. This drops the pre_save phase-status capture, which slightly lowers the query count on the game-start and phase-creation paths (perf assertions updated). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YJpwkPRdgx4u6H2bMchrUk
✅ Deploy Preview for diplicity-variant-creator canceled.
|
Contributor
|
Warning WIP limit exceeded. There are now 11 open pull requests — the project target is 5 or fewer. Please close or merge an existing PR before continuing with this one. |
…ue-jyhen2 # Conflicts: # service/agent/decorators.py
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.
What this PR does
Step 3 of the AgentTask direction (steps 1–2: #1110, #1113). Makes
agenta thirdemitconsumer alongsidenotificationandchannel event, so bot work is triggered by domain events instead of Django signals — the consistency goal from the original discussion.How it works
agent/registry.pyholdsAgentTaskSpecclasses registered per event, mirroringnotification.registry/channel.registry:@register("phase_started")→ PhaseStartedSpec → plan tasks for bot members@register("phase_state_confirmed")→ PhaseStateConfirmedSpec → finalize tasks (runs the "all humans confirmed, bots still pending" check — Option A: the event is dumb, the spec holds the bot-aware logic, keeping bot knowledge insideagent)@register("channel_message")→ ChannelMessageSpec → reply tasks (skips bot senders)AgentTask.objects.create_from_event(event_type, context)now takes the emit(event_type, context)signature, looks up the spec, and enqueues whatever tasks it returns via_enqueue(unchanged get-or-create + defer).emit/dispatch.pygains theAgentTaskconsumer;emit/context.pycarries themessageobject so the reply spec can key its task on it.Emit sites
phase_started— emitted where a phase becomes active: game start (game/models.py), resolution (phase/models.py, guarded so a game-ending phase no longer spawns plan tasks), and revert.phase_state_confirmed— emitted when orders are confirmed (phase/serializers.py).emit("channel_message", …)— no new site.Removed
agent/signals.pyandagent/decorators.pyare deleted; their trigger logic moved into the specs. This drops thepre_savephase-status capture, which slightly lowers the query count on the game-start and phase-creation paths (perf assertions ingame/tests.pyandphase/tests.pyupdated: −1 each).Behavior notes
channel_message(the real posted-message event) rather than any rawChannelMessageORM create — more correct, and bot-sent messages still don't trigger replies.agent,emit,game,phase,channel,integration, andnotificationsuites.Checklist
main(the/review-prskill'sghdependency isn't wired in this environment, so the review was run manually) — no correctness issues found🤖 Generated with Claude Code
Generated by Claude Code