Skip to content

Commit

Permalink
feat: simplify initial session splash (#362)
Browse files Browse the repository at this point in the history
  • Loading branch information
baxen authored Nov 27, 2024
1 parent 9f60e31 commit 4fa9c2a
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 96 deletions.
2 changes: 1 addition & 1 deletion crates/goose-cli/src/agents/mock_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct MockAgent;
#[async_trait]
impl Agent for MockAgent {
fn add_system(&mut self, _system: Box<dyn System>) {
()

}

async fn reply(&self, _messages: &[Message]) -> Result<BoxStream<'_, Result<Message>>> {
Expand Down
29 changes: 15 additions & 14 deletions crates/goose-cli/src/commands/session.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use console::style;
use rand::{distributions::Alphanumeric, Rng};
use std::path::{Path, PathBuf};

use goose::agent::Agent;
use goose::models::message::Message;
use goose::providers::factory;

use crate::commands::expected_config::get_recommended_models;
Expand All @@ -11,7 +11,6 @@ use crate::profile::{
};
use crate::prompt::cliclack::CliclackPrompt;
use crate::prompt::rustyline::RustylinePrompt;
use crate::prompt::thinking::get_random_goose_action;
use crate::prompt::Prompt;
use crate::session::{ensure_session_dir, Session};

Expand Down Expand Up @@ -48,7 +47,7 @@ pub fn build_session<'a>(
// TODO: Odd to be prepping the provider rather than having that done in the agent?
let provider = factory::get_provider(provider_config).unwrap();
let agent = Box::new(Agent::new(provider));
let mut prompt = match std::env::var("GOOSE_INPUT") {
let prompt = match std::env::var("GOOSE_INPUT") {
Ok(val) => match val.as_str() {
"cliclack" => Box::new(CliclackPrompt::new()) as Box<dyn Prompt>,
"rustyline" => Box::new(RustylinePrompt::new()) as Box<dyn Prompt>,
Expand All @@ -57,17 +56,19 @@ pub fn build_session<'a>(
Err(_) => Box::new(RustylinePrompt::new()),
};

prompt.render(Box::new(Message::assistant().with_text(format!(
r#"{}...
Provider: {}
Model: {}
Session file: {}"#,
get_random_goose_action(),
loaded_profile.provider,
loaded_profile.model,
session_file.display()
))));

println!(
"{} {} {} {} {}",
style("starting session |").dim(),
style("provider:").dim(),
style(loaded_profile.provider).cyan().dim(),
style("model:").dim(),
style(loaded_profile.model).cyan().dim(),
);
println!(
" {} {}",
style("logging to").dim(),
style(session_file.display()).dim().cyan(),
);
Box::new(Session::new(agent, prompt, session_file))
}

Expand Down
19 changes: 3 additions & 16 deletions crates/goose-cli/src/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,9 @@ pub trait Prompt {
fn hide_busy(&self);
fn close(&self);
fn goose_ready(&self) {
self.draw_goose();
}

fn draw_goose(&self) {
println!(
r#" __ - - - -
( 0)> < honk! >
|| - - - -
||
__||_
<=/ \=>
\_____/
| |
^ ^
"#
);
println!("\n");
println!("Goose is running! Enter your instructions, or try asking what goose can do.");
println!("\n");
}
}

Expand Down
52 changes: 0 additions & 52 deletions crates/goose-cli/src/prompt/thinking.rs
Original file line number Diff line number Diff line change
@@ -1,50 +1,5 @@
use rand::seq::SliceRandom;

/// List of goose-specific actions for noting goose readiness.
pub const GOOSE_ACTIONS: &[&str] = &[
"Spreading wings",
"Honking thoughtfully",
"Waddling to conclusions",
"Flapping wings excitedly",
"Preening code feathers",
"Gathering digital breadcrumbs",
"Paddling through data",
"Migrating thoughts",
"Nesting ideas",
"Squawking calculations",
"Ruffling algorithmic feathers",
"Pecking at problems",
"Stretching webbed feet",
"Foraging for solutions",
"Grooming syntax",
"Building digital nest",
"Patrolling the codebase",
"Gosling about",
"Strutting with purpose",
"Diving for answers",
"Herding bytes",
"Molting old code",
"Swimming through streams",
"Goose-stepping through logic",
"Synchronizing flock algorithms",
"Navigating code marshes",
"Incubating brilliant ideas",
"Arranging feathers recursively",
"Gliding through branches",
"Migrating to better solutions",
"Nesting functions carefully",
"Hatching clever solutions",
"Preening parse trees",
"Flying through functions",
"Gathering syntax seeds",
"Webbing connections",
"Flocking to optimizations",
"Paddling through protocols",
"Honking success signals",
"Waddling through workflows",
"Nesting in neural networks",
];

/// Extended list of playful thinking messages including both goose and general AI actions
pub const THINKING_MESSAGES: &[&str] = &[
"Thinking",
Expand Down Expand Up @@ -268,10 +223,3 @@ pub fn get_random_thinking_message() -> &'static str {
.choose(&mut rand::thread_rng())
.unwrap_or(&THINKING_MESSAGES[0])
}

/// Returns a random goose-specific action
pub fn get_random_goose_action() -> &'static str {
GOOSE_ACTIONS
.choose(&mut rand::thread_rng())
.unwrap_or(&GOOSE_ACTIONS[0])
}
7 changes: 1 addition & 6 deletions crates/goose-cli/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl<'a> Session<'a> {

pub async fn start(&mut self) -> Result<(), Box<dyn std::error::Error>> {
self.setup_session();
self.prompt.goose_ready();

loop {
let input = self.prompt.get_input().unwrap();
Expand Down Expand Up @@ -202,14 +203,8 @@ impl<'a> Session<'a> {
fn setup_session(&mut self) {
let system = Box::new(DeveloperSystem::new());
self.agent.add_system(system);
self.prompt
.render(raw_message("Connected developer system."));
let goosehints_system = Box::new(GooseHintsSystem::new());
self.agent.add_system(goosehints_system);
self.prompt
.render(raw_message("Connected .goosehints system."));

self.prompt.goose_ready();
}

fn close_session(&mut self) {
Expand Down
5 changes: 2 additions & 3 deletions crates/goose-server/src/routes/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ fn convert_messages(incoming: Vec<IncomingMessage>) -> Vec<Message> {
struct ProtocolFormatter;

impl ProtocolFormatter {

fn format_text(text: &str) -> String {
let encoded_text = serde_json::to_string(text).unwrap_or_else(|_| String::new());
format!("0:{}\n", encoded_text)
Expand Down Expand Up @@ -236,8 +235,8 @@ async fn stream_message(
MessageContent::Text(text) => {
for line in text.text.lines() {
let modified_line = format!("{}\n", line);
tx.send(ProtocolFormatter::format_text(&modified_line)).await?;

tx.send(ProtocolFormatter::format_text(&modified_line))
.await?;
}
}
MessageContent::Image(_) => {
Expand Down
10 changes: 7 additions & 3 deletions crates/goose/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ impl MemoryManager {
if let Some(first_line) = lines.next() {
if first_line.starts_with('#') {
let tags = first_line[1..]
.trim()
.split_whitespace()
.map(String::from)
.collect::<Vec<_>>();
Expand Down Expand Up @@ -236,8 +235,7 @@ pub fn execute_tool_call(tool_call: ToolCall) -> Result<String, io::Error> {
.map(|v| v.as_str().unwrap())
.collect();
let is_global = tool_call.arguments["is_global"].as_bool().unwrap();
let _result =
MemoryManager::new()?.remember("context", category, data, &tags, is_global)?;
MemoryManager::new()?.remember("context", category, data, &tags, is_global)?;
Ok(format!("Stored memory in category: {}", category))
}
"retrieve_memories" => {
Expand Down Expand Up @@ -274,6 +272,12 @@ pub struct MemorySystem {
instructions: String,
}

impl Default for MemorySystem {
fn default() -> Self {
Self::new()
}
}

impl MemorySystem {
pub fn new() -> Self {
let memory_manager = MemoryManager::new().expect("Failed to create MemoryManager");
Expand Down
2 changes: 1 addition & 1 deletion crates/goose/src/providers/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl TokenCache {
let hash = format!("{:x}", hasher.finalize());

fs::create_dir_all(get_base_path()).unwrap();
let cache_path = PathBuf::from(get_base_path()).join(format!("{}.json", hash));
let cache_path = get_base_path().join(format!("{}.json", hash));

Self { cache_path }
}
Expand Down

0 comments on commit 4fa9c2a

Please sign in to comment.