Subagents offered, named-only and capped by the server's word
CI / check (push) Canceled after 0s

- ModelInfo.subagents, ModelList.subagents_cap, Chat.subagents {offered, named_only, cap},
  Activity.subagents_offered, ContextUse.auto_compact/until_compact/compactable: all
  optional, so an older server still parses and the app falls back to its old guess.
- The Subagents setting: shown by offered, the one-request note when named_only, sliders
  from 1 to the cap (ticks up to 8), none at a cap of 1.
- Compact disabled when the server says there is nothing to compact yet.
- The context's number columns widen with the type (they touched at 1.5x).
- SubagentsTest; shots 07-tune-one-at-a-time and a tall 411x2000 for the activity sheet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Opus 5.5 committed 2026-11-09 17:04:44 +00:00
1 parent 0be487bf96
commit 0117c3e238
22 files changed
+248 -41

No files matched your search

@@ -60,9 +60,13 @@ object ActivityLogic {
/**
* How many tokens are left before the chat compacts itself: the window's [ContextUse.threshold]
* per cent, less what is used. Null when it never will -- the threshold is 0 (off) or 100,
* or the window is unknown -- since a count against an unknown window is a guess.
* or the window is unknown -- since a count against an unknown window is a guess. The
* server's [ContextUse.untilCompact] and [ContextUse.autoCompact] win where it says them.
*/
fun untilAutoCompact(context: ContextUse): Int? {
// The server's own count, where it gives one.
if (context.autoCompact == false) return null
context.untilCompact?.let { return it.coerceAtLeast(0) }
if (context.limit <= 0 || context.threshold !in 1..99) return null
return (context.limit.toLong() * context.threshold / 100 - context.used).toInt().coerceAtLeast(0)
}
@@ -144,7 +144,10 @@ class ApiClient(val base: String, private val token: String, val http: OkHttpCli
// --- Account -----------------------------------------------------------------------------
suspend fun me(): Me = get("/me")
suspend fun models(chatId: String? = null): List<ModelInfo> = get<ModelList>(if (chatId != null) "/models?chat=$chatId" else "/models").models
suspend fun models(chatId: String? = null): List<ModelInfo> = modelList(chatId).models
/** 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")
suspend fun folders(): List<Folder> = get<FolderList>("/folders").folders
@@ -95,6 +95,8 @@ data class ModelInfo(
/** The picture's path on the instance (`/api/v2/models/images/…`), read with the token. */
val image: String? = null,
val default: Boolean = false,
/** Whether a new chat on this model is offered subagents (server 2.0.0-beta.7); null from an older one. */
val subagents: SubagentsOffer? = null,
) {
/**
* The levels, for a server that says them; an older one said only `efforts`, offered after
@@ -118,12 +120,12 @@ data class ModelInfo(
val onLevel: String get() = offered.firstOrNull { it != "off" } ?: effort
/**
* Whether a new chat on this model may have a team, as far as the app can tell: the model
* serves two requests at once (`parallel` ≥ 2, or no stated limit) and takes tools. The
* server also needs subagents on, which only an existing chat's activity says
* (`team_offered`); a setting it does not use is kept and does nothing.
* Whether a new chat on this model is offered subagents: the server's word
* (`subagents.offered`) when it says it. An older server did not, and then the app guesses
* from the model alone: it serves two requests at once (`parallel` ≥ 2, or no stated
* limit) and takes tools.
*/
val mayHaveTeam: Boolean get() = tools && (parallel == null || parallel >= 2)
val mayHaveTeam: Boolean get() = subagents?.offered ?: (tools && (parallel == null || parallel >= 2))
companion object {
val CONTROLS = setOf("none", "switch", "slider")
@@ -131,7 +133,20 @@ data class ModelInfo(
}
@Serializable
data class ModelList(val models: List<ModelInfo> = emptyList())
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,
)
/**
* 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
* names in the chat could -- the chat's own serves one request at a time -- and the setting then
* says so. [cap] is the instance's most, on a chat (not on a model).
*/
@Serializable
data class SubagentsOffer(val offered: Boolean = false, @SerialName("named_only") val namedOnly: Boolean = false, val cap: Int? = null)
@Serializable
data class Folder(val id: String, val name: String = "", @SerialName("parent_id") val parentId: String? = null, val kind: String = "", val position: Int = 0)
@@ -172,6 +187,8 @@ data class Chat(
val plan: JsonObject? = null,
/** The team's size: how many agents, its own included, the chat may have. */
val agents: AgentsSetting? = null,
/** Whether this chat is offered subagents, and the cap (server 2.0.0-beta.7); null from an older one. */
val subagents: SubagentsOffer? = null,
) {
val isAgent: Boolean get() = kind == "agent"
}
@@ -588,6 +605,14 @@ data class ContextUse(
val percent: Double? = null,
val measured: Boolean = false,
val threshold: Int = 0,
/**
* The compaction facts (server 2.0.0-beta.7): whether the chat compacts by itself, how many
* tokens before it does (null: never, or not known), and whether Compact can run now.
* Null from an older server; the app then works the first two out from [threshold].
*/
@SerialName("auto_compact") val autoCompact: Boolean? = null,
@SerialName("until_compact") val untilCompact: Int? = null,
val compactable: Boolean? = null,
@SerialName("tools_count") val toolsCount: Int = 0,
@SerialName("mcp_count") val mcpCount: Int = 0,
val categories: List<ContextPart> = emptyList(),
@@ -613,6 +638,8 @@ data class Activity(
val agents: List<ActivityAgent> = emptyList(),
val team: ActivityTeam? = null,
@SerialName("team_offered") val teamOffered: Boolean = false,
/** The same fact by the word a person reads (server 2.0.0-beta.7). */
@SerialName("subagents_offered") val subagentsOffered: Boolean? = null,
val context: ContextUse? = null,
val outputs: List<Output> = emptyList(),
val plan: JsonObject? = null,