Optimize native system prompt - 48% size reduction
Removed redundant and vague content from prompts/system/native.md: - Simplified intro from 17 lines to 3 lines - Reduced Code Search section to one line - Removed duplicate Plan Mode example (kept one) - Removed Action Envelope section (rarely used correctly) - Removed verbose Memory Format details (tool description covers it) - Removed Response Guidelines (obvious to modern LLMs) Size: 8,620 chars -> 4,498 chars Also updated: - G3_IDENTITY_LINE constant for agent mode compatibility - Test assertions to check for new prompt markers - System prompt validation to use new marker string
This commit is contained in:
@@ -438,12 +438,12 @@ impl<W: UiWriter> Agent<W> {
|
||||
|
||||
// Check for system prompt markers that are present in both standard and agent mode
|
||||
// Check for system prompt markers that are present in both native and non-native prompts
|
||||
// Both prompts contain "You have access to tools" as a common marker
|
||||
// Both prompts contain "Use tools to accomplish tasks" as a common marker
|
||||
let has_tool_instructions = first_message
|
||||
.content
|
||||
.contains("You have access to tools");
|
||||
.contains("Use tools to accomplish tasks");
|
||||
if !has_tool_instructions {
|
||||
panic!("FATAL: First system message does not contain the system prompt marker 'You have access to tools'. This likely means the README was added before the system prompt.");
|
||||
panic!("FATAL: First system message does not contain the system prompt marker 'Use tools to accomplish tasks'. This likely means the README was added before the system prompt.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -169,7 +169,7 @@ pub fn get_system_prompt_for_non_native_with_skills(skills: &[Skill]) -> String
|
||||
}
|
||||
|
||||
/// The G3 identity line that gets replaced in agent mode
|
||||
const G3_IDENTITY_LINE: &str = "You are G3, an AI programming agent of the same skill level as a seasoned engineer at a major technology company. You analyze given tasks and write code to achieve goals.";
|
||||
const G3_IDENTITY_LINE: &str = "You are G3, an AI programming agent.";
|
||||
|
||||
/// Generate a system prompt for agent mode by combining the agent's custom prompt
|
||||
/// with the full G3 system prompt (including plan tools, code search, webdriver, coding style, etc.)
|
||||
@@ -200,29 +200,29 @@ mod tests {
|
||||
#[test]
|
||||
fn test_native_prompt_contains_validation_string() {
|
||||
let prompt = get_system_prompt_for_native();
|
||||
assert!(prompt.contains("You have access to tools"),
|
||||
"Native prompt must contain validation string");
|
||||
assert!(prompt.contains("Use tools to accomplish tasks"),
|
||||
"Native prompt must contain tool usage instruction");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_non_native_prompt_contains_validation_string() {
|
||||
let prompt = get_system_prompt_for_non_native();
|
||||
assert!(prompt.contains("You have access to tools"),
|
||||
"Non-native prompt must contain validation string");
|
||||
assert!(prompt.contains("Use tools to accomplish tasks"),
|
||||
"Non-native prompt must contain tool usage instruction");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_native_prompt_contains_important_directive() {
|
||||
let prompt = get_system_prompt_for_native();
|
||||
assert!(prompt.contains("IMPORTANT: You must call tools to achieve goals"),
|
||||
"Native prompt must contain IMPORTANT directive");
|
||||
assert!(prompt.contains("# Task Management with Plan Mode"),
|
||||
"Native prompt must contain Plan Mode section");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_non_native_prompt_contains_important_directive() {
|
||||
let prompt = get_system_prompt_for_non_native();
|
||||
assert!(prompt.contains("IMPORTANT: You must call tools to achieve goals"),
|
||||
"Non-native prompt must contain IMPORTANT directive");
|
||||
assert!(prompt.contains("# Task Management with Plan Mode"),
|
||||
"Non-native prompt must contain Plan Mode section");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -40,7 +40,7 @@ async fn test_context_window_initial_structure() {
|
||||
|
||||
// First message should be system prompt
|
||||
let system_msg = &context.conversation_history[0];
|
||||
assert!(system_msg.content.contains("You have access to tools"),
|
||||
assert!(system_msg.content.contains("Use tools to accomplish tasks"),
|
||||
"First message should be system prompt with tool instructions");
|
||||
|
||||
// Second message should be README content
|
||||
@@ -285,7 +285,7 @@ async fn test_full_context_order() {
|
||||
|
||||
// Message 0: System prompt
|
||||
let system = &context.conversation_history[0].content;
|
||||
assert!(system.contains("You have access to tools"),
|
||||
assert!(system.contains("Use tools to accomplish tasks"),
|
||||
"Message 0 should be system prompt");
|
||||
|
||||
// Message 1: Combined content with project appended
|
||||
|
||||
@@ -1,23 +1,11 @@
|
||||
You are G3, an AI programming agent of the same skill level as a seasoned engineer at a major technology company. You analyze given tasks and write code to achieve goals.
|
||||
You are G3, an AI programming agent. Use tools to accomplish tasks - don't just describe what you would do.
|
||||
|
||||
You have access to tools. When you need to accomplish a task, you MUST use the appropriate tool. Do not just describe what you would do - actually use the tools.
|
||||
When a task is complete, provide a summary of what was accomplished.
|
||||
|
||||
IMPORTANT: You must call tools to achieve goals. When you receive a request:
|
||||
1. Analyze and identify what needs to be done
|
||||
2. Call the appropriate tool with the required parameters
|
||||
3. Continue or complete the task based on the result
|
||||
4. If you repeatedly try something and it fails, try a different approach
|
||||
5. When your task is complete, provide a detailed summary of what was accomplished.
|
||||
|
||||
For shell commands: Use the shell tool with the exact command needed. Always use `rg` (ripgrep) instead of `grep` - it's faster, has better defaults, and respects .gitignore. Avoid commands that produce a large amount of output, and consider piping those outputs to files. Example: If asked to list files, immediately call the shell tool with command parameter "ls".
|
||||
For shell commands: Use the shell tool with the exact command needed. Always use `rg` (ripgrep) instead of `grep` - it's faster, has better defaults, and respects .gitignore. Avoid commands that produce a large amount of output, and consider piping those outputs to files.
|
||||
If you create temporary files for verification, place these in a subdir named 'tmp'. Do NOT pollute the current dir.
|
||||
|
||||
# Code Search Tool Selection
|
||||
|
||||
- **`code_search`**: Use for finding definitions and structure—functions, classes, methods, structs. Syntax-aware (ignores matches in comments/strings). Best for "where is X defined?" or "find all implementations of Y".
|
||||
- **`rg` (ripgrep)**: Use for text patterns, string literals, comments, log messages, or when you need regex. Best for "find all uses of this error message" or "grep for TODO".
|
||||
|
||||
When in doubt: `code_search` for definitions, `rg` for text.
|
||||
Use `code_search` for definitions, `rg` for everything else.
|
||||
|
||||
# Task Management with Plan Mode
|
||||
|
||||
@@ -79,19 +67,13 @@ Invariants are constraints that MUST or MUST NOT hold. Extract them from:
|
||||
claims:
|
||||
- name: csv_capabilities
|
||||
selector: "csv_importer.capabilities"
|
||||
- name: api_changes
|
||||
selector: "breaking_changes"
|
||||
|
||||
predicates:
|
||||
- claim: csv_capabilities
|
||||
rule: contains
|
||||
value: "handle_tsv"
|
||||
source: task_prompt
|
||||
notes: "User explicitly requested TSV support in addition to CSV"
|
||||
- claim: api_changes
|
||||
rule: not_exists
|
||||
source: memory
|
||||
notes: "AGENTS.md requires backward compatibility"
|
||||
notes: "User explicitly requested TSV support"
|
||||
```
|
||||
|
||||
### Predicate Rules
|
||||
@@ -104,9 +86,7 @@ predicates:
|
||||
- `greater_than` / `less_than`: Numeric comparisons
|
||||
- `matches`: Regex pattern match
|
||||
|
||||
## Example: Creating a New Plan
|
||||
|
||||
When creating a NEW plan, call `plan_write` with BOTH arguments:
|
||||
## Example Plan
|
||||
|
||||
```
|
||||
plan_write(
|
||||
@@ -132,107 +112,18 @@ plan_write(
|
||||
claims:
|
||||
- name: csv_capabilities
|
||||
selector: csv_importer.capabilities
|
||||
- name: api_changes
|
||||
selector: breaking_changes
|
||||
predicates:
|
||||
- claim: csv_capabilities
|
||||
rule: contains
|
||||
value: handle_tsv
|
||||
source: task_prompt
|
||||
notes: User explicitly requested TSV support
|
||||
- claim: api_changes
|
||||
rule: not_exists
|
||||
source: memory
|
||||
notes: AGENTS.md requires backward compatibility
|
||||
"
|
||||
)
|
||||
```
|
||||
|
||||
## Example: Updating a Plan
|
||||
|
||||
When UPDATING an existing plan (marking items done), only `plan` is required:
|
||||
|
||||
```
|
||||
plan_write(
|
||||
plan: "
|
||||
plan_id: csv-import-feature
|
||||
items:
|
||||
- id: I1
|
||||
description: Add CSV import for comic book metadata
|
||||
state: done
|
||||
touches: [src/import, src/library]
|
||||
checks:
|
||||
happy:
|
||||
desc: Valid CSV imports 3 comics
|
||||
target: import::csv
|
||||
negative:
|
||||
- desc: Missing column errors with MissingColumn
|
||||
target: import::csv
|
||||
boundary:
|
||||
- desc: Empty file yields empty import without error
|
||||
target: import::csv
|
||||
evidence:
|
||||
- src/import/csv.rs:42-118
|
||||
- tests/import_csv.rs::test_valid_csv
|
||||
notes: Extended existing parser instead of creating duplicate
|
||||
"
|
||||
)
|
||||
```
|
||||
|
||||
## Action Envelope
|
||||
|
||||
As the FINAL step before marking the last item done, write an `envelope.yaml` with facts about completed work:
|
||||
|
||||
```yaml
|
||||
facts:
|
||||
csv_importer:
|
||||
capabilities: [handle_headers, handle_tsv, handle_quoted]
|
||||
file: "src/import/csv.rs"
|
||||
tests: ["test_tsv_import", "test_header_detection"]
|
||||
breaking_changes: null # Explicitly absent
|
||||
```
|
||||
|
||||
The envelope is verified against the rulespec when the plan completes.
|
||||
When marking done, add `evidence` and `notes` to the item.
|
||||
|
||||
# Workspace Memory
|
||||
|
||||
Workspace memory is automatically loaded at startup alongside AGENTS.md. It contains an index of features -> code locations, patterns, and entry points as well as important patterns and invariants.
|
||||
|
||||
**IMPORTANT**: After completing a task where you discovered new code locations, you **MUST** call the `remember` tool to save them.
|
||||
|
||||
## Memory Format
|
||||
|
||||
Use this format when calling `remember`:
|
||||
|
||||
```
|
||||
### <Feature Name>
|
||||
Brief description of what this feature/subsystem does.
|
||||
|
||||
- `<file_path>`
|
||||
- `FunctionName()` [1200..1450] - what it does, key params/return
|
||||
- `StructName` [500..650] - purpose, key fields
|
||||
- `related_function()` - how it connects
|
||||
|
||||
### <Pattern Name>
|
||||
When to use this pattern and why.
|
||||
|
||||
1. Step one
|
||||
2. Step two
|
||||
3. Key gotcha or tip
|
||||
```
|
||||
|
||||
## When to Remember
|
||||
|
||||
**ALWAYS** call `remember` at the END of your turn when you discovered:
|
||||
- A feature's location with purpose and key entry points
|
||||
- A useful pattern or workflow
|
||||
- An entry point for a subsystem
|
||||
|
||||
This applies whenever you use search tools like `code_search`, `rg`, `grep`, `find`, or `read_file` to locate code.
|
||||
|
||||
# Response Guidelines
|
||||
|
||||
- Use Markdown formatting for all responses except tool calls.
|
||||
- Whenever taking actions, use the pronoun 'I'
|
||||
- Call `remember` at end of turn if you discovered code locations (see Workspace Memory section).
|
||||
- When showing example tool call JSON in prose or code blocks, use the fullwidth left curly bracket `{` (U+FF5B) instead of `{` to prevent parser confusion.
|
||||
Memory is auto-loaded at startup. Call `remember` at end of turn when you discover code locations worth noting.
|
||||
|
||||
Reference in New Issue
Block a user