Contract at server dev 5d7b79c: a new agent chat's Subagents setting
CI / check (push) Canceled after 0s

The server answers /models?kind=agent&device= (e888bc2, models_agent.json)
with `agent_subagents {offered, device_runs}`. A new agent chat reads it
for the device chosen (again when another is chosen) and shows the
Subagents setting exactly when it is offered; when the device's CLI does
not run subagents (`device_runs` false) the server's sentence says so
beside it. An older server says nothing and the setting stays hidden.

Strings at the same ref: every translatable string is translated in all
eight languages -- "Open slots" from the server's catalogue, the row's
"% context" from strings_own.json (the server words it as a sentence),
and `progress_line` (text · elapsed, symbols only) is no longer counted
as translatable.

ContractTest (models_agent.json), ChatStateTest, shot 07-tune-new-agent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Opus 5.5 committed 2026-11-10 10:37:43 +00:00
1 parent 73e753ab57
commit a4116b11a8
22 files changed
+208 -20

No files matched your search

@@ -149,6 +149,10 @@ class ApiClient(val base: String, private val token: String, val http: OkHttpCli
/** The models with the instance's subagent cap; with [chatId], whether each is offered subagents on that chat. */
suspend fun modelList(chatId: String? = null): ModelList = get(if (chatId != null) "/models?chat=$chatId" else "/models")
/** The models for a new agent chat on [deviceId], with whether it may have subagents (`agent_subagents`). */
suspend fun agentModelList(deviceId: String?): ModelList =
get("/models?kind=agent" + deviceId?.let { "&device=" + java.net.URLEncoder.encode(it, "UTF-8") }.orEmpty())
suspend fun folders(): List<Folder> = get<FolderList>("/folders").folders
suspend fun devices(): List<LinkedDevice> = get<DeviceList>("/devices").devices
@@ -154,8 +154,18 @@ data class ModelList(
val models: List<ModelInfo> = emptyList(),
/** The instance's cap on a chat's subagents (server 2.0.0-beta.7); null from an older one. */
@SerialName("subagents_cap") val subagentsCap: Int? = null,
/** With `kind=agent` (spec 3.4.0 §14): whether a new agent chat may have subagents. */
@SerialName("agent_subagents") val agentSubagents: AgentSubagents? = null,
)
/**
* A new agent chat's Subagents fact (`/models?kind=agent&device=`): [offered] where the instance
* and the person allow them; [deviceRuns] whether the chosen device runs them (it lists `agents`
* and `tree`), null while it is not linked or none was named.
*/
@Serializable
data class AgentSubagents(val offered: Boolean = false, @SerialName("device_runs") val deviceRuns: Boolean? = null)
/**
* Whether subagents are offered (harness spec 3.3.0, `subagents.md` §4): [offered] when
* subagents are on and at least one model could serve; [namedOnly] when only a model the person
@@ -11,6 +11,7 @@ import eu.llembas.android.api.Activity
import eu.llembas.android.api.ActivityAgent
import eu.llembas.android.api.ActivityFrame
import eu.llembas.android.api.ActivitySummary
import eu.llembas.android.api.AgentSubagents
import eu.llembas.android.api.AgentTarget
import eu.llembas.android.api.AgentsSetting
import eu.llembas.android.api.ApiClient
@@ -76,6 +77,8 @@ data class ChatState(
val draft: Draft = Draft(),
/** The subagent tree (spec 3.4.0) from this chat's last `tree` frame; null until one came. */
val tree: SubagentTree? = null,
/** For a new agent chat: whether it may have subagents, and whether its device runs them. */
val agentSubagents: AgentSubagents? = null,
)
/**
@@ -106,7 +109,14 @@ val ChatState.level: String?
* Whether the Subagents setting is shown (plan rule 4): the chat's own word for a chat that
* exists (`subagents.offered`, else the activity's), the model's for a new one.
*/
fun ChatState.offersTeam(agent: Boolean): Boolean = if (chat != null) chat.subagents?.offered ?: teamOffered else !agent && modelInfo?.mayHaveTeam == true
fun ChatState.offersTeam(agent: Boolean): Boolean = when {
chat != null -> chat.subagents?.offered ?: teamOffered
// A new agent chat: the server's word for agent chats (spec 3.4.0 §14), never a guess.
agent -> agentSubagents?.offered == true
else -> modelInfo?.mayHaveTeam == true
}
/**
* Whether subagents need a model the person names in the chat: the chat's own serves one
@@ -183,7 +193,20 @@ class ChatViewModel(app: Application) :
override fun clearUnsent() = _state.update { it.copy(unsent = null) }
override fun updateDraft(change: (Draft) -> Draft) = _state.update { it.copy(draft = change(it.draft)) }
override fun updateDraft(change: (Draft) -> Draft) {
val before = _state.value.device?.id
_state.update { it.copy(draft = change(it.draft)) }
if (agentChat && _state.value.chat == null && _state.value.device?.id != before) readAgentFacts()
}
/** A new agent chat's Subagents fact, for the device chosen now; an older server says nothing. */
private fun readAgentFacts() {
val device = _state.value.device?.id
viewModelScope.launch {
val facts = runCatching { api().agentModelList(device) }.getOrNull()?.agentSubagents
_state.update { if (it.device?.id == device) it.copy(agentSubagents = facts) else it }
}
}
override fun rename(title: String) = change("title", title.trim())
@@ -201,6 +224,7 @@ class ChatViewModel(app: Application) :
val devices = if (agent) client.devices() else emptyList()
val base = if (agent) getApplication<Application>().lembas.instances.current()?.base.orEmpty() else ""
_state.update { it.copy(models = models, devices = devices, instanceBase = base, loading = false) }
if (agent) readAgentFacts()
return@launch
}
val detail = client.chat(chatId)
@@ -433,6 +433,15 @@ fun TuneContent(state: ChatState, actions: ChatActions, agent: Boolean, modifier
color = palette.inkMuted,
modifier = Modifier.padding(horizontal = 24.dp),
)
if (chat == null && agent && state.agentSubagents?.deviceRuns == false) {
// The chosen computer's CLI is older than subagents: the setting would go nowhere.
Text(
stringResource(R.string.subagents_device_cannot),
style = MaterialTheme.typography.bodySmall,
color = palette.warning,
modifier = Modifier.padding(horizontal = 24.dp, vertical = 4.dp),
)
}
if (state.subagentsNamedOnly) {
// The chat's model serves one request at a time: no default to fall back on.
Text(