| 165 | } |
| 166 | |
| 167 | fn explicit_agent_target(prompt: &str, registry: &AgentRegistry) -> Option<String> { |
| 168 | let lower = prompt.to_lowercase(); |
| 169 | let mut aliases = registry |
| 170 | .list() |
| 171 | .into_iter() |
| 172 | .flat_map(agent_explicit_aliases) |
| 173 | .collect::<Vec<_>>(); |
| 174 | aliases.sort_by_key(|alias| std::cmp::Reverse(alias.0.len())); |
| 175 | aliases.dedup(); |
| 176 | |
| 177 | for (alias, target) in aliases { |
| 178 | if contains_explicit_reference(&lower, &alias) { |
| 179 | return Some(target); |
| 180 | } |
| 181 | } |
| 182 | None |
| 183 | } |
| 184 | |
| 185 | fn agent_explicit_aliases(agent: AgentDefinition) -> Vec<(String, String)> { |
| 186 | let target = agent.name.clone(); |