Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix(host): run memory and naming helpers on the bot's model

leepokaifcb2dc0cc196
diff --git a/host/src/agent/bot.rs b/host/src/agent/bot.rs
index 66bb5afc..53392e82 100644
--- a/host/src/agent/bot.rs
+++ b/host/src/agent/bot.rs
@@ -974,23 +974,7 @@ impl Actor {
let res = conn.acp.request("session/new", params).await?;
let sid = res["sessionId"].as_str().ok_or_else(|| anyhow!("agent returned no sessionId"))?.to_owned();
conn.loaded.insert(sid.clone());
- if let Some(model) = self.cfg.model.clone().filter(|m| !m.is_empty()) {
- let config_id = crate::agent::auth::model_config(&res).and_then(|c| c["id"].as_str());
- let r = if let Some(config_id) = config_id {
- conn.acp
- .request(
- "session/set_config_option",
- json!({"sessionId": sid, "configId": config_id, "value": model}),
- )
- .await
- } else {
- conn.acp.request("session/set_model", json!({"sessionId": sid, "modelId": model})).await
- };
- if let Err(e) = r {
- tracing::warn!(model, error = format!("{e:#}"), "couldn't set model");
- bail!("Couldn't select model {model}: {e:#}");
- }
- }
+ select_model(&conn.acp, &res, &sid, &self.cfg).await?;
self.set_session(slot, Some(&sid));
self.session_fresh = true;
self.turn_session = Some(sid.clone());
@@ -1449,6 +1433,23 @@ pub(crate) async fn launch_commands(cfg: &BotConfig, progress: impl Fn(&str)) ->
})
}
+/// Switches a new session (`session/new` answered `res`) to the bot's chosen model.
+pub(crate) async fn select_model(acp: &Acp, res: &Value, sid: &str, cfg: &BotConfig) -> Result<()> {
+ let Some(model) = cfg.model.as_deref().filter(|m| !m.is_empty()) else { return Ok(()) };
+ let r = match crate::agent::auth::model_config(res).and_then(|c| c["id"].as_str()) {
+ Some(config_id) => {
+ acp.request("session/set_config_option", json!({"sessionId": sid, "configId": config_id, "value": model}))
+ .await
+ }
+ None => acp.request("session/set_model", json!({"sessionId": sid, "modelId": model})).await,
+ };
+ if let Err(e) = r {
+ tracing::warn!(model, error = format!("{e:#}"), "couldn't set model");
+ bail!("Couldn't select model {model}: {e:#}");
+ }
+ Ok(())
+}
+
/// Spawns an ACP agent and completes the `initialize` handshake.
pub(crate) async fn start_agent(command: &str, cwd: &str, env: &[(String, String)], budget: Duration) -> Result<Conn> {
let (acp, rx) = Acp::spawn(command, cwd, env)?;
diff --git a/host/src/chat/memory.rs b/host/src/chat/memory.rs
index 93d4b197..e3cd0069 100644
--- a/host/src/chat/memory.rs
+++ b/host/src/chat/memory.rs
@@ -805,10 +805,13 @@ pub(crate) async fn one_shot(hub: &Arc<Hub>, cfg: &BotConfig, system: &str, user
} else {
format!("{system}\n\n---\n\n{user}")
};
- let sid = acp.request("session/new", params).await?["sessionId"]
- .as_str()
- .ok_or_else(|| anyhow!("agent returned no sessionId"))?
- .to_owned();
+ let res = acp.request("session/new", params).await?;
+ let sid = res["sessionId"].as_str().ok_or_else(|| anyhow!("agent returned no sessionId"))?.to_owned();
+ // Same model as the bot: the harness default may be another (local) model that
+ // would load next to the bot's, or a cloud one the user kept these chats away from.
+ if !conn.claude {
+ crate::agent::bot::select_model(&acp, &res, &sid, cfg).await?;
+ }
let prompt = acp.request("session/prompt", json!({"sessionId": sid, "prompt": [{"type": "text", "text": text}]}));
tokio::pin!(prompt);
let deadline = tokio::time::sleep(KEEPER_TIMEOUT);