Skip to content

Conversation

@Eric-Guo
Copy link
Owner

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

  • 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.

upstream PR 293

@Eric-Guo
Copy link
Owner Author

@codex review this PR.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

@Eric-Guo Eric-Guo force-pushed the agends_md_as_first_message branch from 0c33279 to 145af39 Compare November 14, 2025 17:47
@Eric-Guo
Copy link
Owner Author

@codex review this PR x 2.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

@Eric-Guo Eric-Guo force-pushed the agends_md_as_first_message branch from 145af39 to c6552b1 Compare November 14, 2025 17:57
@Eric-Guo
Copy link
Owner Author

@codex review this PR x 3.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

@Eric-Guo
Copy link
Owner Author

@codex review this PR x 4.

@chatgpt-codex-connector
Copy link

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

ℹ️ 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".

@Eric-Guo
Copy link
Owner Author

@copilot review

Copy link

Copilot AI commented Nov 15, 2025

@Eric-Guo I've opened a new pull request, #2, to work on those changes. Once the pull request is ready, I'll request review from you.

@Eric-Guo
Copy link
Owner Author

@codex review this PR x 5.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

@Eric-Guo
Copy link
Owner Author

@codex review this PR x 6

Copy link

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

Choose a reason for hiding this comment

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

💡 Codex Review

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:]

P1 Badge Prevent compaction from discarding AGENTS.md instructions

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.


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]))

P2 Badge Refresh cached AGENTS.md after /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".

@Eric-Guo Eric-Guo force-pushed the agends_md_as_first_message branch 5 times, most recently from 49c21ae to 6845d43 Compare November 20, 2025 08:56
@Eric-Guo
Copy link
Owner Author

@codex review this PR x 7

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

ℹ️ 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".

@Eric-Guo Eric-Guo force-pushed the agends_md_as_first_message branch 3 times, most recently from 80e411c to 804abf8 Compare November 21, 2025 13:37
@Eric-Guo
Copy link
Owner Author

@codex review this PR x 8

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a 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".

@Eric-Guo
Copy link
Owner Author

@codex review this PR x 21

@chatgpt-codex-connector
Copy link

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

ℹ️ 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".

@Eric-Guo Eric-Guo force-pushed the agends_md_as_first_message branch 2 times, most recently from 85eefb4 to 91f1115 Compare November 28, 2025 02:10
@Eric-Guo Eric-Guo force-pushed the agends_md_as_first_message branch from 91f1115 to f6a5b5f Compare November 28, 2025 08:45
Eric-Guo and others added 21 commits November 28, 2025 19:24
*. 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 Eric-Guo force-pushed the agends_md_as_first_message branch from f6a5b5f to 1422db3 Compare November 28, 2025 11:27
Eric-Guo pushed a commit that referenced this pull request Dec 27, 2025
Signed-off-by: Richard Chien <stdrc@outlook.com>
Co-authored-by: Richard Chien <stdrc@outlook.com>
Eric-Guo pushed a commit that referenced this pull request Dec 27, 2025
Signed-off-by: Richard Chien <stdrc@outlook.com>
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.

2 participants