Dynamically refresh skill instructions each turn (#9217)
Signed-off-by: Douwe Osinga <douwe@squareup.com> Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
@@ -106,9 +106,7 @@ impl Extension {
|
||||
}
|
||||
|
||||
fn get_instructions(&self) -> Option<String> {
|
||||
self.server_info
|
||||
.as_ref()
|
||||
.and_then(|info| info.instructions.clone())
|
||||
self.client.get_instructions()
|
||||
}
|
||||
|
||||
fn get_client(&self) -> McpClientBox {
|
||||
|
||||
@@ -84,6 +84,13 @@ pub trait McpClientTrait: Send + Sync {
|
||||
|
||||
fn get_info(&self) -> Option<&InitializeResult>;
|
||||
|
||||
/// Return the extension's current instructions. The default reads from
|
||||
/// `get_info()`, but platform extensions can override this to provide
|
||||
/// dynamically computed instructions (e.g. freshly discovered skills).
|
||||
fn get_instructions(&self) -> Option<String> {
|
||||
self.get_info().and_then(|info| info.instructions.clone())
|
||||
}
|
||||
|
||||
async fn list_resources(
|
||||
&self,
|
||||
_session_id: &str,
|
||||
|
||||
@@ -441,11 +441,9 @@ mod tests {
|
||||
.values()
|
||||
.map(|def| {
|
||||
let client = (def.client_factory)(context.clone());
|
||||
let info = client.get_info();
|
||||
let instructions = info
|
||||
.and_then(|i| i.instructions.clone())
|
||||
.unwrap_or_default();
|
||||
let has_resources = info
|
||||
let instructions = client.get_instructions().unwrap_or_default();
|
||||
let has_resources = client
|
||||
.get_info()
|
||||
.and_then(|i| i.capabilities.resources.as_ref())
|
||||
.is_some();
|
||||
ExtensionInfo::new(def.name, &instructions, has_resources)
|
||||
|
||||
Reference in New Issue
Block a user