Skip to content

Commit

Permalink
add goose configure flow for adjusting amt of tool output shown durin…
Browse files Browse the repository at this point in the history
…g cli usage
  • Loading branch information
laanak08 committed Feb 3, 2025
1 parent 0ca4cf0 commit fcdb1b3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
41 changes: 41 additions & 0 deletions crates/goose-cli/src/commands/configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,13 @@ pub async fn handle_configure() -> Result<(), Box<dyn Error>> {
"Enable or disable connected extensions",
)
.item("add", "Add Extension", "Connect to a new extension")
.item("tool_output", "Adjust Tool Output", "Show more or less tool output")
.interact()?;

match action {
"toggle" => toggle_extensions_dialog(),
"add" => configure_extensions_dialog(),
"tool_output" => configure_tool_output_dialog(),
"providers" => configure_provider_dialog().await.and(Ok(())),
_ => unreachable!(),
}
Expand Down Expand Up @@ -545,3 +547,42 @@ pub fn configure_extensions_dialog() -> Result<(), Box<dyn Error>> {

Ok(())
}

pub fn configure_tool_output_dialog() -> Result<(), Box<dyn Error>> {
let config = Config::global();
let tool_log_level = cliclack::select("Which tool output would you like to show?")
.item(
"high",
"High Importance",
"",
)
.item(
"medium",
"Medium Importance",
"Ex. results of file-writes",
)
.item(
"all",
"All",
"Ex. shell command output",
)
.interact()?;

match tool_log_level {
"high" => {
config.set("GOOSE_CLI_MIN_PRIORITY", Value::from(0.8))?;
cliclack::outro("Showing tool output of high importance only.")?;
}
"med" => {
config.set("GOOSE_CLI_MIN_PRIORITY", Value::from(0.2))?;
cliclack::outro("Showing tool output of medium importance.")?;
}
"all" => {
config.set("GOOSE_CLI_MIN_PRIORITY", Value::from(0.0))?;
cliclack::outro("Showing all tool output.")?;
}
_ => unreachable!(),
};

Ok(())
}
8 changes: 4 additions & 4 deletions crates/goose-cli/src/prompt/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use goose::message::{Message, MessageContent, ToolRequest, ToolResponse};
use mcp_core::role::Role;
use mcp_core::{content::Content, tool::ToolCall};
use serde_json::Value;

use goose::config::Config;
use super::Theme;

const MAX_STRING_LENGTH: usize = 40;
Expand Down Expand Up @@ -267,6 +267,7 @@ pub fn render(message: &Message, theme: &Theme, renderers: HashMap<String, Box<d
}

pub fn default_response_renderer(tool_response: &ToolResponse, theme: &str) {
let config = Config::global();
match &tool_response.tool_result {
Ok(contents) => {
for content in contents {
Expand All @@ -277,15 +278,14 @@ pub fn default_response_renderer(tool_response: &ToolResponse, theme: &str) {
continue;
}

let min_priority = std::env::var("GOOSE_CLI_MIN_PRIORITY")
let min_priority = config.get::<f32>("GOOSE_CLI_MIN_PRIORITY")
.ok()
.and_then(|val| val.parse::<f32>().ok())
.unwrap_or(0.0);

// if priority is not set OR less than or equal to min_priority, do not render
if content
.priority()
.is_some_and(|priority| priority <= min_priority)
.is_some_and(|priority| priority < min_priority)
|| content.priority().is_none()
{
continue;
Expand Down

0 comments on commit fcdb1b3

Please sign in to comment.