Skip to content

Conversation

@Eric-Guo
Copy link
Contributor

@Eric-Guo Eric-Guo commented Nov 14, 2025

Related Issue / TODO

Resolve KIMI_AGENTS_MD: str # TODO: move to first message from system prompt

Description

  • 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 message containing the AGENTS.md guidance/content before the user’s first message so it lives in the transcript rather than the prompt template.

Know issue

Codex Web Code Review: Didn't find any major issues. Swish!
Codex CLI(gpt-5.1-codex-max vhigh): I did not find any discrete bugs or regressions introduced by this patch. The new AGENTS.md handling, runtime changes, and supporting utilities appear internally consistent and are backed by tests.

Frontier coding agents

larged done by codex.

codex review done by x 19

Copilot AI review requested due to automatic review settings November 14, 2025 18:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Eric-Guo Eric-Guo force-pushed the agents_md_move_out branch 2 times, most recently from 8d970af to 5dbbfdc Compare November 20, 2025 00:35
@Eric-Guo
Copy link
Contributor Author

Finally codex-max-xhigh say:

After reviewing the diff against upstream_main, I did not find any regressions or missing updates introduced by the change set. The new AGENTS.md injection logic, runtime wiring, and tests appear internally consistent and self-contained.

@Eric-Guo
Copy link
Contributor Author

I'm not sure "move KIMI_AGENTS_MD to first message from system prompt." is worth it or not, in short term, it introduce quite complex change (+330 line change), but in long term, it lead #288 possible or even select tools at AGENTS.md.

Any comment? @xxchan @stdrc

@Eric-Guo Eric-Guo force-pushed the agents_md_move_out branch 5 times, most recently from c504b9c to 25dc8ae Compare November 21, 2025 14:57
@Eric-Guo
Copy link
Contributor Author

Codex Review: Didn't find any major issues. Swish!

@Eric-Guo Eric-Guo force-pushed the agents_md_move_out branch 3 times, most recently from de6d355 to 022d567 Compare November 22, 2025 03:10
@Eric-Guo
Copy link
Contributor Author

Eric-Guo commented Nov 22, 2025

I see #328 merged and if we want multi-agent in different AGENTS.md working on the same history, this refactor become must have.

Another scenario I can image is add a new option like --agent_md_file and when startup kimi, user can choose which AGENTS file to use.

@Eric-Guo Eric-Guo force-pushed the agents_md_move_out branch 6 times, most recently from 5d986ba to 911ea85 Compare November 24, 2025 11:29
@Eric-Guo Eric-Guo force-pushed the agents_md_move_out branch 4 times, most recently from 91f1115 to 1422db3 Compare November 28, 2025 11:26
Eric-Guo and others added 21 commits November 28, 2025 22:43
*. 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
@Eric-Guo
Copy link
Contributor Author

It's conflicted with #381, and since it's already 2 weeks and mention @xxchan @stdrc 1 week ago and no response, perfer close here.

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