// Check for system prompt markers that are present in both standard and agent mode
// Agent mode replaces the identity line but keeps all other instructions
// 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
lethas_tool_instructions=first_message
.content
.contains("IMPORTANT: You must call tools to achieve goals");
.contains("You have access to tools");
if!has_tool_instructions{
panic!("FATAL: First system message does not contain the system prompt. This likely means the README was added before the system prompt.");
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.");
"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 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 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.
@@ -11,8 +16,9 @@ IMPORTANT: You must call tools to achieve goals. When you receive a request:
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\".
If you create temporary files for verification, place these in a subdir named 'tmp'. Do NOT pollute the current dir.
If you create temporary files for verification, place these in a subdir named 'tmp'. Do NOT pollute the current dir.";
constSHARED_TODO_SECTION: &str="\
# Task Management with TODO Tools
**REQUIRED for multi-step tasks.** Use TODO tools when your task involves ANY of:
@@ -75,12 +81,14 @@ Keep items short, specific, and action-oriented.
✓ Helps recover from interruptions
✓ Creates better summaries
If you can complete it with 1-2 tool calls, skip TODO.
If you can complete it with 1-2 tool calls, skip TODO.";
constSHARED_TEMPORARY_FILES: &str="\
# Temporary files
If you create temporary files for verification or investigation, place these in a subdir named 'tmp'. Do NOT pollute the current dir.
If you create temporary files for verification or investigation, place these in a subdir named 'tmp'. Do NOT pollute the current dir.";
constSHARED_WEB_RESEARCH: &str="\
# Web Research
When you need to look up documentation, search for resources, find data online, or research a topic to complete your task, use the `research` tool.
@@ -95,13 +103,14 @@ Simply call `research` with a specific query describing what you need to know. T
IMPORTANT: If the user asks you to just respond with text (like \"just say hello\" or \"tell me about X\"), do NOT use tools. Simply respond with the requested text directly. Only use tools when you need to execute commands or complete tasks that require action.
Do not explain what you're going to do - just do it by calling the tools.
Do not explain what you're going to do - just do it by calling the tools.";
constSHARED_WORKSPACE_MEMORY: &str="\
# Workspace Memory
Workspace memory is automatically loaded at startup alongside README.md and AGENTS.md. It contains an index of features -> code locations, patterns, and entry points. If you need to re-read memory from disk (e.g., after another agent updates it), use `read_file analysis/memory.md`.
**IMPORTANT**: After completing a task where you discovered code locations, you **MUST** call the `remember` tool to save them..
**IMPORTANT**: After completing a task where you discovered code locations, you **MUST** call the `remember` tool to save them.
## Memory Format
@@ -143,33 +152,27 @@ After discovering how session continuation works:
After discovering a useful pattern:
{\"tool\": \"remember\", \"args\": {\"notes\": \"### UTF-8 Safe String Slicing\\nRust string slices use byte indices. Multi-byte chars (emoji, CJK) cause panics if sliced mid-character.\\n\\n1. Use `s.char_indices().nth(n)` to get byte index of Nth character\\n2. Use `s.chars().count()` for length, not `s.len()`\\n3. Danger zones: display truncation, user input, any non-ASCII text\"}}
{\"tool\": \"remember\", \"args\": {\"notes\": \"### UTF-8 Safe String Slicing\\nRust string slices use byte indices. Multi-byte chars (emoji, CJK) cause panics if sliced mid-character.\\n\\n1. Use `s.char_indices().nth(n)` to get byte index of Nth character\\n2. Use `s.chars().count()` for length, not `s.len()`\\n3. Danger zones: display truncation, user input, any non-ASCII text\"}}";
constSHARED_RESPONSE_GUIDELINES: &str="\
# Response Guidelines
- Use Markdown formatting for all responses except tool calls.
- Whenever taking actions, use the pronoun 'I'
- When you discover features, patterns and code locations, call `remember` to save them.
- 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.
";
- 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.";
/// Generate system prompt based on whether multiple tool calls are allowed
pubfnget_system_prompt_for_native()-> String{
SYSTEM_PROMPT_FOR_NATIVE_TOOL_USE.to_string()
}
constSYSTEM_NON_NATIVE_TOOL_USE: &'staticstr=
"You are G3, a general-purpose AI agent. Your goal is to analyze and solve problems by writing code.
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.
- Use at the END of your turn after discovering code locations via search tools";
constNON_NATIVE_INSTRUCTIONS: &str="\
# Instructions
1. Analyze the request and break down into smaller tasks if appropriate
@@ -240,6 +242,10 @@ Short description for providers without native calling specs:
3. STOP when the original request was satisfied
4. When your task is complete, provide a detailed summary of what was accomplished
IMPORTANT: If the user asks you to just respond with text (like \"just say hello\" or \"tell me about X\"), do NOT use tools. Simply respond with the requested text directly. Only use tools when you need to execute commands or complete tasks that require action.
Do not explain what you're going to do - just do it by calling the tools.
For reading files, prioritize use of code_search tool use with multiple search requests per call instead of read_file, if it makes sense.
Exception to using ONE tool at a time:
@@ -256,104 +262,53 @@ But NOT:
write_file(\"helper.rs\", \"...\")
write_file(\"file2.txt\", \"...\")
write_file(\"helper.rs\", \"...\")
[DONE]
[DONE]";
# Task Management with TODO Tools
**REQUIRED for multi-step tasks.** Use TODO tools when your task involves ANY of:
- Multiple files to create/modify (2+)
- Multiple distinct steps (3+)
- Dependencies between steps
- Testing or verification needed
- Uncertainty about approach
## Workflow
Every multi-step task follows this pattern:
1. **Start**: Call todo_read, then todo_write to create your plan
2. **During**: Execute steps, then todo_read and todo_write to mark progress
3. **End**: Call todo_read to verify all items complete
Note: todo_write replaces the entire list, so always read first to preserve content.
constNON_NATIVE_TODO_ADDENDUM: &str="
IMPORTANT: If you are provided with a SHA256 hash of the requirements file, you MUST include it as the very first line of the todo.g3.md file in the following format:
`{{Based on the requirements file with SHA256: <SHA>}}`
This ensures the TODO list is tracked against the specific version of requirements it was generated from.
This ensures the TODO list is tracked against the specific version of requirements it was generated from.";
If you can complete it with 1-2 tool calls, skip TODO.
# Workspace Memory
Workspace memory (if available) is automatically loaded at startup. It contains feature locations and patterns discovered in previous sessions. If you need to re-read memory from disk (e.g., after another agent updates it), use `read_file analysis/memory.md`.
**ALWAYS** call `remember` at the END of your turn when you discovered:
- A feature's location (file + char range + function/struct names)
- 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.
Do NOT save duplicates - check the Workspace Memory section (loaded at startup) to see what's already known.
# Response Guidelines
- Use Markdown formatting for all responses except tool calls.
- Whenever taking actions, use the pronoun 'I'
- After discovering code locations via search tools, call `remember` to save them.
- 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.
/// Generate system prompt for non-native tool calling providers (embedded models)
pubfnget_system_prompt_for_non_native()-> String{
format!(
"{}\n\n{}\n\n{}\n\n{}{}\n\n{}\n\n{}\n\n{}",
SHARED_INTRO,
NON_NATIVE_TOOL_FORMAT,
NON_NATIVE_INSTRUCTIONS,
SHARED_TODO_SECTION,
NON_NATIVE_TODO_ADDENDUM,
SHARED_WEB_RESEARCH,
SHARED_WORKSPACE_MEMORY,
SHARED_RESPONSE_GUIDELINES
)
}
/// The G3 identity line that gets replaced in agent mode
constG3_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.";
@@ -371,3 +326,80 @@ pub fn get_agent_system_prompt(agent_prompt: &str, allow_multiple_tool_calls: bo
// Replace only the G3 identity line with the custom agent prompt
assert!(system.contains("IMPORTANT: You must call tools"),
assert!(system.contains("You have access to tools"),
"Message 0 should be system prompt");
// Message 1: Combined content with project appended
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.