Contract at server dev 8dd3201: a subagent's conversation by its id
CI / check (push) Canceled after 0s
CI / check (push) Canceled after 0s
The server's /api/v2 has the tree routes (8dd3201): GET /chats/{c}/tree
{tree, room, live} and GET /chats/{c}/subagents/{id}/transcript {id,
state, turns}. The activity sheet reads the tree when it opens (an older
server's 404 is ignored), so the list is there without a reply streaming;
a subagent's row opens its conversation from the transcript route, by id,
followed every 3 s while it has not ended -- the provisional member-by-name
route is gone. The conversation dialog is one for both kinds now
(ConversationDialog); a 409 (an agent chat's device away) is said in the
server's words. Findings and stopping are not on Android (the reduced
display, subagents.md §12).
ContractTest reads tree.json and subagent_transcript.json.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
12 files changed
+237
-38
No files matched your search
@@ -104,19 +104,4 @@ 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,
|
||||
)
|
||||
}
|
||||
@@ -247,6 +247,12 @@ class ApiClient(val base: String, private val token: String, val http: OkHttpCli
|
||||
/** One background agent and its whole conversation, read-only. `kind` is `member` or `job`. */
|
||||
suspend fun agent(chatId: String, kind: String, id: String): AgentDetail = get("/chats/$chatId/agents/${segment(kind)}/${segment(id)}")
|
||||
|
||||
/** The chat's subagent tree and room (spec 3.4.0); a 404 from a server without it. */
|
||||
suspend fun tree(chatId: String): TreeView = get("/chats/$chatId/tree")
|
||||
|
||||
/** A subagent's conversation by its id (`s1`), read-only; 409 while an agent chat's device is away. */
|
||||
suspend fun subagentTranscript(chatId: String, id: String): SubagentTranscript = get("/chats/$chatId/subagents/${segment(id)}/transcript")
|
||||
|
||||
/** Stop a background agent (a member leaves the team with those under it). */
|
||||
suspend fun stopAgent(chatId: String, kind: String, id: String): List<String> =
|
||||
send<Stopped>("POST", "/chats/$chatId/agents/${segment(kind)}/${segment(id)}/stop", null).stopped
|
||||
|
||||
@@ -47,6 +47,14 @@ data class TreeAgent(
|
||||
val contextPercent: Int? get() = context?.takeIf { it.window > 0 }?.let { (it.used.toLong() * 100 / it.window).toInt() }
|
||||
}
|
||||
|
||||
/** `GET /chats/{chat}/tree`: the tree (null: none), the room, and whether it is live (false: kept while the device is away). */
|
||||
@Serializable
|
||||
data class TreeView(val tree: SubagentTree? = null, val room: List<RoomMessage> = emptyList(), val live: Boolean = true)
|
||||
|
||||
/** `GET /chats/{chat}/subagents/{id}/transcript`: its conversation, read-only, live or after it ended. */
|
||||
@Serializable
|
||||
data class SubagentTranscript(val id: String = "", val state: String = "", val turns: List<AgentTurn> = emptyList())
|
||||
|
||||
@Serializable
|
||||
data class TreeContext(val used: Int = 0, val window: Int = 0)
|
||||
|
||||
|
||||
@@ -77,11 +77,13 @@ import eu.llembas.android.api.ActivityAgent
|
||||
import eu.llembas.android.api.ActivityLogic
|
||||
import eu.llembas.android.api.ActivitySummary
|
||||
import eu.llembas.android.api.ActivityTeam
|
||||
import eu.llembas.android.api.AgentDetail
|
||||
import eu.llembas.android.api.AgentTurn
|
||||
import eu.llembas.android.api.ApiClient
|
||||
import eu.llembas.android.api.ContextUse
|
||||
import eu.llembas.android.api.Output
|
||||
import eu.llembas.android.api.RoomMessage
|
||||
import eu.llembas.android.api.SubagentTree
|
||||
import eu.llembas.android.api.TreeAgent
|
||||
import eu.llembas.android.api.TreeLogic
|
||||
import eu.llembas.android.lembas
|
||||
import eu.llembas.android.ui.MarkdownText
|
||||
@@ -195,6 +197,7 @@ private fun categoryName(key: String): String = when (key) {
|
||||
interface ActivityActions {
|
||||
fun stop(agent: ActivityAgent) {}
|
||||
fun read(agent: ActivityAgent) {}
|
||||
fun readSubagent(agent: TreeAgent) {}
|
||||
fun openFile(path: String) {}
|
||||
fun compact() {}
|
||||
}
|
||||
@@ -212,6 +215,7 @@ fun ActivityPanel(chatId: String?, state: ChatState, model: ChatViewModel, canOp
|
||||
var now by remember { mutableLongStateOf(SystemClock.elapsedRealtime()) }
|
||||
var stopping by remember { mutableStateOf<ActivityAgent?>(null) }
|
||||
var reading by remember { mutableStateOf<ActivityAgent?>(null) }
|
||||
var readingSubagent by remember { mutableStateOf<TreeAgent?>(null) }
|
||||
var viewing by remember { mutableStateOf<String?>(null) }
|
||||
|
||||
LaunchedEffect(chatId) {
|
||||
@@ -240,6 +244,10 @@ fun ActivityPanel(chatId: String?, state: ChatState, model: ChatViewModel, canOp
|
||||
reading = agent
|
||||
}
|
||||
|
||||
override fun readSubagent(agent: TreeAgent) {
|
||||
readingSubagent = agent
|
||||
}
|
||||
|
||||
override fun openFile(path: String) {
|
||||
if (canOpenFiles) viewing = path
|
||||
}
|
||||
@@ -283,6 +291,7 @@ fun ActivityPanel(chatId: String?, state: ChatState, model: ChatViewModel, canOp
|
||||
)
|
||||
}
|
||||
if (chatId != null) reading?.let { agent -> AgentConversation(chatId, agent, onClose = { reading = null }) }
|
||||
if (chatId != null) readingSubagent?.let { agent -> SubagentConversation(chatId, agent, onClose = { readingSubagent = null }) }
|
||||
viewing?.let { path -> TreeFileViewer(path, onClose = { viewing = null }) }
|
||||
}
|
||||
|
||||
@@ -339,7 +348,7 @@ fun ActivityContent(
|
||||
if (shownTree != null) {
|
||||
item {
|
||||
Section(stringResource(R.string.team_agents), count = shownTree.agents.count { !it.isMain }.takeIf { it > 0 }) {
|
||||
SubagentList(shownTree) { agent -> actions.read(ActivityLogic.ofTreeAgent(agent)) }
|
||||
SubagentList(shownTree, actions::readSubagent)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -775,22 +784,57 @@ private fun RoomEntry(entry: RoomMessage) {
|
||||
/** What a background agent was told and said: `GET /chats/{chat}/agents/{kind}/{id}`, re-read while it works. */
|
||||
@Composable
|
||||
private fun AgentConversation(chatId: String, agent: ActivityAgent, onClose: () -> Unit) {
|
||||
val state = stateWord(agent.state)
|
||||
ConversationDialog(
|
||||
name = agent.name,
|
||||
facts = listOf(state, agent.model),
|
||||
key = agent.kind + "/" + agent.id,
|
||||
onClose = onClose,
|
||||
) { api ->
|
||||
val detail = api.agent(chatId, agent.kind, agent.id)
|
||||
Conversation(detail.transcript, detail.agent.isActive)
|
||||
}
|
||||
}
|
||||
|
||||
/** A tree subagent's conversation (spec 3.4.0 §11), read-only, followed while it runs. */
|
||||
@Composable
|
||||
private fun SubagentConversation(chatId: String, agent: TreeAgent, onClose: () -> Unit) {
|
||||
ConversationDialog(
|
||||
name = "${agent.name} (${agent.id})",
|
||||
facts = listOf(treeStateWord(agent.state), agent.position, agent.model),
|
||||
key = "tree/" + agent.id,
|
||||
onClose = onClose,
|
||||
) { api ->
|
||||
val read = api.subagentTranscript(chatId, agent.id)
|
||||
Conversation(read.turns, read.state !in TreeLogic.ENDED)
|
||||
}
|
||||
}
|
||||
|
||||
/** What a conversation dialog draws: the turns, and whether to read them again (it still runs). */
|
||||
private class Conversation(val turns: List<AgentTurn>, val running: Boolean)
|
||||
|
||||
/**
|
||||
* An agent's conversation, full screen and read-only: read with [load], again every 3 s while
|
||||
* it runs. Nobody types into it.
|
||||
*/
|
||||
@Composable
|
||||
private fun ConversationDialog(name: String, facts: List<String>, key: String, onClose: () -> Unit, load: suspend (ApiClient) -> Conversation) {
|
||||
val context = LocalContext.current
|
||||
val palette = LocalPalette.current
|
||||
var detail by remember { mutableStateOf<AgentDetail?>(null) }
|
||||
var detail by remember { mutableStateOf<Conversation?>(null) }
|
||||
var error by remember { mutableStateOf<String?>(null) }
|
||||
LaunchedEffect(agent.kind, agent.id) {
|
||||
LaunchedEffect(key) {
|
||||
val api = context.lembas.instances.client() ?: return@LaunchedEffect
|
||||
while (true) {
|
||||
try {
|
||||
detail = api.agent(chatId, agent.kind, agent.id)
|
||||
detail = load(api)
|
||||
error = null
|
||||
} catch (e: kotlinx.coroutines.CancellationException) {
|
||||
throw e
|
||||
} catch (e: Exception) {
|
||||
error = context.explain(e)
|
||||
}
|
||||
if (detail?.agent?.isActive != true) break
|
||||
if (detail?.running != true) break
|
||||
delay(3_000)
|
||||
}
|
||||
}
|
||||
@@ -801,20 +845,20 @@ private fun AgentConversation(chatId: String, agent: ActivityAgent, onClose: ()
|
||||
navigationIcon = { IconButton(onClick = onClose) { Icon(Icons.Filled.Close, contentDescription = stringResource(R.string.close)) } },
|
||||
title = {
|
||||
Column {
|
||||
Text(agent.name, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
val now = detail?.agent ?: agent
|
||||
Text(name, maxLines = 1, overflow = TextOverflow.Ellipsis)
|
||||
Text(
|
||||
listOf(stateWord(now.state), now.model).filter { it.isNotBlank() }.joinToString(" · "),
|
||||
facts.filter { it.isNotBlank() }.joinToString(" · "),
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = palette.inkFaint,
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
},
|
||||
) { padding ->
|
||||
val turns = detail?.transcript
|
||||
val turns = detail?.turns
|
||||
when {
|
||||
turns == null && error != null -> Box(Modifier.padding(padding).fillMaxSize().padding(32.dp), contentAlignment = Alignment.Center) {
|
||||
Text(error.orEmpty(), color = palette.inkMuted, textAlign = TextAlign.Center)
|
||||
|
||||
@@ -458,6 +458,9 @@ class ChatViewModel(app: Application) :
|
||||
teamOffered = read.subagentsOffered ?: read.teamOffered,
|
||||
)
|
||||
}
|
||||
// The tree (spec 3.4.0), for a sheet opened when no reply streams it; an older
|
||||
// server answers 404 and the Tasks section stands for it.
|
||||
runCatching { api().tree(chat.id) }.getOrNull()?.tree?.let { tree -> _state.update { it.copy(tree = tree) } }
|
||||
} catch (e: Exception) {
|
||||
fail(e)
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ private fun TreeRowItem(row: TreeRow, onOpen: (TreeAgent) -> Unit) {
|
||||
|
||||
/** 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) {
|
||||
internal 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)
|
||||
|
||||
@@ -17,9 +17,11 @@ import eu.llembas.android.api.Plan
|
||||
import eu.llembas.android.api.StatusFrame
|
||||
import eu.llembas.android.api.SteeredFrame
|
||||
import eu.llembas.android.api.StepsFrame
|
||||
import eu.llembas.android.api.SubagentTranscript
|
||||
import eu.llembas.android.api.Tail
|
||||
import eu.llembas.android.api.ToolCall
|
||||
import eu.llembas.android.api.TreeFrame
|
||||
import eu.llembas.android.api.TreeView
|
||||
import eu.llembas.android.ui.chat.approvalTexts
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.builtins.ListSerializer
|
||||
@@ -195,6 +197,20 @@ class ContractTest {
|
||||
assertEquals(tree, LiveReply("m").apply("tree", text("event_tree")).tree)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theTreeReadAndASubagentsConversation() {
|
||||
val view = read("tree", TreeView.serializer())
|
||||
assertTrue(view.live)
|
||||
assertNotNull(view.tree)
|
||||
assertEquals(listOf("message", "report"), view.room.map { if (it.report) "report" else "message" })
|
||||
val read = read("subagent_transcript", SubagentTranscript.serializer())
|
||||
assertEquals("s2", read.id)
|
||||
assertEquals("working", read.state)
|
||||
assertTrue(read.turns.first().machine)
|
||||
assertEquals("src/api.py", read.turns[1].tools.single().title)
|
||||
assertTrue(read.turns[1].running)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun everyFrameParses() {
|
||||
assertTrue(read("event_steps", StepsFrame.serializer()).steps.isNotEmpty())
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package eu.llembas.android
|
||||
|
||||
import eu.llembas.android.api.ActivityLogic
|
||||
import eu.llembas.android.api.LembasJson
|
||||
import eu.llembas.android.api.SubagentTree
|
||||
import eu.llembas.android.api.TreeLogic
|
||||
@@ -72,12 +71,4 @@ class TreeTest {
|
||||
assertTrue(TreeLogic.hasSubagents(tree.copy(agents = tree.agents.take(1), ended = emptyList(), openSlots = 2)))
|
||||
assertTrue(TreeLogic.hasSubagents(tree))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aSubagentOpensAsAMember() {
|
||||
val agent = ActivityLogic.ofTreeAgent(tree.agents[1])
|
||||
assertEquals("member", agent.kind)
|
||||
assertEquals("parser", agent.id)
|
||||
assertTrue(agent.transcript)
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ref": "2fd3c031468a4ea34e187142020a7ec16c118a3e",
|
||||
"commit": "2fd3c031468a4ea34e187142020a7ec16c118a3e",
|
||||
"sha256": "b3bf3570ff57b64c0b9ae18243231e90b26da93b1c9684ea9f2fe173f7d786cc"
|
||||
"ref": "8dd32015ef4e62a2721db325f5bf665f32bb6b30",
|
||||
"commit": "8dd32015ef4e62a2721db325f5bf665f32bb6b30",
|
||||
"sha256": "1ce08462fc195ce942a5e76b06eaf7bbf5298502ef32ae4f0a060b1ebb98f6de"
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"id": "s2",
|
||||
"findings": [
|
||||
{
|
||||
"n": 1,
|
||||
"text": "Login is POST /session.",
|
||||
"time": 1767323045000
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"id": "s2",
|
||||
"state": "working",
|
||||
"turns": [
|
||||
{
|
||||
"role": "user",
|
||||
"text": "Write the routes.",
|
||||
"machine": true
|
||||
},
|
||||
{
|
||||
"role": "assistant",
|
||||
"text": "Reading the API first.",
|
||||
"tools": [
|
||||
{
|
||||
"name": "read",
|
||||
"title": "src/api.py",
|
||||
"isError": false
|
||||
}
|
||||
],
|
||||
"error": "",
|
||||
"running": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
{
|
||||
"tree": {
|
||||
"min": 2,
|
||||
"max": 4,
|
||||
"size": 3,
|
||||
"open_slots": 0,
|
||||
"agents": [
|
||||
{
|
||||
"id": "lead",
|
||||
"name": "lead",
|
||||
"position": "the main agent",
|
||||
"parent": null,
|
||||
"state": "working",
|
||||
"model": "local/qwen",
|
||||
"mode": "auto",
|
||||
"request": [],
|
||||
"manager": true,
|
||||
"progress": {
|
||||
"phase": "waiting_for_subagents",
|
||||
"since": 1767323045000,
|
||||
"running": 2
|
||||
},
|
||||
"findings": 0,
|
||||
"messages": 1
|
||||
},
|
||||
{
|
||||
"id": "s1",
|
||||
"name": "area",
|
||||
"position": "owns the API",
|
||||
"parent": "lead",
|
||||
"state": "working",
|
||||
"model": "local/qwen",
|
||||
"mode": "auto",
|
||||
"request": [],
|
||||
"manager": true,
|
||||
"task": "Direct it.",
|
||||
"progress": null,
|
||||
"findings": 0,
|
||||
"messages": 1
|
||||
},
|
||||
{
|
||||
"id": "s2",
|
||||
"name": "routes",
|
||||
"position": "writes the routes",
|
||||
"parent": "area",
|
||||
"state": "working",
|
||||
"model": "local/qwen",
|
||||
"mode": "edit",
|
||||
"request": [
|
||||
"execute"
|
||||
],
|
||||
"manager": false,
|
||||
"task": "Write the routes.",
|
||||
"context": {
|
||||
"used": 9100,
|
||||
"window": 131072
|
||||
},
|
||||
"progress": {
|
||||
"phase": "running_tool",
|
||||
"since": 1767323045000,
|
||||
"tool": "read",
|
||||
"what": "src/api.py"
|
||||
},
|
||||
"findings": 1,
|
||||
"messages": 1
|
||||
}
|
||||
],
|
||||
"ended": [
|
||||
{
|
||||
"id": "s3",
|
||||
"name": "scout",
|
||||
"position": "maps the code",
|
||||
"parent": "lead",
|
||||
"state": "done",
|
||||
"model": "local/qwen",
|
||||
"mode": "auto",
|
||||
"request": [],
|
||||
"manager": false,
|
||||
"task": "Map it.",
|
||||
"progress": null,
|
||||
"findings": 0,
|
||||
"messages": 1,
|
||||
"ended": 1767323045000
|
||||
}
|
||||
]
|
||||
},
|
||||
"room": [
|
||||
{
|
||||
"n": 1,
|
||||
"from": "routes",
|
||||
"to": [
|
||||
"area"
|
||||
],
|
||||
"text": "Routes are in.",
|
||||
"report": false,
|
||||
"kind": "message",
|
||||
"time": 1767323045000
|
||||
},
|
||||
{
|
||||
"n": 2,
|
||||
"from": "scout",
|
||||
"to": [
|
||||
"lead"
|
||||
],
|
||||
"text": "Mapped: see map.md.",
|
||||
"report": true,
|
||||
"kind": "report",
|
||||
"time": 1767323045000
|
||||
}
|
||||
],
|
||||
"live": true
|
||||
}
|
||||
Reference in new issue
Block a user