Skip to content

Unify prompt assembly and align tool routing with sub-agent delegation - #346

Merged
F16shen merged 7 commits into
AI-Shell-Team:mainfrom
F16shen:refactor/prompt-assembly
Jul 8, 2026
Merged

Unify prompt assembly and align tool routing with sub-agent delegation#346
F16shen merged 7 commits into
AI-Shell-Team:mainfrom
F16shen:refactor/prompt-assembly

Conversation

@F16shen

@F16shen F16shen commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Introduce PromptAssembly to unify MainChat and sub-agent system prompt + tool spec assembly, replacing legacy LlmSession prompt filtering APIs.
  • Move per-tool routing into tool descriptions (usage stays in tool prompt appendices); oracle delegates tool choice to descriptions without duplicated routing tables.
  • Expand built-in sub-agent system prompts (explore/plan/general-purpose) and tighten Agent delegation schema (scope, thoroughness).
  • Convert embedded LLM templates to English, remove unused/dead prompt copies, and clarify enter_plan_mode routing vs usage boundaries.

Test plan

  • make format-check && make lint
  • cargo test -p aish-llm --test prompt_assembly_contract
  • cargo test -p aish-tools --test tool_routing_lint
  • cargo test -p aish-prompts
  • WeTTY smoke: natural-language explore/plan requests delegate via Agent appropriately
  • WeTTY smoke: multi-step work needing .aish/plans/ artifact routes to enter_plan_mode

Summary by CodeRabbit

  • New Features

    • Added clearer agent routing for explore vs plan mode, including explicit guidance for when to use each workflow.
    • Improved tool instructions and how tool visibility is presented across main chat and sub-agent contexts.
  • Bug Fixes

    • Reduced duplicated/legacy prompt content and aligned tool behavior between main chat and sub-agent flows.
    • Prevented plan-mode execution in sub-agent contexts and tightened tool exposure rules.
  • Documentation

    • Standardized embedded prompt templates to English only and removed unused/empty prompt text for a cleaner experience.

F16shen added 6 commits July 8, 2026 17:00
Introduce a unified assembly seam for MainChat and sub-agent contexts,
centralize tool visibility filtering, and remove legacy LlmSession prompt APIs.
Put when-to-use routing in tool descriptions and add routing lint tests;
keep detailed usage in tool prompts and leave the Agent tool prompt empty.
Add English explore/plan/general-purpose system prompts with read-only and
search strategy guidance, and tighten Agent prompt schema for scope and thoroughness.
Convert runtime embedded templates to English, drop unused template keys,
remove stale aish-shell prompt markdown copies, and english SSH error context.
…aries

Point oracle tool choice at per-tool descriptions only, and keep enter_plan_mode
routing in description while limiting its prompt appendix to post-entry usage.
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Thanks for the pull request. A maintainer will review it when available.

Please keep the PR focused, explain the why in the description, and make sure local checks pass before requesting review.

Contribution guide: https://github.com/AI-Shell-Team/aish/blob/main/CONTRIBUTING.md

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

This pull request description looks incomplete. Please update the missing sections below before review.

Missing items:

  • User-visible Changes
  • Compatibility
  • Testing
  • Change Type
  • Scope

@github-actions github-actions Bot added docs Documentation-related issue size: XL experienced-contributor labels Jul 8, 2026
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 0f8a8918-3b92-4ae9-92ba-a8b49deaec99

📥 Commits

Reviewing files that changed from the base of the PR and between e51f007 and 77f6d07.

📒 Files selected for processing (4)
  • crates/aish-llm/src/agents/mod.rs
  • crates/aish-llm/src/agents/spawn.rs
  • crates/aish-llm/src/agents/tool_loop.rs
  • crates/aish-shell/src/app.rs
✅ Files skipped from review due to trivial changes (2)
  • crates/aish-llm/src/agents/mod.rs
  • crates/aish-shell/src/app.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • crates/aish-llm/src/agents/spawn.rs
  • crates/aish-llm/src/agents/tool_loop.rs

📝 Walkthrough

Walkthrough

This PR introduces prompt assembly and visibility controls, wires them into session and sub-agent execution paths, expands tool routing guidance, and converts embedded prompt templates to English while removing unused prompt files.

