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

@@ -0,0 +1,96 @@
package eu.llembas.android
import eu.llembas.android.api.Activity
import eu.llembas.android.api.ActivityLogic
import eu.llembas.android.api.AgentsSetting
import eu.llembas.android.api.Chat
import eu.llembas.android.api.ContextUse
import eu.llembas.android.api.LembasJson
import eu.llembas.android.api.ModelInfo
import eu.llembas.android.api.ModelList
import eu.llembas.android.api.SubagentsOffer
import eu.llembas.android.ui.chat.ChatState
import eu.llembas.android.ui.chat.Draft
import eu.llembas.android.ui.chat.offersTeam
import eu.llembas.android.ui.chat.subagentsCap
import eu.llembas.android.ui.chat.subagentsNamedOnly
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
/**
* The Subagents setting by the server's word (harness spec 3.3.0, `subagents.md` §4): shown
* when it says subagents are offered, with its note when only a named model could serve, up to
* the instance's cap -- and, from a server that says none of it, the app's old guess.
*/
class SubagentsTest {
private val serving = ModelInfo(id = "qwen", tools = true, parallel = 4)
@Test
fun theServersWordWinsOverTheGuess() {
// The guess would offer them (tools, four at once); the server says no.
val refused = serving.copy(subagents = SubagentsOffer(offered = false))
assertFalse(refused.mayHaveTeam)
// The guess would not (one at a time); the server offers them for a named model.
val oneAtATime = serving.copy(parallel = 1, subagents = SubagentsOffer(offered = true, namedOnly = true))
assertTrue(oneAtATime.mayHaveTeam)
// An older server: the guess.
assertTrue(serving.mayHaveTeam)
assertFalse(serving.copy(parallel = 1).mayHaveTeam)
}
@Test
fun aNewChatAsksItsModel() {
val state = ChatState(models = listOf(serving.copy(parallel = 1, subagents = SubagentsOffer(offered = true, namedOnly = true))), modelsCap = 8)
assertTrue(state.offersTeam(agent = false))
assertFalse(state.offersTeam(agent = true))
assertTrue(state.subagentsNamedOnly)
assertEquals(8, state.subagentsCap)
}
@Test
fun anOpenChatAsksItself() {
val chat = Chat(id = "c1", model = "qwen", subagents = SubagentsOffer(offered = false, cap = 6))
// The activity's older word says yes; the chat's own says no, and wins.
val state = ChatState(chat = chat, models = listOf(serving), teamOffered = true, modelsCap = 8)
assertFalse(state.offersTeam(agent = false))
assertEquals(6, state.subagentsCap)
assertFalse(state.subagentsNamedOnly)
// A chat from an older server: the activity's word, and the spec's cap.
val older = ChatState(chat = chat.copy(subagents = null), teamOffered = true, draft = Draft())
assertTrue(older.offersTeam(agent = false))
assertEquals(AgentsSetting.CAP, older.subagentsCap)
}
@Test
fun theNewFieldsParseAndTheOldOnesStillDo() {
val list = LembasJson.decodeFromString(
ModelList.serializer(),
"""{"models": [{"id": "qwen", "subagents": {"offered": true, "named_only": false}}], "subagents_cap": 12}""",
)
assertEquals(12, list.subagentsCap)
assertEquals(SubagentsOffer(offered = true), list.models.single().subagents)
val bare = LembasJson.decodeFromString(ModelList.serializer(), """{"models": [{"id": "qwen"}]}""")
assertNull(bare.subagentsCap)
assertNull(bare.models.single().subagents)
val activity = LembasJson.decodeFromString(
Activity.serializer(),
"""{"team_offered": true, "subagents_offered": false,
"context": {"used": 1000, "limit": 10000, "threshold": 95, "auto_compact": true, "until_compact": 8000, "compactable": false}}""",
)
assertEquals(false, activity.subagentsOffered)
assertEquals(8000, ActivityLogic.untilAutoCompact(activity.context!!))
assertEquals(false, activity.context!!.compactable)
}
@Test
fun autoCompactOffIsOffWhateverTheThreshold() {
val context = ContextUse(used = 1000, limit = 10000, threshold = 95, autoCompact = false, untilCompact = 8500)
assertNull(ActivityLogic.untilAutoCompact(context))
// Without the server's facts: worked out from the threshold.
assertEquals(8500, ActivityLogic.untilAutoCompact(ContextUse(used = 1000, limit = 10000, threshold = 95)))
}
}
@@ -24,6 +24,7 @@ import eu.llembas.android.api.ScheduleRun
import eu.llembas.android.api.SchedulingModel
import eu.llembas.android.api.SchedulingModels
import eu.llembas.android.api.Step
import eu.llembas.android.api.SubagentsOffer
import eu.llembas.android.api.Tail
import eu.llembas.android.api.ToolBlock
import eu.llembas.android.api.ToolCall
@@ -184,6 +185,11 @@ object Fakes {
chat = chat.copy(model = "gpt-oss", effort = "high", mode = "plan", agents = AgentsSetting(1, 4)),
)
/** A chat whose model serves one request at a time, on an instance that caps subagents at 6. */
val tunedOneAtATime = tuned.copy(
chat = tuned.chat!!.copy(agents = AgentsSetting(2, 3), subagents = SubagentsOffer(offered = true, namedOnly = true, cap = 6)),
)
val chats = ChatsState(
chats = listOf(
chat,
@@ -103,8 +103,9 @@ class ScreenShots {
}
@Test
fun tune() = shoot("07-tune") {
SheetOver { TuneContent(Fakes.tuned, NoChatActions, agent = false) }
fun tune() {
shoot("07-tune") { SheetOver { TuneContent(Fakes.tuned, NoChatActions, agent = false) } }
shoot("07-tune-one-at-a-time") { SheetOver { TuneContent(Fakes.tunedOneAtATime, NoChatActions, agent = false) } }
}
@Test
@@ -140,7 +141,8 @@ class ScreenShots {
shoot("14-activity", content = sheet)
shoot("14-activity", Phone.Small, content = sheet)
shoot("14-activity", Phone.Small, fontScale = 1.5f, content = sheet)
shoot("15-activity-open", content = open)
shoot("14-activity", Phone.Scroll, content = sheet)
shoot("15-activity-open", Phone.Scroll, content = open)
shoot("16-activity-new-chat") {
SheetOver { ActivityContent(eu.llembas.android.api.Activity(), readAt = 0, now = 0, actions = NoActivityActions, canCompact = false) }
}
@@ -14,10 +14,14 @@ import com.github.takahirom.roborazzi.inspectionMode
import com.github.takahirom.roborazzi.size
import eu.llembas.android.ui.theme.LembasTheme
/** The phones the screens are looked at on: a large one, and a small one where things crowd. */
/**
* The phones the screens are looked at on: a large one, and a small one where things crowd.
* [Scroll] is the large one's width, tall enough to see a sheet's whole scroll at once.
*/
enum class Phone(val tag: String, val widthDp: Int, val heightDp: Int) {
Large("411x891", 411, 891),
Small("360x640", 360, 640),
Scroll("411x2000", 411, 2000),
}
/**