Subagents (spec 3.4.0): the reduced list, coded to subagents.md §12
CI / check (push) Canceled after 0s

Android's share of the tree (§12): a row per agent -- name (id) and
position, the state word (loop.json team.read.states), the progress text
without the clock, context % (floor(used x 100 / window), as team_read
writes it) -- the main agent first, sub-managers' subagents indented under
them, the ended ones after, dimmed, and the open slots. A subagent's row
opens its conversation read-only through the agent route as a member, by
name; the main agent's is the chat.

The server has the tree (services/team.py tree_info, 98f053a) but no
/api/v2 shape for it yet: the app reads it as `tree` in the activity
(`Activity.tree`, null until the server sends it, and then the Tasks
section leaves the team members to the list). To be re-pinned and wired
to the real field when the server's fixture lands.

TreeTest (the §12 example), screenshot 26-subagents.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HomerandClaude Opus 5.5 committed 2026-11-10 09:32:11 +00:00
1 parent 8972bcfcce
commit dff3aa67c0
19 files changed
+431 -1

No files matched your search

@@ -104,4 +104,19 @@ object ActivityLogic {
/** A percentage as the server writes it: one decimal, none when it is whole. */
fun percent(value: Double): String = trim(String.format(Locale.ROOT, "%.1f", value))
/**
* A tree subagent as the agent route knows it: a team member, by its name (`GET
* /chats/{chat}/agents/member/{name}`), which is how the server reads a member's conversation.
*/
fun ofTreeAgent(agent: TreeAgent): ActivityAgent = ActivityAgent(
kind = "member",
id = agent.name,
name = agent.name,
role = agent.position,
brief = agent.task,
state = agent.state,
model = agent.model,
transcript = true,
)
}
@@ -648,6 +648,11 @@ data class Activity(
val context: ContextUse? = null,
val outputs: List<Output> = emptyList(),
val plan: JsonObject? = null,
/**
* The subagent tree (harness spec 3.4.0, `subagents.md` §12), where the server sends it;
* null from an older one, which the Tasks section's team members stand for.
*/
val tree: SubagentTree? = null,
)
@Serializable
@@ -0,0 +1,77 @@
package eu.llembas.android.api
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonElement
/**
* A chat's subagent tree (harness spec 3.4.0, `subagents.md` §12): the main agent at the root,
* every subagent under its parent, open slots, and the subagents that ended. [agents] are in
* tree order. Android shows it as a reduced list (§12): name, position, state, the progress
* line's text and context use, and opens a subagent's conversation read-only.
*/
@Serializable
data class SubagentTree(
val min: Int = 1,
val max: Int = 1,
val size: Int = 0,
@SerialName("open_slots") val openSlots: Int = 0,
val agents: List<TreeAgent> = emptyList(),
val ended: List<TreeAgent> = emptyList(),
)
/** One agent of the tree. [position], [task] and a progress `what` are a model's words: text only. */
@Serializable
data class TreeAgent(
val id: String = "",
val name: String = "",
val position: String = "",
val parent: String? = null,
val state: String = "",
val model: String = "",
val mode: String = "",
val request: List<String> = emptyList(),
val manager: Boolean = false,
val task: String = "",
val context: TreeContext? = null,
val progress: Progress? = null,
val findings: Int = 0,
/** How many of the room's messages are to or from it (a count; a newer server may say more). */
val messages: JsonElement? = null,
/** When it ended, Unix milliseconds; null while it lives. */
val ended: Long? = null,
) {
val isMain: Boolean get() = parent == null
/** `floor(used × 100 / window)`, as the server's `team_read` writes it; null without a window. */
val contextPercent: Int? get() = context?.takeIf { it.window > 0 }?.let { (it.used.toLong() * 100 / it.window).toInt() }
}
@Serializable
data class TreeContext(val used: Int = 0, val window: Int = 0)
/** One row of the reduced list: an agent and how deep it sits under the main agent. */
data class TreeRow(val agent: TreeAgent, val depth: Int, val ended: Boolean)
object TreeLogic {
/** The states a subagent ends in (`subagents.md` §9). */
val ENDED = setOf("done", "out_of_context", "stopped")
/**
* The rows to draw: the live agents in tree order, each as deep as its parent chain (the main
* agent 0), then the ended ones, flat. A parent the tree does not hold (moved, ended) counts
* as the main agent, so no row is lost or drawn deeper than it can be.
*/
fun rows(tree: SubagentTree): List<TreeRow> {
val byName = tree.agents.associateBy { it.name }
fun depth(agent: TreeAgent, seen: Set<String> = emptySet()): Int {
val parent = agent.parent?.let { byName[it] } ?: return if (agent.parent == null) 0 else 1
if (parent.name in seen) return 1
return depth(parent, seen + agent.name) + 1
}
return tree.agents.map { TreeRow(it, depth(it), ended = false) } + tree.ended.map { TreeRow(it, 1, ended = true) }
}
/** Whether there is anything to show beyond the main agent alone. */
fun hasSubagents(tree: SubagentTree?): Boolean = tree != null && (tree.agents.any { !it.isMain } || tree.ended.isNotEmpty() || tree.openSlots > 0)
}
@@ -81,6 +81,7 @@ import eu.llembas.android.api.AgentDetail
import eu.llembas.android.api.ContextUse
import eu.llembas.android.api.Output
import eu.llembas.android.api.RoomMessage
import eu.llembas.android.api.TreeLogic
import eu.llembas.android.lembas
import eu.llembas.android.ui.MarkdownText
import eu.llembas.android.ui.explain
@@ -329,7 +330,18 @@ fun ActivityContent(
}
}
}
item { Section(stringResource(R.string.activity_tasks)) { TasksSection(activity, readAt, now, actions, unfolded) } }
// 3.4.0: the subagents as a reduced list, each opening its conversation read-only;
// the Tasks section then holds the background jobs, the members being in the list.
val tree = activity.tree?.takeIf { TreeLogic.hasSubagents(it) }
if (tree != null) {
item {
Section(stringResource(R.string.team_agents), count = tree.agents.count { !it.isMain }.takeIf { it > 0 }) {
SubagentList(tree) { agent -> actions.read(ActivityLogic.ofTreeAgent(agent)) }
}
}
}
val tasks = if (tree != null) activity.copy(agents = activity.agents.filter { it.kind != "member" }) else activity
item { Section(stringResource(R.string.activity_tasks)) { TasksSection(tasks, readAt, now, actions, unfolded) } }
activity.team?.let { team ->
item { Section(stringResource(R.string.team_room), count = team.room.size.takeIf { it > 0 }) { RoomSection(team) } }
}
@@ -0,0 +1,139 @@
package eu.llembas.android.ui.chat
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import eu.llembas.android.R
import eu.llembas.android.api.SubagentTree
import eu.llembas.android.api.TreeAgent
import eu.llembas.android.api.TreeLogic
import eu.llembas.android.api.TreeRow
import eu.llembas.android.ui.progressLineOf
import eu.llembas.android.ui.theme.LocalPalette
import eu.llembas.android.ui.theme.Palette
/**
* The subagents as Android shows them (harness spec 3.4.0, `subagents.md` §12, the reduced
* list): each row its name and id, its position, its state, what it is doing now (the progress
* text, without the clock -- a row has no room) and how full its context is. The main agent
* first; ended subagents after the live ones, dimmed, with how each ended. A subagent's row opens
* its conversation, read-only ([onOpen]); the main agent's conversation is the chat itself.
*/
@Composable
fun SubagentList(tree: SubagentTree, onOpen: (TreeAgent) -> Unit) {
val palette = LocalPalette.current
Column(verticalArrangement = Arrangement.spacedBy(2.dp)) {
Text(
stringResource(R.string.team_size, tree.size.toString(), tree.max.toString()),
style = MaterialTheme.typography.bodySmall,
color = palette.inkMuted,
)
TreeLogic.rows(tree).forEach { row -> TreeRowItem(row, onOpen) }
if (tree.openSlots > 0) {
Text(
stringResource(R.string.tree_open_slots, tree.openSlots.toString()),
style = MaterialTheme.typography.bodySmall,
color = palette.inkFaint,
modifier = Modifier.padding(start = 16.dp, top = 4.dp),
)
}
}
}
/**
* One row, two lines on a fixed frame: the name and position give way (cut, not wrapped) to the
* state word; the progress text gives way to the context percentage in a column of its own width.
*/
@Composable
private fun TreeRowItem(row: TreeRow, onOpen: (TreeAgent) -> Unit) {
val palette = LocalPalette.current
val agent = row.agent
val opens = !agent.isMain
Column(
Modifier
.fillMaxWidth()
.heightIn(min = 48.dp)
.then(if (opens) Modifier.clickable { onOpen(agent) } else Modifier)
.alpha(if (row.ended) 0.6f else 1f)
.padding(start = (16 * row.depth.coerceIn(0, 4)).dp, top = 6.dp, bottom = 6.dp),
verticalArrangement = Arrangement.Center,
) {
Row(verticalAlignment = Alignment.CenterVertically) {
val title = if (agent.isMain) agent.name else "${agent.name} (${agent.id})"
Text(
listOf(title, agent.position).filter { it.isNotBlank() }.joinToString(" — "),
style = MaterialTheme.typography.bodyMedium,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.weight(1f),
)
Text(
treeStateWord(agent.state),
style = MaterialTheme.typography.labelMedium,
color = treeStateColour(palette, agent.state),
maxLines = 1,
modifier = Modifier.padding(start = 8.dp),
)
}
val doing = if (row.ended) null else progressLineOf(agent.progress, withElapsed = false)
val percent = agent.contextPercent
if (doing != null || percent != null) {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
doing.orEmpty(),
style = MaterialTheme.typography.labelSmall,
color = palette.inkMuted,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.weight(1f),
)
Text(
percent?.let { stringResource(R.string.tree_context, it.toString()) }.orEmpty(),
style = MaterialTheme.typography.labelSmall,
color = palette.inkFaint,
textAlign = TextAlign.End,
maxLines = 1,
modifier = Modifier.width(88.dp),
)
}
}
}
}
/** The state's word (`loop.json` `team.read.states`), the main agent's and every subagent's. */
@Composable
private fun treeStateWord(state: String): String = when (state) {
"working" -> stringResource(R.string.tree_state_working)
"waiting" -> stringResource(R.string.tree_state_waiting)
"finished" -> stringResource(R.string.tree_state_finished)
"idle" -> stringResource(R.string.tree_state_idle)
"paused" -> stringResource(R.string.tree_state_paused)
"done" -> stringResource(R.string.tree_state_done)
"out_of_context" -> stringResource(R.string.tree_state_out_of_context)
"stopped" -> stringResource(R.string.tree_state_stopped)
else -> state
}
private fun treeStateColour(palette: Palette, state: String): Color = when (state) {
"working" -> palette.accent
"waiting", "paused" -> palette.warning
"done", "finished" -> palette.success
"out_of_context" -> palette.danger
else -> palette.inkFaint
}