Changes

Prompt assembly and routing refactor

Layer / File(s) Summary
Prompt visibility and assembly core
crates/aish-llm/src/types.rs, crates/aish-llm/src/prompt/*, crates/aish-llm/src/lib.rs
Adds PromptVisibility, PromptContext, ToolVisibilityPolicy, and PromptAssembly, then re-exports the prompt module API from the crate root.
Session prompt and sub-agent enforcement
crates/aish-llm/src/session.rs
Adds sub-agent session state, replaces legacy prompt/tool filtering helpers with PromptAssembly, and blocks denied tools in sub-agent preflight.
Agent, spawn, and tool-loop wiring
crates/aish-llm/src/agent.rs, crates/aish-llm/src/agents/*, crates/aish-llm/Cargo.toml
Threads PromptContext through agent, spawn, and tool-loop paths; adds built-in sub-agent prompts and registry wiring; updates the dev dependency.
Tool routing guidance and lint tests
crates/aish-tools/src/*/prompt.rs, crates/aish-tools/src/agent_tool/agent_tool.rs, crates/aish-tools/src/plan_tool/enter_plan_mode.rs, crates/aish-tools/tests/tool_routing_lint.rs
Expands agent and tool prompt text with routing and planning guidance, and adds lint tests for the new routing copy.
English prompt templates and cleanup
crates/aish-prompts/src/manager.rs, crates/aish-shell/prompts/*, crates/aish-shell/src/app.rs, CHANGELOG.md
Converts embedded templates and related prompt files to English, prunes default template loading, updates the SSH remote-host string, and documents the change.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

Suggested labels: tests, config

Poem

I hopped through prompts from old to new,
With routing signs in carrot-blue.
Plan and explore now know their way,
English banners light the day.
🐇✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: unified prompt assembly and updated tool routing for sub-agent delegation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (2)
crates/aish-llm/src/prompt/visibility.rs (1)

40-43: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Redundant session.tool_specs() call.

tool_specs is already computed at Line 40; Line 43 recomputes it via session.tool_specs() again just to pass into parent_has_skill_tool, cloning the full tool spec list twice.

♻️ Proposed fix
-        let tool_specs = session.tool_specs();
-        let registered: Vec<String> = tool_specs.into_iter().map(|s| s.function.name).collect();
-        let registered_refs: Vec<&str> = registered.iter().map(|s| s.as_str()).collect();
-        let parent_has_skill = parent_has_skill_tool(&session.tool_specs());
+        let tool_specs = session.tool_specs();
+        let parent_has_skill = parent_has_skill_tool(&tool_specs);
+        let registered: Vec<String> = tool_specs.into_iter().map(|s| s.function.name).collect();
+        let registered_refs: Vec<&str> = registered.iter().map(|s| s.as_str()).collect();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/aish-llm/src/prompt/visibility.rs` around lines 40 - 43, The
visibility logic is recomputing the tool spec list unnecessarily by calling
session.tool_specs() twice. Reuse the existing tool_specs binding in the
prompt/visibility flow, and pass that same value into parent_has_skill_tool
instead of cloning the session data again; this keeps the registered tool
collection and the skill check aligned without the extra allocation.
crates/aish-llm/src/lib.rs (1)

62-62: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

SUBAGENT_GLOBAL_DENY not re-exported at crate root.

prompt::mod.rs re-exports SUBAGENT_GLOBAL_DENY from the prompt module, but this crate-root re-export list omits it. Only relevant if external crates need this constant; internal usage via crate::prompt::SUBAGENT_GLOBAL_DENY in session.rs is unaffected.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/aish-llm/src/lib.rs` at line 62, The crate-root re-export list in
aish-llm::lib currently omits SUBAGENT_GLOBAL_DENY, so add that symbol alongside
the existing prompt exports. Update the pub use statement in the lib.rs
re-export block to include SUBAGENT_GLOBAL_DENY from prompt::mod.rs so external
crates can access it through the crate root, while keeping the existing
PromptAssembly, PromptBundle, PromptContext, and ToolVisibilityPolicy exports
unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@crates/aish-llm/src/lib.rs`:
- Line 62: The crate-root re-export list in aish-llm::lib currently omits
SUBAGENT_GLOBAL_DENY, so add that symbol alongside the existing prompt exports.
Update the pub use statement in the lib.rs re-export block to include
SUBAGENT_GLOBAL_DENY from prompt::mod.rs so external crates can access it
through the crate root, while keeping the existing PromptAssembly, PromptBundle,
PromptContext, and ToolVisibilityPolicy exports unchanged.

In `@crates/aish-llm/src/prompt/visibility.rs`:
- Around line 40-43: The visibility logic is recomputing the tool spec list
unnecessarily by calling session.tool_specs() twice. Reuse the existing
tool_specs binding in the prompt/visibility flow, and pass that same value into
parent_has_skill_tool instead of cloning the session data again; this keeps the
registered tool collection and the skill check aligned without the extra
allocation.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a006ba8e-2811-4162-b2ab-0be4ac1d2831

📥 Commits

Reviewing files that changed from the base of the PR and between 4eb0585 and e51f007.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (39)
  • CHANGELOG.md
  • crates/aish-llm/Cargo.toml
  • crates/aish-llm/src/agent.rs
  • crates/aish-llm/src/agents/builtin_prompts.rs
  • crates/aish-llm/src/agents/mod.rs
  • crates/aish-llm/src/agents/registry.rs
  • crates/aish-llm/src/agents/spawn.rs
  • crates/aish-llm/src/agents/tool_loop.rs
  • crates/aish-llm/src/lib.rs
  • crates/aish-llm/src/prompt/assembly.rs
  • crates/aish-llm/src/prompt/context.rs
  • crates/aish-llm/src/prompt/mod.rs
  • crates/aish-llm/src/prompt/visibility.rs
  • crates/aish-llm/src/session.rs
  • crates/aish-llm/src/types.rs
  • crates/aish-llm/tests/prompt_assembly_contract.rs
  • crates/aish-prompts/src/manager.rs
  • crates/aish-shell/prompts/cmd_error.md
  • crates/aish-shell/prompts/error_detect.md
  • crates/aish-shell/prompts/failure_diagnose.md
  • crates/aish-shell/prompts/guess_command.md
  • crates/aish-shell/prompts/oracle.md
  • crates/aish-shell/prompts/role.md
  • crates/aish-shell/prompts/skill.md
  • crates/aish-shell/prompts/system_diagnose.md
  • crates/aish-shell/src/app.rs
  • crates/aish-tools/src/agent_tool/agent_tool.rs
  • crates/aish-tools/src/agent_tool/prompt.rs
  • crates/aish-tools/src/bash/prompt.rs
  • crates/aish-tools/src/edit_file/prompt.rs
  • crates/aish-tools/src/glob_tool/prompt.rs
  • crates/aish-tools/src/grep_tool/prompt.rs
  • crates/aish-tools/src/plan_tool/enter_plan_mode.rs
  • crates/aish-tools/src/plan_tool/prompt.rs
  • crates/aish-tools/src/python/prompt.rs
  • crates/aish-tools/src/read_file/prompt.rs
  • crates/aish-tools/src/skill_tool/prompt.rs
  • crates/aish-tools/src/write_file/prompt.rs
  • crates/aish-tools/tests/tool_routing_lint.rs
💤 Files with no reviewable changes (8)
  • crates/aish-shell/prompts/role.md
  • crates/aish-shell/prompts/skill.md
  • crates/aish-shell/prompts/cmd_error.md
  • crates/aish-shell/prompts/failure_diagnose.md
  • crates/aish-shell/prompts/system_diagnose.md
  • crates/aish-shell/prompts/oracle.md
  • crates/aish-shell/prompts/error_detect.md
  • crates/aish-shell/prompts/guess_command.md

Resolve mod.rs conflict by keeping both builtin_prompts and event_metadata
after upstream sub-agent TUI progress landed on main.
@F16shen
F16shen merged commit 9ac6f11 into AI-Shell-Team:main Jul 8, 2026
8 checks passed
@F16shen
F16shen deleted the refactor/prompt-assembly branch July 8, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant