Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/goose-mcp/src/developer/rmcp_developer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ use rmcp::{
const WORKING_DIR_HEADER: &str = "agent-working-dir";
const SESSION_ID_HEADER: &str = "agent-session-id";

pub const WORKING_DIR_PLACEHOLDER: &str = "{{WORKING_DIR}}";

fn extract_working_dir_from_meta(meta: &Meta) -> Option<PathBuf> {
meta.0
.get(WORKING_DIR_HEADER)
Expand Down Expand Up @@ -242,8 +244,6 @@ pub struct DeveloperServer {
impl ServerHandler for DeveloperServer {
#[allow(clippy::too_many_lines)]
fn get_info(&self) -> ServerInfo {
// Get base instructions and working directory
let cwd = std::env::current_dir().expect("should have a current working dir");
let os = std::env::consts::OS;
let in_container = Self::is_definitely_container();

Expand All @@ -268,7 +268,7 @@ impl ServerHandler for DeveloperServer {
{container_info}
"#,
os=os,
cwd=cwd.to_string_lossy(),
cwd=WORKING_DIR_PLACEHOLDER,
container_info=if in_container { "container: true" } else { "" },
},
_ => {
Expand All @@ -295,7 +295,7 @@ impl ServerHandler for DeveloperServer {
{container_info}
"#,
os=os,
cwd=cwd.to_string_lossy(),
cwd=WORKING_DIR_PLACEHOLDER,
shell=shell_info,
container_info=if in_container { "container: true" } else { "" },
}
Expand Down
1 change: 1 addition & 0 deletions crates/goose-mcp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub mod tutorial;
pub use autovisualiser::AutoVisualiserRouter;
pub use computercontroller::ComputerControllerServer;
pub use developer::rmcp_developer::DeveloperServer;
pub use developer::rmcp_developer::WORKING_DIR_PLACEHOLDER;
pub use memory::MemoryServer;
pub use tutorial::TutorialServer;

Expand Down
10 changes: 9 additions & 1 deletion crates/goose/src/agents/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1728,7 +1728,15 @@ impl Agent {
) -> Result<Recipe> {
tracing::info!("Starting recipe creation with {} messages", messages.len());

let extensions_info = self.extension_manager.get_extensions_info().await;
let session = self
.config
.session_manager
.get_session(session_id, false)
.await?;
let extensions_info = self
.extension_manager
.get_extensions_info(&session.working_dir)
.await;
tracing::debug!("Retrieved {} extensions info", extensions_info.len());
let (extension_count, tool_count) = self
.extension_manager
Expand Down
12 changes: 6 additions & 6 deletions crates/goose/src/agents/extension_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,17 +791,17 @@ impl ExtensionManager {
}

/// Get extensions info for building the system prompt
pub async fn get_extensions_info(&self) -> Vec<ExtensionInfo> {
pub async fn get_extensions_info(&self, working_dir: &std::path::Path) -> Vec<ExtensionInfo> {
let working_dir_str = working_dir.to_string_lossy();
self.extensions
.lock()
.await
.iter()
.map(|(name, ext)| {
ExtensionInfo::new(
name,
ext.get_instructions().unwrap_or_default().as_str(),
ext.supports_resources(),
)
let instructions = ext.get_instructions().unwrap_or_default();
let instructions =
instructions.replace(goose_mcp::WORKING_DIR_PLACEHOLDER, &working_dir_str);
ExtensionInfo::new(name, &instructions, ext.supports_resources())
})
.collect()
}
Expand Down
5 changes: 4 additions & 1 deletion crates/goose/src/agents/reply_parts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ impl Agent {
tools.sort_by(|a, b| a.name.cmp(&b.name));

// Prepare system prompt
let extensions_info = self.extension_manager.get_extensions_info().await;
let extensions_info = self
.extension_manager
.get_extensions_info(working_dir)
.await;
let (extension_count, tool_count) = self
.extension_manager
.get_extension_and_tool_counts(session_id)
Expand Down
5 changes: 4 additions & 1 deletion crates/goose/tests/providers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ impl ProviderTester {
.await
.expect("get_prefixed_tools failed");

let info = self.extension_manager.get_extensions_info().await;
let info = self
.extension_manager
.get_extensions_info(std::path::Path::new("."))
.await;
let system = PromptManager::new()
.builder()
.with_extensions(info.into_iter())
Expand Down
Loading