Repository navigation
Conversation
Steering messages drained into a running turn are built through build_prompt without load_state, so a plugin cannot relate them to the inbound message they came from. after_build_prompt fires after every prompt the framework builds, with the message and the content the model receives. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fengzdadi
force-pushed
the
feat/after-build-prompt-hook
branch
from
November 5, 2026 17:25
4178448 to
be773de
Compare
This branch has not been deployed
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 changed and why
BubFramework.build_promptbuilds the model-facing user content for every inbound message: the turn's message inprocess_inbound, and each steering message thatAgentPlugins._drain_steeringadds to a running turn. Only the turn's message goes throughload_state. So a plugin that needs the inbound message behind a model-facing user message can capture the turn's message, but not a steered follow-up.PowerContext's Bub plugin hit this case. It recalls memory with what the user wrote, not with the framed prompt, whose channel metadata and date outweigh the user's words in lexical recall. Reading the turn's message in
load_stateworked until a follow-up was steered into the turn. The model then saw the follow-up while the plugin still recalled with the first message (reported in the review of oceanbase/powercontext#2488).after_build_prompt(message, prompt, session_id, state). It runs every implementation afterbuild_promptand ignores their return values.promptis a copy of the built content aslist[UserContent], not the legacy form, so an observer cannot change what the model receives. A plugin can match its text against the user messages inLLMCallRequest.messagesand readmessage, includingChannelMessage.textfrom feat(channels): expose what the sender wrote on Telegram messages #399, for the original words.build_prompt, the prompt, and the tape are unchanged.AgentPluginsdocstring now say that drained messages are built throughbuild_promptandafter_build_prompt; the docstring previously saidbuild_promptonly runs inprocess_inbound().Impacted modules
src/bub/hooks/specs.pysrc/bub/framework.pysrc/bub/hooks/agent.py(docstring)tests/test_framework.py,tests/test_agent_plugins.pywebsite/src/content/docs/docs/reference/hooks.mdx,website/src/content/docs/zh-cn/docs/reference/hooks.mdxVerification
make check: lock check, prek (ruff, ruff format), and mypy passed.uv run pytest -q: 731 passed, 20 skipped.test_after_build_prompt_observes_a_copy_of_the_built_content_with_its_messagechecks that an observer gets the message and the content another plugin built, and that clearing its copy leaves the prompt unchanged.test_agent_plugins_connect_loop_hooks_to_core_agentnow checks that the hook sees both steering messages drained into the run.make docs-test, since the website dependencies are not installed here.🤖 Generated with Claude Code