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
8 changes: 7 additions & 1 deletion docs/architecture/model-request-cache-reuse.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,17 @@ persistence first and then captures the context snapshot.
The child session is initialized from a captured parent context snapshot:

- same parent agent type
- same workspace and model config
- same workspace, with parent model configuration inherited by default
- inherited message context
- cloned session-level prompt cache
- seeded skill/agent listing baselines derived from the parent session

`ai.btw.model_selection` may instead choose a model or pool for new side questions.
The host resolves that default before the first turn, below an explicit child
selection, and existing children retain their own choice. A changed model starts
with its own default reasoning. The context snapshot remains inherited; provider
cache reuse still depends on the selected model's normal cache identity checks.

That gives the side thread an already-built conversational prefix.

In other words, `/btw` now reuses both:
Expand Down
6 changes: 3 additions & 3 deletions docs/interactive-capabilities/capabilities.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"title": "OpenBitFun Playbook",
"origin": "https://playbook.openbitfun.com",
"source": "src/shared/interactive-capabilities/catalog.json",
"digest": "3f6c6936d3a543526f6a768b31c8058041ab3704f44be401086eb9174440d5cc",
"digest": "1e9b09293cfab7a47682d9decab4e0626137d6e79cd2405688d7f16e05a8e6b5",
"ownerDigest": "6f0746578f3c56479f7c289bb05395dfe6917042f4d419de8c9a2f719d31f815",
"searchAcceptance": [
{
Expand Down Expand Up @@ -31932,8 +31932,8 @@
"control": {
"kind": "open",
"reasonCode": "unstructuredInteraction",
"reasonZh": "“开启或关闭侧问(/btw)面板关闭前的丢弃确认提示”保存在当前界面的交互偏好中,智能体会为你打开“输入与交互 → 侧问关闭确认”开关位置。",
"reasonEn": "“Enable or disable the confirmation prompt before closing a /btw side conversation” is stored as a client UI interaction preference; the Agent opens Input & Interaction → Side-Question Close Confirmation for you."
"reasonZh": "“开启或关闭侧问(/btw)面板关闭前的丢弃确认提示”保存在当前界面的交互偏好中,智能体会为你打开“会话与记忆 → 侧问”中的确认开关。",
"reasonEn": "“Enable or disable the confirmation prompt before closing a /btw side conversation” is stored as a client UI interaction preference; the Agent opens Session & Memory → Side questions for you."
}
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 1,
"generatedFrom": "src/shared/interactive-capabilities/catalog.json",
"catalogDigest": "3f6c6936d3a543526f6a768b31c8058041ab3704f44be401086eb9174440d5cc",
"catalogDigest": "1e9b09293cfab7a47682d9decab4e0626137d6e79cd2405688d7f16e05a8e6b5",
"count": 231,
"reasonCounts": {
"externalAuth": 4,
Expand Down Expand Up @@ -2762,15 +2762,15 @@
"titleZh": "开启或关闭侧问(/btw)面板关闭前的丢弃确认提示",
"titleEn": "Enable or disable the confirmation prompt before closing a /btw side conversation",
"reasonCode": "unstructuredInteraction",
"reasonZh": "“开启或关闭侧问(/btw)面板关闭前的丢弃确认提示”保存在当前界面的交互偏好中,智能体会为你打开“输入与交互 → 侧问关闭确认”开关位置。",
"reasonEn": "“Enable or disable the confirmation prompt before closing a /btw side conversation” is stored as a client UI interaction preference; the Agent opens Input & Interaction → Side-Question Close Confirmation for you.",
"reasonZh": "“开启或关闭侧问(/btw)面板关闭前的丢弃确认提示”保存在当前界面的交互偏好中,智能体会为你打开“会话与记忆 → 侧问”中的确认开关。",
"reasonEn": "“Enable or disable the confirmation prompt before closing a /btw side conversation” is stored as a client UI interaction preference; the Agent opens Session & Memory → Side questions for you.",
"presentationTarget": {
"kind": "settings",
"pageId": "application.voice",
"sectionId": "btw-close-confirmation"
},
"evidence": [
"source:src/web-ui/src/app/scenes/settings/pages/application/BtwCloseConfirmationSettingsSection.tsx#BtwCloseConfirmationSettingsSection"
"source:src/web-ui/src/app/scenes/settings/pages/ai/BtwSettingsSection.tsx#BtwSettingsSection"
]
},
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"schemaVersion": 2,
"generatedFrom": "src/shared/interactive-capabilities/catalog.json",
"catalogDigest": "3f6c6936d3a543526f6a768b31c8058041ab3704f44be401086eb9174440d5cc",
"catalogDigest": "1e9b09293cfab7a47682d9decab4e0626137d6e79cd2405688d7f16e05a8e6b5",
"commandCount": 701,
"coverage": {
"commandCount": 701,
Expand Down
5 changes: 3 additions & 2 deletions scripts/generate-interactive-capabilities.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,10 @@ export function projectSettingsCatalogDestination(capabilityId, destination, ite
if (destination.kind !== 'settings') return destination;
const capability = SETTINGS_MIGRATIONS.capabilities[capabilityId];
const input = capability?.items?.[itemId] ?? capability?.destination ?? destination;
const migratedSection = SETTINGS_MIGRATIONS.sections?.[input.pageId]?.[input.sectionId];
const migratedView = SETTINGS_MIGRATIONS.views[input.pageId]?.[input.viewId];
const migrated = migratedView ?? SETTINGS_MIGRATIONS.pages[input.pageId];
const sectionId = input.sectionId ?? migrated?.sectionId;
const migrated = migratedSection ?? migratedView ?? SETTINGS_MIGRATIONS.pages[input.pageId];
const sectionId = migratedSection?.sectionId ?? input.sectionId ?? migrated?.sectionId;
return {
kind: 'settings',
pageId: migrated?.pageId ?? input.pageId,
Expand Down
9 changes: 9 additions & 0 deletions scripts/interactive-capabilities.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ test('historical settings wire targets resolve through the current presentation
assert.deepEqual(projectSettingsCatalogDestination(automation.id, hooks.destination, hooks.id), {
kind: 'settings', pageId: 'tools.automation', sectionId: 'hooks',
});
const input = runtimeCatalog.capabilities.find(({ id }) => id === 'setting.application.input');
const btwClose = input.items.find(({ id }) => id === 'btw-close-confirmation');
assert.deepEqual(btwClose.destination, { kind: 'settings', pageId: 'application.voice', sectionId: 'btw-close-confirmation' });
assert.deepEqual(projectSettingsCatalogDestination(input.id, btwClose.destination, btwClose.id), {
kind: 'settings', pageId: 'ai.session-memory', sectionId: 'btw',
});
assert.deepEqual(projectSettingsCatalogDestination('legacy', { kind: 'settings', pageId: 'application.input', sectionId: 'btw-close-confirmation' }), {
kind: 'settings', pageId: 'ai.session-memory', sectionId: 'btw',
});
const computerUse = runtimeCatalog.capabilities.find(({ id }) => id === 'feature.computer-use');
assert.deepEqual(projectSettingsCatalogDestination(computerUse.id, computerUse.destination), {
kind: 'settings', pageId: 'tools.desktop-control',
Expand Down
6 changes: 5 additions & 1 deletion src/apps/cli/src/peer_host/commands/btw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ pub(crate) async fn btw_ask_stream(state: &PeerHostState, args: &Value) -> Resul
return Err("Peer event stream lost continuity while starting the side question".into());
}

let model_target = coordinator
.get_session_manager()
.get_session(&child_session_id)
.map(openbitfun_core::agentic::session::session_model_target);
let runtime = side_questions().clone();
let request_id = request.request_id;
runtime
Expand All @@ -166,7 +170,7 @@ pub(crate) async fn btw_ask_stream(state: &PeerHostState, args: &Value) -> Resul
tokio::time::sleep(BTW_TURN_POLL_INTERVAL).await;
}
});
Ok(json!({ "ok": true }))
Ok(json!({ "ok": true, "modelTarget": model_target }))
}

pub(crate) async fn btw_cancel(args: &Value) -> Result<Value, String> {
Expand Down
15 changes: 15 additions & 0 deletions src/apps/desktop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,21 @@ before the first selected-text question. Peer hosts must advertise
`btw_model_pool_selection_v1` for these typed initial choices; older hosts retain
the inherited path without silently replacing a pool with its current member.

Settings → AI → Session & Memory → Side questions controls the default for new `/btw`
sessions (`ai.btw.model_selection`). The default is `{ "kind": "inherit" }`, which
retains the parent's model, reasoning and pool binding. A fixed model uses
`{ "kind": "model", "model_ref": "<configured model id>" }`; a pool uses
`{ "kind": "pool", "pool_id": "<pool id>" }`. An explicit choice inside a side
question takes precedence and affects only that conversation. Changing the global
BTW default does not change existing conversations. A different model starts with
its own default reasoning, while inherited sessions retain the parent's reasoning.
Unavailable saved choices remain stored and block new side questions until an
explicit choice repairs or overrides them. Peers expose this setting only when the
execution host advertises `btw_model_defaults_v1`; settings and model IDs belong to
that host. SSH/Docker workspace side questions keep their parent's execution root.
The host returns the committed model target with admission so the selector shows
the actual choice without depending on a second request.

Peer Device Mode routes pool operations to capable Desktop/CLI hosts. Standalone
browser clients, detached dispatch, and ACP/external-agent model selection
do not expose pool selection in this version. Mobile/IM clients can continue a
Expand Down
36 changes: 33 additions & 3 deletions src/apps/desktop/src/api/btw_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,17 @@ pub struct BtwAskStreamRequest {
pub user_message_metadata: Option<serde_json::Value>,
#[serde(default)]
pub initial_model_selection: Option<openbitfun_runtime_ports::AgentSessionModelSelection>,
/// Requires btw_model_pool_selection_v1; omitted means inherit the parent binding.
/// Requires btw_model_pool_selection_v1; omitted uses the host BTW default.
#[serde(default)]
pub initial_model_target: Option<openbitfun_runtime_ports::AgentSessionModelTargetSelection>,
}

#[derive(Debug, Clone, Serialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct BtwAskStreamResponse {
pub ok: bool,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub model_target: Option<openbitfun_core_types::model_pool::SessionModelTarget>,
}

#[derive(Debug, Clone, Deserialize)]
Expand Down Expand Up @@ -132,6 +134,10 @@ pub async fn btw_ask_stream(
.await
.map_err(|e| e.to_string())?;

let model_target = coordinator
.get_session_manager()
.get_session(&child_session_id)
.map(openbitfun_core::agentic::session::session_model_target);
state
.side_question_runtime
.register_btw_turn(
Expand Down Expand Up @@ -161,13 +167,37 @@ pub async fn btw_ask_stream(
}
});

Ok(BtwAskStreamResponse { ok: true })
Ok(BtwAskStreamResponse {
ok: true,
model_target,
})
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn btw_admission_response_reads_legacy_and_keeps_new_target_optional_for_old_readers() {
let legacy: BtwAskStreamResponse =
serde_json::from_value(serde_json::json!({"ok":true})).unwrap();
assert!(legacy.model_target.is_none());
assert_eq!(
serde_json::to_value(legacy).unwrap(),
serde_json::json!({"ok":true})
);
let current: BtwAskStreamResponse = serde_json::from_value(serde_json::json!({
"ok":true, "modelTarget": { "sessionId":"child", "selection":{"kind":"model","model_ref":"side-model"}, "reasoningPreset":null },
})).unwrap();
#[derive(Deserialize)]
struct LegacyResponse {
ok: bool,
}
let old_reader: LegacyResponse =
serde_json::from_value(serde_json::to_value(current).unwrap()).unwrap();
assert!(old_reader.ok);
}

#[test]
fn btw_request_reads_legacy_payloads_and_round_trips_optional_metadata() {
let legacy = serde_json::json!({
Expand Down
56 changes: 56 additions & 0 deletions src/crates/assembly/core/src/agentic/coordination/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ fn apply_primary_agent_model_default(
#[cfg(test)]
tokio::task_local! {
static TEST_AGENT_MODEL_DEFAULTS: AgentModelSelections;
static TEST_BTW_AI_CONFIG: crate::service::config::types::AIConfig;
}

async fn normalize_model_selection(model_id: &str) -> OpenBitFunResult<String> {
Expand Down Expand Up @@ -12133,6 +12134,50 @@ Update the persona files and delete BOOTSTRAP.md as soon as bootstrap is complet
Ok(child_session)
}

async fn resolve_btw_initial_model_target(
&self,
child_session_id: &str,
model_id: Option<&str>,
legacy_selection: Option<&openbitfun_runtime_ports::AgentSessionModelSelection>,
explicit_target: Option<openbitfun_runtime_ports::AgentSessionModelTargetSelection>,
) -> OpenBitFunResult<Option<openbitfun_runtime_ports::AgentSessionModelTargetSelection>> {
if explicit_target.is_some()
|| legacy_selection.is_some()
|| model_id.is_some_and(|id| !id.trim().is_empty())
|| self
.session_manager
.get_session(child_session_id)
.is_some_and(|session| !session.dialog_turn_ids.is_empty())
{
return Ok(explicit_target);
}
#[cfg(test)]
if let Ok(ai) = TEST_BTW_AI_CONFIG.try_with(Clone::clone) {
return Self::btw_default_model_target(&ai);
}
let service = get_global_config_service().await?;
let ai = service.get_config(Some("ai")).await?;
Self::btw_default_model_target(&ai)
}

fn btw_default_model_target(
ai: &crate::service::config::types::AIConfig,
) -> OpenBitFunResult<Option<openbitfun_runtime_ports::AgentSessionModelTargetSelection>> {
let selection = openbitfun_config_contracts::btw::validate_model_selection(ai)
.map_err(OpenBitFunError::validation)?;
let selection = match selection {
AgentModelSelection::Inherit => return Ok(None),
AgentModelSelection::Model { model_ref } => ModelSelection::Model { model_ref },
AgentModelSelection::Pool { pool_id } => ModelSelection::Pool { pool_id },
};
Ok(Some(
openbitfun_runtime_ports::AgentSessionModelTargetSelection {
selection,
reasoning_preset: None,
},
))
}

pub async fn start_btw_turn(
&self,
request_id: &str,
Expand Down Expand Up @@ -12170,6 +12215,17 @@ Update the persona files and delete BOOTSTRAP.md as soon as bootstrap is complet
));
}

// Resolve the host's future-session default only for an unsubmitted
// child. Explicit controller choices and existing children keep ownership.
let initial_model_target = self
.resolve_btw_initial_model_target(
child_session_id,
model_id,
initial_model_selection.as_ref(),
initial_model_target,
)
.await?;

let child_session = self
.ensure_btw_session(
parent_session_id,
Expand Down
Loading
Loading