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)
}