Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions microagents-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "microagents-cli"
version = "0.4.2"
version = "0.4.3"
edition = "2024"
license = "MIT"
readme = "README.md"
Expand All @@ -12,9 +12,9 @@ keywords = ["ai", "agents", "cli", "tui", "rust"]
async-trait = "0.1.89"
futures-core = "0.3.32"
futures-util = "0.3.32"
microagents-core = { path = "../microagents-core", version = "0.4.2" }
microagents-events = { path = "../microagents-events", version = "0.2.0" }
microagents-storage = { path = "../microagents-storage", version = "0.1.1" }
microagents-core = { path = "../microagents-core", version = "0.4.3" }
microagents-events = { path = "../microagents-events", version = "0.3.0" }
microagents-storage = { path = "../microagents-storage", version = "0.1.2" }
qdrant-edge = "0.7.1"
ratatui = {version = "0.30.0", features = ["serde", "palette"]}
serde_json = "1.0.150"
Expand All @@ -31,6 +31,7 @@ tempfile = "3.27.0"
fastembed = "5"
dirs = "6.0.0"
indicatif = "0.18.4"
chrono = { version = "0.4.45", features = ["serde"] }

[target.'cfg(windows)'.dependencies]
liteparse = { version = "2.0.2", default-features = false }
Expand Down
69 changes: 67 additions & 2 deletions microagents-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ struct Args {
#[arg(long = "session-id", value_name = "ID")]
session_id: Option<String>,

/// Fork a previous session by id, creating a new session with cloned history.
#[arg(long = "fork", value_name = "ID")]
fork: Option<String>,
Comment thread
AstraBert marked this conversation as resolved.

/// Prompt to run in headless mode.
#[arg(long, short, default_value = None)]
prompt: Option<String>,
Expand Down Expand Up @@ -117,14 +121,75 @@ async fn build_agent(
Ok(base_builder.build()?)
}

async fn fork_session(parent_id: &str, storage_opt: Option<String>) -> Result<String, AgentError> {
let storage = build_storage(storage_opt).await?;
let parent_events = storage.get_session(parent_id).await.map_err(|e| {
AgentError::SessionLoadError(format!("Failed to load parent session: {}", e))
})?;

if parent_events.is_empty() {
return Err(AgentError::SessionLoadError(format!(
"Parent session {} has no events or does not exist",
parent_id
)));
}

let new_sid = uuid::Uuid::new_v4().to_string();

for event in parent_events {
if matches!(&event, microagents_events::AgentEventAny::SessionFork(_)) {
continue;
}
let cloned_event = event.with_session_id(new_sid.clone());
match cloned_event {
microagents_events::AgentEventAny::SessionInit(init_event) => {
storage.create_session(init_event).await.map_err(|e| {
AgentError::RunError(format!("Failed to write forked session init: {}", e))
})?;
}
other => {
storage.update_session(other).await.map_err(|e| {
AgentError::RunError(format!("Failed to write forked event: {}", e))
})?;
}
}
Comment thread
AstraBert marked this conversation as resolved.
}

let fork_event = microagents_events::SessionForkEvent {
session_id: new_sid.clone(),
parent_session_id: parent_id.to_string(),
timestamp: chrono::Utc::now(),
};
storage
.update_session(microagents_events::AgentEventAny::SessionFork(fork_event))
.await
.map_err(|e| AgentError::RunError(format!("Failed to write session fork event: {}", e)))?;

Ok(new_sid)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let args = Args::parse();

let resolved_session_id = if let Some(parent_id) = &args.fork {
if args.session_id.is_some() {
return Err(
"--fork-id and --session-id are mutually exclusive: only provide one of the two."
.into(),
);
}
let new_sid = fork_session(parent_id, args.storage.clone()).await?;
Some(new_sid)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
} else {
args.session_id.clone()
};

if let Some(p) = args.prompt {
initialize_environment(args.verbose).await?;
let agent = build_agent(args.provider, args.model, args.storage, args.skill).await?;
let mut stream = agent
.run(p, args.session_id)
.run(p, resolved_session_id)
.await
.map_err(|e| e.to_string())?;
while let Some(ev) = stream.next().await {
Expand All @@ -151,7 +216,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
// and that things did not just randomly freeze
initialize_environment(true).await?;
println!("Launching TUI...");
let initial_session = args.session_id.clone();
let initial_session = resolved_session_id.clone();
let load_history_storage = args.storage.clone();
tui::run_with_session(
initial_session,
Expand Down
6 changes: 3 additions & 3 deletions microagents-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "microagents-core"
version = "0.4.2"
version = "0.4.3"
edition = "2024"
license = "MIT"
readme = "README.md"
Expand All @@ -23,8 +23,8 @@ serde_json = "1.0.149"
thiserror = "2.0.18"
dashmap = "6"
ultrafast-models-sdk = { version = "0.1.6", features = ["openai", "anthropic", "groq", "mistral", "cohere", "azure", "bedrock", "standalone", "ollama"] }
microagents-events = { path = "../microagents-events", version = "0.2.0" }
microagents-storage = { path = "../microagents-storage", version = "0.1.1" }
microagents-events = { path = "../microagents-events", version = "0.3.0" }
microagents-storage = { path = "../microagents-storage", version = "0.1.2" }
async-stream = "0.3.6"
uuid = { version = "1.23.1", features = ["v4"] }
tokio = { version = "1.52.3", features = ["full"] }
Expand Down
2 changes: 1 addition & 1 deletion microagents-events/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "microagents-events"
version = "0.2.0"
version = "0.3.0"
edition = "2024"
license = "MIT"
readme = "README.md"
Expand Down
Loading
Loading