Skip to content

feat(agent-core): include recent messages in Stop hook payload#1299

Open
Liewzheng wants to merge 2 commits into
MoonshotAI:mainfrom
Liewzheng:main
Open

feat(agent-core): include recent messages in Stop hook payload#1299
Liewzheng wants to merge 2 commits into
MoonshotAI:mainfrom
Liewzheng:main

Conversation

@Liewzheng

Copy link
Copy Markdown

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

  • : Stop hook inputData now contains — the last 10 user/assistant messages with text content serialized to strings.
  • : added a test verifying the Stop hook payload includes and entries.
  • & : documented the new field in the Stop event row.
  • : patch-level changeset for .

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

  • Only and roles are included.
  • Non-text content parts (images, tool calls, etc.) are filtered out to keep the payload small and JSON-serializable.
  • This is a backward-compatible additive change; existing Stop hooks that ignore continue to work.

Liewzheng added 2 commits July 2, 2026 15:24
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-bot

changeset-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: fd185db

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +744 to +753
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');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant