-
Notifications
You must be signed in to change notification settings - Fork 3
feat(prompts): implement skill-based dynamic prompt architecture #21
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
Conversation
Add builtin_skills.rs with six skills extracted from the monolithic prompt: - git: Version control best practices, commits, PRs, branches - code-quality: Linting, testing, style matching guidelines - file-operations: Safe file ops, read-before-write, rollback strategies - debugging: Tier 1-4 failure handling, error recovery - security: Secrets handling, input validation, secure defaults - planning: Cognitive architecture, task decomposition Each skill has YAML frontmatter (name, description, version, tags) and helper functions: get_builtin_skill(), list_builtin_skills(), is_builtin_skill(), builtin_skill_count() This reduces context window usage by loading skills only when relevant.
Add skill-based prompt system to cortex-engine: - USE_SKILL_BASED_PROMPT constant for mode control - build_system_prompt_with_skills() for skill-aware prompts - inject_skills() helper for skill content injection - auto_detect_skills_from_message() for automatic skill detection - available_skills() and is_valid_skill() utilities - Comprehensive test suite for all new functions Maintains backward compatibility with existing monolithic prompt.
- Add SkillSource::Builtin variant to distinguish embedded skills - Add load_builtin() method to SkillLoader for loading built-in skills - Update load() method to check built-ins before filesystem search - Update list() method to include built-in skills in listings - Add comprehensive tests for built-in skill loading
Greptile OverviewGreptile SummaryThis PR successfully transforms the monolithic system prompt architecture into a modular skill-based system. The implementation adds six built-in skills (git, code-quality, file-operations, debugging, security, planning) that can be loaded on-demand based on task requirements, reducing context window usage from ~2000+ tokens to ~500 tokens base plus only relevant skills. Key Changes:
Architecture Benefits:
Code Quality:
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| src/cortex-prompt-harness/src/prompts/mod.rs | Added exports for new base_agent and builtin_skills modules with clean re-exports |
| src/cortex-prompt-harness/src/prompts/base_agent.rs | New minimal base prompt with skill loading mechanism, comprehensive tests, and skill recommendation logic |
| src/cortex-prompt-harness/src/prompts/builtin_skills.rs | Six built-in skills (git, code-quality, file-operations, debugging, security, planning) with YAML frontmatter and comprehensive documentation |
| src/cortex-engine/src/session/prompt.rs | Added skill-based prompt building functions with auto-detection and injection logic, backward compatible with monolithic mode |
| src/cortex-engine/src/tools/handlers/skill.rs | Enhanced skill handler to load built-in skills with priority over filesystem skills, comprehensive test coverage |
Sequence Diagram
sequenceDiagram
participant User
participant Agent
participant PromptBuilder
participant SkillLoader
participant BuiltinSkills
User->>Agent: "Fix this bug and create a PR"
Agent->>PromptBuilder: Request prompt construction
alt Skill-based mode (USE_SKILL_BASED_PROMPT=true)
PromptBuilder->>PromptBuilder: auto_detect_skills_from_message()
Note over PromptBuilder: Detects: ["debugging", "git"]
PromptBuilder->>PromptBuilder: build_system_prompt_with_skills()
PromptBuilder->>BuiltinSkills: get_builtin_skill("debugging")
BuiltinSkills-->>PromptBuilder: SKILL_DEBUGGING content
PromptBuilder->>BuiltinSkills: get_builtin_skill("git")
BuiltinSkills-->>PromptBuilder: SKILL_GIT content
PromptBuilder->>PromptBuilder: inject_skills(BASE_PROMPT_WITH_SKILLS, skills)
PromptBuilder->>PromptBuilder: strip_yaml_frontmatter()
PromptBuilder-->>Agent: Base prompt + skill instructions (~1500 tokens)
else Monolithic mode
PromptBuilder->>PromptBuilder: build_system_prompt()
PromptBuilder-->>Agent: CORTEX_MAIN_PROMPT (~2000+ tokens)
end
Agent->>Agent: Execute task with loaded skills
opt Agent calls UseSkill tool
Agent->>SkillLoader: UseSkill("security")
SkillLoader->>SkillLoader: load("security")
SkillLoader->>BuiltinSkills: is_builtin_skill("security")
BuiltinSkills-->>SkillLoader: true
SkillLoader->>BuiltinSkills: get_builtin_skill("security")
BuiltinSkills-->>SkillLoader: SKILL_SECURITY content
SkillLoader->>SkillLoader: parse_skill_md(content)
SkillLoader->>SkillLoader: Register in SkillRegistry
SkillLoader-->>Agent: Skill loaded with instructions
end
Agent-->>User: Task completed with appropriate skills
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.
5 files reviewed, no comments
The skill-based prompt functions are public API designed for future integration but are not yet used outside of tests. Add #[allow(dead_code)] annotations to suppress warnings while preserving the API surface. Also applies rustfmt formatting fixes.
- Update session lifecycle to use skill-based prompts by default - Add auto-detection and injection of skills on first user message - Export skill-related functions from session module - Update SwitchAgent handler to use skill-based prompts The skill system now automatically: 1. Starts sessions with a minimal base prompt (reduces context) 2. Detects relevant skills from the first user message 3. Injects detected skill content into the system prompt 4. Allows on-demand skill loading via UseSkill tool This reduces context window usage by only loading relevant instructions based on the task type.
|
waiting for benchmark, don't merge |
Summary
This PR transforms the monolithic system prompt architecture into a modular skill-based system where the agent loads specialized skills on-demand based on task requirements. This reduces context window usage by only including relevant instructions.
Changes
New Files
src/cortex-prompt-harness/src/prompts/builtin_skills.rs- Six built-in skills:git: Version control operations, commits, PRs, branchescode-quality: Linting, testing, style matchingfile-operations: Safe file handling, read-before-write patternsdebugging: Tier 1-4 failure protocol, error recoverysecurity: Secrets handling, input validationplanning: Cognitive architecture, task decompositionsrc/cortex-prompt-harness/src/prompts/base_agent.rs- Minimal base agent prompt with skill loading mechanismModified Files
src/cortex-prompt-harness/src/prompts/mod.rs- Added exports for new modulessrc/cortex-engine/src/session/prompt.rs- Added skill-based prompt building functionssrc/cortex-engine/src/tools/handlers/skill.rs- Added built-in skill support to UseSkill handlerArchitecture
How It Works
load_skill(["git", "debugging"])Skill Loading Examples
load_skill(["git"])load_skill(["debugging", "code-quality"])load_skill(["planning", "code-quality", "file-operations"])Benefits
Testing
Verification