Make the system prompt smaller (#6991)
Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
@@ -443,7 +443,8 @@ impl Agent {
|
||||
let created_final_output_tool = FinalOutputTool::new(response);
|
||||
let final_output_system_prompt = created_final_output_tool.system_prompt();
|
||||
*final_output_tool = Some(created_final_output_tool);
|
||||
self.extend_system_prompt(final_output_system_prompt).await;
|
||||
self.extend_system_prompt("final_output".to_string(), final_output_system_prompt)
|
||||
.await;
|
||||
}
|
||||
|
||||
pub async fn apply_recipe_components(
|
||||
@@ -1533,9 +1534,9 @@ impl Agent {
|
||||
}))
|
||||
}
|
||||
|
||||
pub async fn extend_system_prompt(&self, instruction: String) {
|
||||
pub async fn extend_system_prompt(&self, key: String, instruction: String) {
|
||||
let mut prompt_manager = self.prompt_manager.lock().await;
|
||||
prompt_manager.add_system_prompt_extra(instruction);
|
||||
prompt_manager.add_system_prompt_extra(key, instruction);
|
||||
}
|
||||
|
||||
pub async fn update_provider(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#[cfg(test)]
|
||||
use chrono::DateTime;
|
||||
use chrono::Utc;
|
||||
use indexmap::IndexMap;
|
||||
use serde::Serialize;
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
@@ -19,7 +20,7 @@ const MAX_TOOLS: usize = 50;
|
||||
|
||||
pub struct PromptManager {
|
||||
system_prompt_override: Option<String>,
|
||||
system_prompt_extras: Vec<String>,
|
||||
system_prompt_extras: IndexMap<String, String>,
|
||||
current_date_timestamp: String,
|
||||
}
|
||||
|
||||
@@ -173,24 +174,25 @@ impl<'a> SystemPromptBuilder<'a, PromptManager> {
|
||||
|
||||
// Add hints if provided
|
||||
if let Some(hints) = self.hints {
|
||||
system_prompt_extras.push(hints);
|
||||
system_prompt_extras.insert("hints".to_string(), hints);
|
||||
}
|
||||
|
||||
if goose_mode == GooseMode::Chat {
|
||||
system_prompt_extras.push(
|
||||
system_prompt_extras.insert(
|
||||
"chat_mode".to_string(),
|
||||
"Right now you are in the chat only mode, no access to any tool use and system."
|
||||
.to_string(),
|
||||
);
|
||||
}
|
||||
|
||||
let sanitized_system_prompt_extras: Vec<String> = system_prompt_extras
|
||||
.into_iter()
|
||||
.map(|extra| sanitize_unicode_tags(&extra))
|
||||
.collect();
|
||||
|
||||
if sanitized_system_prompt_extras.is_empty() {
|
||||
if system_prompt_extras.is_empty() {
|
||||
base_prompt
|
||||
} else {
|
||||
let sanitized_system_prompt_extras: Vec<String> = system_prompt_extras
|
||||
.into_values()
|
||||
.map(|extra| sanitize_unicode_tags(&extra))
|
||||
.collect();
|
||||
|
||||
format!(
|
||||
"{}\n\n# Additional Instructions:\n\n{}",
|
||||
base_prompt,
|
||||
@@ -204,7 +206,7 @@ impl PromptManager {
|
||||
pub fn new() -> Self {
|
||||
PromptManager {
|
||||
system_prompt_override: None,
|
||||
system_prompt_extras: Vec::new(),
|
||||
system_prompt_extras: IndexMap::new(),
|
||||
// Use the fixed current date time so that prompt cache can be used.
|
||||
// Filtering to an hour to balance user time accuracy and multi session prompt cache hits.
|
||||
current_date_timestamp: Utc::now().format("%Y-%m-%d %H:00").to_string(),
|
||||
@@ -215,14 +217,15 @@ impl PromptManager {
|
||||
pub fn with_timestamp(dt: DateTime<Utc>) -> Self {
|
||||
PromptManager {
|
||||
system_prompt_override: None,
|
||||
system_prompt_extras: Vec::new(),
|
||||
system_prompt_extras: IndexMap::new(),
|
||||
current_date_timestamp: dt.format("%Y-%m-%d %H:%M:%S").to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Add an additional instruction to the system prompt
|
||||
pub fn add_system_prompt_extra(&mut self, instruction: String) {
|
||||
self.system_prompt_extras.push(instruction);
|
||||
/// Add an additional instruction to the system prompt with a key
|
||||
/// Using the same key will replace the previous instruction
|
||||
pub fn add_system_prompt_extra(&mut self, key: String, instruction: String) {
|
||||
self.system_prompt_extras.insert(key, instruction);
|
||||
}
|
||||
|
||||
/// Override the system prompt with custom text
|
||||
@@ -275,7 +278,7 @@ mod tests {
|
||||
fn test_build_system_prompt_sanitizes_extras() {
|
||||
let mut manager = PromptManager::new();
|
||||
let malicious_extra = "Extra instruction\u{E0041}\u{E0042}\u{E0043}hidden";
|
||||
manager.add_system_prompt_extra(malicious_extra.to_string());
|
||||
manager.add_system_prompt_extra("test".to_string(), malicious_extra.to_string());
|
||||
|
||||
let result = manager.builder().build();
|
||||
|
||||
@@ -289,9 +292,14 @@ mod tests {
|
||||
#[test]
|
||||
fn test_build_system_prompt_sanitizes_multiple_extras() {
|
||||
let mut manager = PromptManager::new();
|
||||
manager.add_system_prompt_extra("First\u{E0041}instruction".to_string());
|
||||
manager.add_system_prompt_extra("Second\u{E0042}instruction".to_string());
|
||||
manager.add_system_prompt_extra("Third\u{E0043}instruction".to_string());
|
||||
manager
|
||||
.add_system_prompt_extra("test1".to_string(), "First\u{E0041}instruction".to_string());
|
||||
manager.add_system_prompt_extra(
|
||||
"test2".to_string(),
|
||||
"Second\u{E0042}instruction".to_string(),
|
||||
);
|
||||
manager
|
||||
.add_system_prompt_extra("test3".to_string(), "Third\u{E0043}instruction".to_string());
|
||||
|
||||
let result = manager.builder().build();
|
||||
|
||||
@@ -307,7 +315,7 @@ mod tests {
|
||||
fn test_build_system_prompt_preserves_legitimate_unicode_in_extras() {
|
||||
let mut manager = PromptManager::new();
|
||||
let legitimate_unicode = "Instruction with 世界 and 🌍 emojis";
|
||||
manager.add_system_prompt_extra(legitimate_unicode.to_string());
|
||||
manager.add_system_prompt_extra("test".to_string(), legitimate_unicode.to_string());
|
||||
|
||||
let result = manager.builder().build();
|
||||
|
||||
|
||||
@@ -5,35 +5,14 @@ expression: system_prompt
|
||||
You are a general-purpose AI agent called goose, created by Block, the parent company of Square, CashApp, and Tidal.
|
||||
goose is being developed as an open-source software project.
|
||||
|
||||
goose uses LLM providers with tool calling capability. You can be used with different language models (gpt-4o,
|
||||
claude-sonnet-4, o1, llama-3.2, deepseek-r1, etc).
|
||||
These models have varying knowledge cut-off dates depending on when they were trained, but typically it's between 5-10
|
||||
months prior to the current date.
|
||||
|
||||
# Extensions
|
||||
|
||||
Extensions allow other applications to provide context to goose. Extensions connect goose to different data sources and
|
||||
tools.
|
||||
You are capable of dynamically plugging into new extensions and learning how to use them. You solve higher level
|
||||
problems using the tools in these extensions, and can interact with multiple at once.
|
||||
|
||||
If the Extension Manager extension is enabled, you can use the search_available_extensions tool to discover additional
|
||||
extensions that can help with your task. To enable or disable extensions, use the manage_extensions tool with the
|
||||
extension_name. You should only enable extensions found from the search_available_extensions tool.
|
||||
If Extension Manager is not available, you can only work with currently enabled extensions and cannot dynamically load
|
||||
new ones.
|
||||
Extensions provide additional tools and context from different data sources and applications.
|
||||
You can dynamically enable or disable extensions as needed to help complete tasks.
|
||||
|
||||
No extensions are defined. You should let the user know that they should add extensions.
|
||||
|
||||
|
||||
# Response Guidelines
|
||||
|
||||
- Use Markdown formatting for all responses.
|
||||
- Follow best practices for Markdown, including:
|
||||
- Using headers for organization.
|
||||
- Bullet points for lists.
|
||||
- Links formatted correctly, either as linked text (e.g., [this is linked text](https://example.com)) or automatic
|
||||
links using angle brackets (e.g., <http://example.com/>).
|
||||
- For code examples, use fenced code blocks by placing triple backticks (` ``` `) before and after the code. Include the
|
||||
language identifier after the opening backticks (e.g., ` ```python `) to enable syntax highlighting.
|
||||
- Ensure clarity, conciseness, and proper formatting to enhance readability and usability.
|
||||
Use Markdown formatting for all responses.
|
||||
|
||||
+4
-26
@@ -5,23 +5,10 @@ expression: system_prompt
|
||||
You are a general-purpose AI agent called goose, created by Block, the parent company of Square, CashApp, and Tidal.
|
||||
goose is being developed as an open-source software project.
|
||||
|
||||
goose uses LLM providers with tool calling capability. You can be used with different language models (gpt-4o,
|
||||
claude-sonnet-4, o1, llama-3.2, deepseek-r1, etc).
|
||||
These models have varying knowledge cut-off dates depending on when they were trained, but typically it's between 5-10
|
||||
months prior to the current date.
|
||||
|
||||
# Extensions
|
||||
|
||||
Extensions allow other applications to provide context to goose. Extensions connect goose to different data sources and
|
||||
tools.
|
||||
You are capable of dynamically plugging into new extensions and learning how to use them. You solve higher level
|
||||
problems using the tools in these extensions, and can interact with multiple at once.
|
||||
|
||||
If the Extension Manager extension is enabled, you can use the search_available_extensions tool to discover additional
|
||||
extensions that can help with your task. To enable or disable extensions, use the manage_extensions tool with the
|
||||
extension_name. You should only enable extensions found from the search_available_extensions tool.
|
||||
If Extension Manager is not available, you can only work with currently enabled extensions and cannot dynamically load
|
||||
new ones.
|
||||
Extensions provide additional tools and context from different data sources and applications.
|
||||
You can dynamically enable or disable extensions as needed to help complete tasks.
|
||||
|
||||
Because you dynamically load extensions, your conversation history may refer
|
||||
to interactions with extensions that are not currently active. The currently
|
||||
@@ -31,20 +18,11 @@ in your tool specification.
|
||||
|
||||
## test
|
||||
|
||||
test supports resources, you can use extensionmanager__read_resource,
|
||||
and extensionmanager__list_resources on this extension.
|
||||
test supports resources.
|
||||
### Instructions
|
||||
how to use this extension
|
||||
|
||||
|
||||
# Response Guidelines
|
||||
|
||||
- Use Markdown formatting for all responses.
|
||||
- Follow best practices for Markdown, including:
|
||||
- Using headers for organization.
|
||||
- Bullet points for lists.
|
||||
- Links formatted correctly, either as linked text (e.g., [this is linked text](https://example.com)) or automatic
|
||||
links using angle brackets (e.g., <http://example.com/>).
|
||||
- For code examples, use fenced code blocks by placing triple backticks (` ``` `) before and after the code. Include the
|
||||
language identifier after the opening backticks (e.g., ` ```python `) to enable syntax highlighting.
|
||||
- Ensure clarity, conciseness, and proper formatting to enhance readability and usability.
|
||||
Use Markdown formatting for all responses.
|
||||
|
||||
+6
-34
@@ -5,23 +5,10 @@ expression: system_prompt
|
||||
You are a general-purpose AI agent called goose, created by Block, the parent company of Square, CashApp, and Tidal.
|
||||
goose is being developed as an open-source software project.
|
||||
|
||||
goose uses LLM providers with tool calling capability. You can be used with different language models (gpt-4o,
|
||||
claude-sonnet-4, o1, llama-3.2, deepseek-r1, etc).
|
||||
These models have varying knowledge cut-off dates depending on when they were trained, but typically it's between 5-10
|
||||
months prior to the current date.
|
||||
|
||||
# Extensions
|
||||
|
||||
Extensions allow other applications to provide context to goose. Extensions connect goose to different data sources and
|
||||
tools.
|
||||
You are capable of dynamically plugging into new extensions and learning how to use them. You solve higher level
|
||||
problems using the tools in these extensions, and can interact with multiple at once.
|
||||
|
||||
If the Extension Manager extension is enabled, you can use the search_available_extensions tool to discover additional
|
||||
extensions that can help with your task. To enable or disable extensions, use the manage_extensions tool with the
|
||||
extension_name. You should only enable extensions found from the search_available_extensions tool.
|
||||
If Extension Manager is not available, you can only work with currently enabled extensions and cannot dynamically load
|
||||
new ones.
|
||||
Extensions provide additional tools and context from different data sources and applications.
|
||||
You can dynamically enable or disable extensions as needed to help complete tasks.
|
||||
|
||||
Because you dynamically load extensions, your conversation history may refer
|
||||
to interactions with extensions that are not currently active. The currently
|
||||
@@ -31,8 +18,7 @@ in your tool specification.
|
||||
|
||||
## extension_A
|
||||
|
||||
extension_A supports resources, you can use extensionmanager__read_resource,
|
||||
and extensionmanager__list_resources on this extension.
|
||||
extension_A supports resources.
|
||||
### Instructions
|
||||
<instructions on how to use extension A>
|
||||
## extension_B
|
||||
@@ -42,23 +28,9 @@ and extensionmanager__list_resources on this extension.
|
||||
|
||||
# Suggestion
|
||||
|
||||
The user currently has enabled 6 extensions with a total of 51 tools.
|
||||
Since this exceeds the recommended limits (5 extensions or 50 tools),
|
||||
you should ask the user if they would like to disable some extensions for this session.
|
||||
|
||||
Use the search_available_extensions tool to find extensions available to disable.
|
||||
You should only disable extensions found from the search_available_extensions tool.
|
||||
List all the extensions available to disable in the response.
|
||||
Explain that minimizing extensions helps with the recall of the correct tools to use.
|
||||
The user has 6 extensions with 51 tools enabled, exceeding recommended limits (5 extensions or 50 tools).
|
||||
Consider asking if they'd like to disable some extensions to improve tool selection accuracy.
|
||||
|
||||
# Response Guidelines
|
||||
|
||||
- Use Markdown formatting for all responses.
|
||||
- Follow best practices for Markdown, including:
|
||||
- Using headers for organization.
|
||||
- Bullet points for lists.
|
||||
- Links formatted correctly, either as linked text (e.g., [this is linked text](https://example.com)) or automatic
|
||||
links using angle brackets (e.g., <http://example.com/>).
|
||||
- For code examples, use fenced code blocks by placing triple backticks (` ``` `) before and after the code. Include the
|
||||
language identifier after the opening backticks (e.g., ` ```python `) to enable syntax highlighting.
|
||||
- Ensure clarity, conciseness, and proper formatting to enhance readability and usability.
|
||||
Use Markdown formatting for all responses.
|
||||
|
||||
Reference in New Issue
Block a user