-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: move KIMI_AGENTS_MD to first message from system prompt. #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: upstream_main
Are you sure you want to change the base?
Conversation
|
@codex review this PR. |
There was a problem hiding this comment.
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.
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
0c33279 to
145af39
Compare
|
@codex review this PR x 2. |
There was a problem hiding this comment.
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.
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
145af39 to
c6552b1
Compare
|
@codex review this PR x 3. |
There was a problem hiding this comment.
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.
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review this PR x 4. |
|
Codex Review: Didn't find any major issues. Hooray! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@copilot review |
|
@codex review this PR x 5. |
There was a problem hiding this comment.
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.
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review this PR x 6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
kimi-cli/src/kimi_cli/soul/compaction.py
Lines 35 to 57 in 824e819
| class SimpleCompaction(Compaction): | |
| MAX_PRESERVED_MESSAGES = 2 | |
| async def compact(self, messages: Sequence[Message], llm: LLM) -> Sequence[Message]: | |
| history = list(messages) | |
| if not history: | |
| return history | |
| preserve_start_index = len(history) | |
| n_preserved = 0 | |
| for index in range(len(history) - 1, -1, -1): | |
| if history[index].role in {"user", "assistant"}: | |
| n_preserved += 1 | |
| if n_preserved == self.MAX_PRESERVED_MESSAGES: | |
| preserve_start_index = index | |
| break | |
| if n_preserved < self.MAX_PRESERVED_MESSAGES: | |
| return history | |
| to_compact = history[:preserve_start_index] | |
| to_preserve = history[preserve_start_index:] | |
AGENTS.md is now appended to the conversation as an assistant message, but SimpleCompaction only preserves the last two assistant/user messages and compacts everything earlier into a summary. Once the context grows large enough to trigger compaction, the injected AGENTS content will be summarized away and the agent loses those instructions for the remainder of the session. Previously the guidance lived in the system prompt and was never compacted. You may need to pin the injected message (e.g. treat it as non‑compactable or re‑inject after compaction) to keep the project rules available.
kimi-cli/src/kimi_cli/ui/shell/metacmd.py
Lines 225 to 232 in 824e819
| app.soul = soul_bak | |
| agents_md = load_agents_md(soul_bak._runtime.builtin_args.KIMI_WORK_DIR) | |
| system_message = system( | |
| "The user just ran `/init` meta command. " | |
| "The system has analyzed the codebase and generated an `AGENTS.md` file. " | |
| f"Latest AGENTS.md file content:\n{agents_md}" | |
| ) | |
| await app.soul._context.append_message(Message(role="user", content=[system_message])) |
/init or file changes
Runtime caches agents_md at startup and _ensure_initial_system_messages always uses that cached string. The /init meta command regenerates AGENTS.md and loads the new content, but the Runtime instance is never updated, so future subagents or cleared contexts keep injecting the stale, pre‑init instructions. The same issue occurs if the user edits AGENTS.md during a session. Consider updating runtime.agents_md (and possibly re‑seeding contexts) after AGENTS.md changes so new conversations see the latest guidance.
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
49c21ae to
6845d43
Compare
|
@codex review this PR x 7 |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
80e411c to
804abf8
Compare
|
@codex review this PR x 8 |
There was a problem hiding this comment.
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.
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review this PR x 21 |
|
Codex Review: Didn't find any major issues. Nice work! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
85eefb4 to
91f1115
Compare
927eb65 to
18326bf
Compare
91f1115 to
f6a5b5f
Compare
*. Runtime now loads AGENTS.md once and keeps it beside other runtime metadata instead of exposing it through the system prompt arguments, so built-in args are limited to clock/workdir info. *. KimiSoul tracks whether an empty context has been seeded and, on the first run, appends a <system> message containing the AGENTS.md guidance/content before the user’s first message so it lives in the transcript rather than the prompt template.
Removing KIMI_AGENTS_MD from BuiltinSystemPromptArgs means string.Template.substitute no longer receives this key. Any custom agent system prompt that still contains ${KIMI_AGENTS_MD} (common for prompts derived from the previous default) will now raise a KeyError when the agent loads, preventing the CLI from starting. Switching to safe_substitute would preserve backward compatibility.
…e stays in context. Builds the AGENTS injection via a shared _agents_md_message() helper so the startup seeding logic is centralized and reusable. Also reinserts a fresh AGENTS message right after the compaction summary before re-appending preserved turns, preserving the latest user prompt order while keeping project rules visible for the next LLM step.
…agents.md in the active work_dir, and tells the user to delete the file before regenerate.(same as OpenAI codex)
… covered by a regression spec. determine _initial_context_prepared by detecting existing AGENTS content, backfill AGENTS.md even when history exists, and avoid duplicates via the new _agents_md_present helper that scans assistant text parts.
…ly and injected without restarting. reload AGENTS.md into a fresh Runtime via replace, clear _initial_context_prepared based on actual context, and use the refreshed content for the meta-command message so subsequent runs/compactions see it.
…ages via a history reset before re-injecting the fresh instructions, preventing duplicates. Added AGENTS.md detection helper plus Context.reset_history so the backing file and counters are rewritten when stale system messages are dropped.
…d_agents_md), skips regeneration when AGENTS.md already exists but still refreshes the runtime cache and context messaging. Context accepts KaosPath backends by converting to local paths, fixing append/restore operations in tests. The regression test now seeds a temporary AGENTS.md so /init can reload it without hitting the mock LLM flow.
…ts by copying via dataclasses.replace, so required fields travel with both fixed and dynamic clones.
…for async execution. Added type hint for Awaitable and improved assertion for app soul instance.
…ime dataclass (lines 48‑52) that omits the labor_market field and the subagent copy helpers present in soul/agent.py, yet it’s published in the package. Nothing imports this module (rg "soul.runtime" returns no hits), so it only serves as a misleading alternate entry point: importing Runtime from this file produces instances without a labor market, which will break Task/CreateSubagent flows that rely on it. Consider removing this file or wiring it up to the real Runtime to avoid an unusable duplicate API.
…ool runtime dependencies, and labor-market subagents so /init reloads propagate to newly spawned helpers instead of using stale guidance. * Added regression ensuring a CreateSubagent-created helper after /init inherits the refreshed AGENTS.md content and injects it into its initial context.
…d detection to drop stale entries before reinjection, preventing conflicting instructions in refreshed sessions. Added stale AGENTS cleanup before initial injection and kept presence checks tied to the current digest to ensure only the latest instructions remain. Added a regression test that simulates a refreshed AGENTS.md and verifies the stale message is replaced with the new content.
…eckpoint/usage records and only drop messages matching a predicate; so stale AGENTS.md pruning no longer zeros _next_checkpoint_id or strips checkpoint entries. Added regression test_refresh_agents_md_preserves_checkpoints in tests/test_kimisoul.py to cover AGENTS.md refresh when checkpoints already exist and verify new content is injected without losing checkpoint metadata.
…e new history.py responsibility is maintain history: Sequence[Message], move other relative staff to the new history.py if you think relative.
…nd agent, and implemented update_runtime method to handle external runtime changes. Updated init function to utilize new properties for improved clarity and functionality.
…s any previously injected AGENTS.md messages and _agents_md_present no longer treats missing content as satisfied; centralized removal helper handles both stale and deletion cases
… of the same name (reportRedeclaration)
f6a5b5f to
1422db3
Compare
Signed-off-by: Richard Chien <stdrc@outlook.com> Co-authored-by: Richard Chien <stdrc@outlook.com>
Signed-off-by: Richard Chien <stdrc@outlook.com>
upstream PR 293