Feature/at agent mention (#8571)
Signed-off-by: Douwe Osinga <douwe@squareup.com> Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
@@ -136,6 +136,7 @@ pub enum CommandType {
|
||||
Builtin,
|
||||
Recipe,
|
||||
Skill,
|
||||
Agent,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
|
||||
@@ -436,6 +437,26 @@ pub async fn get_slash_commands(
|
||||
});
|
||||
}
|
||||
|
||||
let discover_dir = working_dir
|
||||
.as_deref()
|
||||
.unwrap_or_else(|| std::path::Path::new("."));
|
||||
for source in
|
||||
goose::agents::platform_extensions::summon::discover_filesystem_sources(discover_dir)
|
||||
{
|
||||
use goose::agents::platform_extensions::SourceKind;
|
||||
if matches!(
|
||||
source.kind,
|
||||
SourceKind::Agent | SourceKind::Recipe | SourceKind::Subrecipe
|
||||
) && !source.content.is_empty()
|
||||
{
|
||||
commands.push(SlashCommand {
|
||||
command: source.name,
|
||||
help: source.description,
|
||||
command_type: CommandType::Agent,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Json(SlashCommandsResponse { commands }))
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ use crate::agents::extension_manager::{
|
||||
get_parameter_names, ExtensionManager, ExtensionManagerCapabilities,
|
||||
};
|
||||
use crate::agents::final_output_tool::{FINAL_OUTPUT_CONTINUATION_MESSAGE, FINAL_OUTPUT_TOOL_NAME};
|
||||
use crate::agents::platform_extensions::summon::discover_filesystem_sources;
|
||||
use crate::agents::platform_extensions::MANAGE_EXTENSIONS_TOOL_NAME_COMPLETE;
|
||||
use crate::agents::platform_tools::PLATFORM_MANAGE_SCHEDULE_TOOL_NAME;
|
||||
use crate::agents::prompt_manager::PromptManager;
|
||||
@@ -354,10 +355,17 @@ impl Agent {
|
||||
}
|
||||
let initial_messages = conversation.messages().clone();
|
||||
|
||||
let (tools, toolshim_tools, system_prompt) = self
|
||||
let (tools, toolshim_tools, mut system_prompt) = self
|
||||
.prepare_tools_and_prompt(session_id, working_dir)
|
||||
.await?;
|
||||
|
||||
if let Some(instructions) = self.resolve_at_mention(&conversation, working_dir) {
|
||||
system_prompt = format!(
|
||||
"{}\n\n# Instructions from active agent:\n\n{}",
|
||||
system_prompt, instructions
|
||||
);
|
||||
}
|
||||
|
||||
let goose_mode = *self.current_goose_mode.lock().await;
|
||||
|
||||
if goose_mode == GooseMode::SmartApprove {
|
||||
@@ -391,6 +399,30 @@ impl Agent {
|
||||
})
|
||||
}
|
||||
|
||||
fn resolve_at_mention(
|
||||
&self,
|
||||
conversation: &Conversation,
|
||||
working_dir: &std::path::Path,
|
||||
) -> Option<String> {
|
||||
let last_message = conversation.messages().last()?;
|
||||
if last_message.role == rmcp::model::Role::User {
|
||||
let after_at = last_message
|
||||
.as_concat_text()
|
||||
.trim()
|
||||
.strip_prefix('@')?
|
||||
.to_lowercase();
|
||||
|
||||
for source in discover_filesystem_sources(working_dir) {
|
||||
let name = source.name.to_lowercase();
|
||||
let is_match = after_at == name || after_at.starts_with(&format!("{} ", name));
|
||||
if is_match && !source.content.is_empty() {
|
||||
return Some(source.content.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
async fn categorize_tools(
|
||||
&self,
|
||||
response: &Message,
|
||||
|
||||
@@ -218,7 +218,7 @@ fn scan_agents_from_dir(
|
||||
}
|
||||
}
|
||||
|
||||
fn discover_filesystem_sources(working_dir: &Path) -> Vec<Source> {
|
||||
pub fn discover_filesystem_sources(working_dir: &Path) -> Vec<Source> {
|
||||
let mut sources: Vec<Source> = Vec::new();
|
||||
let mut seen: std::collections::HashSet<String> = std::collections::HashSet::new();
|
||||
|
||||
@@ -240,6 +240,7 @@ fn discover_filesystem_sources(working_dir: &Path) -> Vec<Source> {
|
||||
})
|
||||
.chain(
|
||||
[
|
||||
home.as_ref().map(|h| h.join(".goose/recipes")),
|
||||
Some(config.join("recipes")),
|
||||
home.as_ref().map(|h| h.join(".agents/recipes")),
|
||||
]
|
||||
@@ -255,6 +256,7 @@ fn discover_filesystem_sources(working_dir: &Path) -> Vec<Source> {
|
||||
];
|
||||
|
||||
let global_agent_dirs: Vec<PathBuf> = [
|
||||
home.as_ref().map(|h| h.join(".goose/agents")),
|
||||
home.as_ref().map(|h| h.join(".agents/agents")),
|
||||
Some(config.join("agents")),
|
||||
home.as_ref().map(|h| h.join(".claude/agents")),
|
||||
|
||||
Reference in New Issue
Block a user