Add basic cron scheduler to goose-server (#2621)
This commit is contained in:
@@ -205,18 +205,17 @@ impl Agent {
|
||||
usage: &crate::providers::base::ProviderUsage,
|
||||
messages_length: usize,
|
||||
) -> Result<()> {
|
||||
let session_file = session::get_path(session_config.id);
|
||||
let mut metadata = session::read_metadata(&session_file)?;
|
||||
let session_file_path = session::storage::get_path(session_config.id.clone());
|
||||
let mut metadata = session::storage::read_metadata(&session_file_path)?;
|
||||
|
||||
metadata.schedule_id = session_config.schedule_id.clone();
|
||||
|
||||
metadata.working_dir = session_config.working_dir.clone();
|
||||
metadata.total_tokens = usage.usage.total_tokens;
|
||||
metadata.input_tokens = usage.usage.input_tokens;
|
||||
metadata.output_tokens = usage.usage.output_tokens;
|
||||
// The message count is the number of messages in the session + 1 for the response
|
||||
// The message count does not include the tool response till next iteration
|
||||
|
||||
metadata.message_count = messages_length + 1;
|
||||
|
||||
// Keep running sum of tokens to track cost over the entire session
|
||||
let accumulate = |a: Option<i32>, b: Option<i32>| -> Option<i32> {
|
||||
match (a, b) {
|
||||
(Some(x), Some(y)) => Some(x + y),
|
||||
@@ -231,7 +230,8 @@ impl Agent {
|
||||
metadata.accumulated_output_tokens,
|
||||
usage.usage.output_tokens,
|
||||
);
|
||||
session::update_metadata(&session_file, &metadata).await?;
|
||||
|
||||
session::storage::update_metadata(&session_file_path, &metadata).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -22,4 +22,6 @@ pub struct SessionConfig {
|
||||
pub id: session::Identifier,
|
||||
/// Working directory for the session
|
||||
pub working_dir: PathBuf,
|
||||
/// ID of the schedule that triggered this session, if any
|
||||
pub schedule_id: Option<String>, // NEW
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user