-
Notifications
You must be signed in to change notification settings - Fork 1
feat(prompt): tell the agent which model runs it, its subagents, and the advisor #860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1c04ce4
feat(prompt): tell the agent which model runs it, its subagents, and …
matthewyjiang 1a326eb
fix(models): pick up catalog names that land mid-session
matthewyjiang 119b8ce
chore(providers): cut 0.21.0 for the model name API
matthewyjiang 001880f
fix(models): keep model descriptions one line and advisor notices honest
matthewyjiang b793181
refactor(models): purify prompt model labels and centralize switch no…
matthewyjiang ee0866a
refactor(models): drop residual identity wrappers and soft prefetch f…
matthewyjiang b804ab4
refactor(runtime): peel provider switch and finish review/CI cleanup
matthewyjiang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| //! Catalog names for models, for text that people and models read. | ||
| //! | ||
| //! A model id such as `gpt-5.6-sol` is the fact Rho acts on: it selects the | ||
| //! provider route, and it is what a user types back into `/model`. The name is | ||
| //! the fact a person recognizes. Both come from caches Rho already fills, so | ||
| //! nothing here reaches the network, and nothing here invents a name from an id: | ||
| //! an unknown model shows its id alone rather than a guess. | ||
|
|
||
| use std::{ | ||
| collections::HashMap, | ||
| sync::{OnceLock, RwLock}, | ||
| }; | ||
|
|
||
| use crate::model::{models_dev, provider_models}; | ||
|
|
||
| /// Names resolved this process, including the models that have none. | ||
| /// | ||
| /// Two reasons, and both matter. Every lookup otherwise opens a fresh sqlite | ||
| /// connection and runs its schema statements, and these lookups sit on hot | ||
| /// paths: every delegated run listing formats one. And a name that changed | ||
| /// mid-session would rewrite text a caller was already given, which the prompt | ||
| /// surfaces must never do. Resolving once per process fixes both. | ||
| /// | ||
| /// The cost is that a name arriving later - the startup prefetch landing, a | ||
| /// model refresh - is not picked up until the next launch. That is the intended | ||
| /// trade: a stable id beats a name that appears halfway through a session. | ||
| type NameCache = HashMap<(String, String), Option<String>>; | ||
|
|
||
| fn cache() -> &'static RwLock<NameCache> { | ||
| static CACHE: OnceLock<RwLock<NameCache>> = OnceLock::new(); | ||
| CACHE.get_or_init(|| RwLock::new(NameCache::new())) | ||
| } | ||
|
|
||
| /// Catalog name for `provider/model`, or `None` when no catalog carries one. | ||
| /// | ||
| /// The models.dev catalog wins because its names are curated across providers | ||
| /// (`GPT-5.6 Sol`, `Claude Fable 5`). A provider's own model list is the | ||
| /// fallback, and only when it named the model: discovery stores the id as the | ||
| /// display name for providers that publish no name, and echoing the id back as | ||
| /// a name would be noise. | ||
| /// | ||
| /// Resolved once per process; see [`NameCache`]. | ||
| pub fn model_display_name(provider: &str, model: &str) -> Option<String> { | ||
| let key = (provider.to_string(), model.to_string()); | ||
| if let Some(name) = cache().read().expect("model name cache").get(&key) { | ||
| return name.clone(); | ||
| } | ||
| let name = read_model_display_name(provider, model); | ||
| cache() | ||
| .write() | ||
| .expect("model name cache") | ||
| .insert(key, name.clone()); | ||
| name | ||
| } | ||
|
|
||
| fn read_model_display_name(provider: &str, model: &str) -> Option<String> { | ||
| if let Some(name) = models_dev::cached_model_metadata(provider, model) | ||
| .and_then(|metadata| metadata.display_name) | ||
| { | ||
| return Some(name); | ||
| } | ||
| provider_models::cached_provider_model(provider, model) | ||
| .map(|entry| entry.display_name) | ||
| .filter(|name| name != model) | ||
| } | ||
|
|
||
| /// Drops resolved names so a test can write a catalog row and read it back. | ||
| #[doc(hidden)] | ||
| pub fn clear_model_display_name_cache_for_tests() { | ||
| cache().write().expect("model name cache").clear(); | ||
| } | ||
|
|
||
| /// `provider/model (Catalog Name)`, or `provider/model` when no name is known. | ||
| /// | ||
| /// The id stays first and always present: it is the part a caller can act on. | ||
| pub fn model_reference_with_display_name(provider: &str, model: &str) -> String { | ||
| let reference = crate::provider::model_reference(provider, model); | ||
| match model_display_name(provider, model) { | ||
| Some(name) => format!("{reference} ({name})"), | ||
| None => reference, | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| #[path = "display_name_tests.rs"] | ||
| mod tests; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| use pretty_assertions::assert_eq; | ||
|
|
||
| use super::*; | ||
| use crate::model::{ | ||
| models_dev::{ | ||
| with_models_dev_cache_dir_for_tests, write_cached_model_metadata_for_tests, ModelMetadata, | ||
| }, | ||
| provider_models::{ | ||
| replace_cached_provider_models_for_tests, with_provider_models_cache_dir_for_tests, | ||
| ProviderModel, | ||
| }, | ||
| ReasoningCapabilities, | ||
| }; | ||
|
|
||
| /// Runs `f` against empty models.dev and provider-model caches. | ||
| fn with_empty_caches<T>(f: impl FnOnce() -> T) -> T { | ||
| let catalog = tempfile::tempdir().unwrap(); | ||
| let provider = tempfile::tempdir().unwrap(); | ||
| with_models_dev_cache_dir_for_tests(catalog.path().to_path_buf(), || { | ||
| with_provider_models_cache_dir_for_tests(provider.path().to_path_buf(), || { | ||
| // Names resolve once per process; each case needs a fresh read. | ||
| clear_model_display_name_cache_for_tests(); | ||
| f() | ||
| }) | ||
| }) | ||
| } | ||
|
|
||
| fn named_metadata(display_name: &str) -> ModelMetadata { | ||
| ModelMetadata { | ||
| display_name: Some(display_name.to_string()), | ||
| reasoning_metadata_complete: true, | ||
| ..ModelMetadata::default() | ||
| } | ||
| } | ||
|
|
||
| fn provider_model(model: &str, display_name: &str) -> ProviderModel { | ||
| ProviderModel { | ||
| provider: "anthropic".into(), | ||
| model: model.into(), | ||
| display_name: display_name.into(), | ||
| context_window: None, | ||
| max_output_tokens: None, | ||
| reasoning_capabilities: ReasoningCapabilities::Unknown, | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn prefers_the_catalog_name_then_the_provider_name_then_nothing() { | ||
| struct Case { | ||
| name: &'static str, | ||
| catalog: Option<ModelMetadata>, | ||
| provider_models: Vec<ProviderModel>, | ||
| expected_name: Option<&'static str>, | ||
| expected_reference: &'static str, | ||
| } | ||
|
|
||
| let cases = [ | ||
| Case { | ||
| name: "catalog name wins over the provider name", | ||
| catalog: Some(named_metadata("Claude Fable 5")), | ||
| provider_models: vec![provider_model("claude-fable-5", "Claude Fable 5 (latest)")], | ||
| expected_name: Some("Claude Fable 5"), | ||
| expected_reference: "anthropic/claude-fable-5 (Claude Fable 5)", | ||
| }, | ||
| Case { | ||
| name: "provider name fills in when the catalog has none", | ||
| catalog: None, | ||
| provider_models: vec![provider_model("claude-fable-5", "Claude Fable 5")], | ||
| expected_name: Some("Claude Fable 5"), | ||
| expected_reference: "anthropic/claude-fable-5 (Claude Fable 5)", | ||
| }, | ||
| Case { | ||
| name: "a provider name equal to the id is not a name", | ||
| catalog: None, | ||
| provider_models: vec![provider_model("claude-fable-5", "claude-fable-5")], | ||
| expected_name: None, | ||
| expected_reference: "anthropic/claude-fable-5", | ||
| }, | ||
| Case { | ||
| name: "an unknown model shows its id alone", | ||
| catalog: None, | ||
| provider_models: Vec::new(), | ||
| expected_name: None, | ||
| expected_reference: "anthropic/claude-fable-5", | ||
| }, | ||
| ]; | ||
|
|
||
| for case in cases { | ||
| with_empty_caches(|| { | ||
| if let Some(metadata) = &case.catalog { | ||
| write_cached_model_metadata_for_tests("anthropic", "claude-fable-5", metadata); | ||
| } | ||
| replace_cached_provider_models_for_tests("anthropic", &case.provider_models).unwrap(); | ||
|
|
||
| assert_eq!( | ||
| model_display_name("anthropic", "claude-fable-5").as_deref(), | ||
| case.expected_name, | ||
| "{}", | ||
| case.name | ||
| ); | ||
| assert_eq!( | ||
| model_reference_with_display_name("anthropic", "claude-fable-5"), | ||
| case.expected_reference, | ||
| "{}", | ||
| case.name | ||
| ); | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.