feat(agent-core): include recent messages in Stop hook payload#1299
feat(agent-core): include recent messages in Stop hook payload#1299Liewzheng wants to merge 2 commits into
Conversation
Restore the session hook extension needed by Mimir: the Stop hook now receives the last 10 user/assistant messages, allowing external memory systems to observe and learn from the current turn. Only text content parts are included; system/tool messages and non-text parts are filtered out to keep the payload small and serializable.
- Add field to Stop hook inputData so external memory systems (e.g. Mimir) can observe and learn from the current turn. - Filter to user/assistant roles and text-only content to keep payload small and serializable. - Update English and Chinese hook documentation. - Add unit test verifying Stop hook payload includes user/assistant messages. - Add changeset for @moonshot-ai/kimi-code.
🦋 Changeset detectedLatest commit: fd185db The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fd185db63a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const stopMessages = this.agent.context.messages | ||
| .slice(-10) | ||
| .map((msg) => ({ | ||
| role: msg.role, | ||
| content: msg.content | ||
| .filter((part) => part.type === 'text') | ||
| .map((part) => part.text) | ||
| .join(''), | ||
| })) | ||
| .filter((msg) => msg.role === 'user' || msg.role === 'assistant'); |
There was a problem hiding this comment.
Filter Stop payload before applying the 10-message cap
For tool-heavy turns, context.messages alternates assistant tool-call messages and tool results before the final answer, but this takes the last 10 raw messages before removing tool roles. After about five tool exchanges, the actual user prompt is outside that window, and the hook receives mostly empty assistant tool-call entries plus the final answer instead of the documented recent user/assistant text, so memory hooks can store a turn without the request that produced it. Filter to user/assistant text messages before applying the limit.
Useful? React with 👍 / 👎.
Summary
This PR extends the hook so that its payload includes the recent user/assistant messages. This enables external memory systems (such as Mimir) to observe and learn from the current turn, rather than only receiving a bare boolean.
Changes
Motivation
Third-party memory hooks need to know what was said in a turn before they can store or consolidate it. Previously the Stop hook only received , so memory tools had to rely solely on (which does not see the assistant reply) or prompt the model to call store tools explicitly.
Notes