会议模式:列表类型 + 变量描述 + 多个最终输出(标签页 / 任意类型)

用户四条,全做了。

【1. 列表类型(只支持追加和清除)】
PIN_TYPES 加 'list'。列表就存成一个 JSON 数组的文本(`["a","b"]`)。

只做两个运算 —— 追加 / 清空。不做删除/插入/排序:
列表在会议里的用途是"攒东西"(攒一轮轮产出、攒要点),要精确编辑的场合
本来就该用变量或让智能体去处理。**少一套操作 = 少一类出错方式。**

加法:`[[SET x=...]]` 时告诉模型"列表只能整体写入一个 JSON 数组",
免得它想去做删除/排序(那会让它写出一个我们解析不了的东西)。

【2. 列表给模型看时是 JSON】
list_render():缩进好的 JSON,ensure_ascii=False 让中文原样留着。
空列表给明确的 `[]`,而不是空字符串 —— 让模型知道"这是个空列表",
而不是"这里什么都没有"。这两个对模型是完全不同的信息。

转换节点也能转列表了:
  文本 → 列表:是 JSON 数组就认,其他当"单个元素"包成一项(比丢掉好)

【3. 变量加描述位,给智能体时也带上】
variables_prompt() 现在收 var_meta(类型 + 描述),拼出来是这样:

    【你可以看到的变量】
    - n = 3 (数字,已经循环了几轮)
    - 要点 = [
      "第一点",
      "第二点"
    ] (列表,每轮攒下来的要点)

    【你可以修改的变量】要点(列表,每轮攒下来的要点)

用户写的描述本来就是给模型看的上下文,不给它等于白写 ——
光有变量名,模型只能猜"这个 isRun 到底是次数还是个开关"。

【4. 多个最终输出,标签页展示,按类型不同渲染】
引擎:每个 end 节点都记下自己那份结果和**类型**(取数据入线的类型),
      meeting_done 带回 results 列表,运行记录里也存。
界面:结果屏顶部一排标签页(只有一个输出时不显示标签页,省一行),
      下面的展示**按类型不同**:
        文本  原样段落
        数字  26sp 大字,一眼看到
        真假  绿/红醒目标记
        列表  按 JSON 展开成 1. 2. 3. 一项一项 + "共 N 项"(空列表明说"(空列表)")
      全都当一段文字显示的话,数字混在长文里看不见、列表挤成一坨没法读。

【验证】
- 引擎回归 40/40,Node 与 Python 16/16 逐用例一致
- 会议 HTTP 13/13 ×2、语音 41/41、Markdown 19/19
- 实测:三个 end 节点分别接 str / num / list,结果拿到 3 份且类型正确
- 实测:列表追加 / 清除、文本转列表、变量描述拼进提示词
This commit is contained in:
l
2026-10-11 02:05:00 +08:00
parent 73e9ead216
commit 7b87eb7ccd
5 changed files with 326 additions and 40 deletions

View File

@@ -52,6 +52,7 @@ import androidx.compose.material3.Slider
import org.json.JSONObject
import org.json.JSONArray
import com.doubao.lynxclone.data.toJson
import com.doubao.lynxclone.data.MeetingResult
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
@@ -323,6 +324,8 @@ private fun MeetingEditorScreen(vm: AppViewModel, initial: Meeting, onBack: () -
// 结果界面要的是"这条链上每一步的结果",不是一堆节点的最终状态 ——
// 循环转几轮就有几条记录,一眼能看出先后。
val liveTrace = remember { mutableStateListOf<TraceStep>() }
// 本次运行的最终输出(可能有多个、类型各不相同,结果界面按标签页展示)
val liveResults = remember { mutableStateListOf<com.doubao.lynxclone.data.MeetingResult>() }
// 当前正在跑哪个节点(界面顶部要显示"运行到哪了")
var nowRunning by remember { mutableStateOf("") }
// 每个节点的告警(比如"输入是空的,你漏了数据线")。
@@ -472,6 +475,8 @@ private fun MeetingEditorScreen(vm: AppViewModel, initial: Meeting, onBack: () -
nodeOutputs[ev.nodeId] = "出错:${ev.error}"
}
"meeting_done" -> {
liveResults.clear()
liveResults.addAll(ev.results)
running = false
litEdge = -1
nowRunning = ""
@@ -1112,6 +1117,7 @@ if (edge.kind == "exec") {
meeting = meeting,
liveOutputs = nodeOutputs,
liveTrace = liveTrace.toList(),
liveResults = liveResults.toList(),
onBack = { showResult = false },
)
return
@@ -1758,6 +1764,135 @@ private fun EditorMenuDialog(
)
}
/**
* 一个最终输出的展示。
*
* ★ **不同类型的展示方式不一样**(用户明确要求):
* 文本 原样段落
* 数字 大字,一眼看到
* 真假 一枚醒目的绿/红标记
* 列表 按 JSON 展开成一项一项(空列表也明确写"(空)")
* 全都当成一段文字显示的话,数字混在长文里看不见、列表挤成一坨没法读。
*/
@Composable
private fun ResultValueView(r: MeetingResult) {
when (r.type) {
"num" -> Text(
r.value.ifBlank { "—" },
fontSize = 26.sp,
fontWeight = FontWeight.Medium,
color = Doubao.Blue,
)
"bool" -> {
val yes = r.value.trim().lowercase() in listOf("true", "1", "yes", "真")
Surface(
shape = RoundedCornerShape(8.dp),
color = (if (yes) Color(0xFF34A853) else Color(0xFFEA4335)).copy(alpha = 0.14f),
) {
Text(
if (yes) "真" else "假",
fontSize = 20.sp,
fontWeight = FontWeight.Medium,
color = if (yes) Color(0xFF34A853) else Color(0xFFEA4335),
modifier = Modifier.padding(horizontal = 14.dp, vertical = 4.dp),
)
}
}
"list" -> {
val items = runCatching {
val arr = JSONArray(r.value.ifBlank { "[]" })
(0 until arr.length()).map { arr.optString(it) }
}.getOrElse { emptyList() }
if (items.isEmpty()) {
Text("(空列表)", fontSize = 13.sp, color = doubaoTextSecondary())
} else {
Column {
items.forEachIndexed { i, item ->
Row(Modifier.padding(vertical = 2.dp)) {
Text(
"${i + 1}.",
fontSize = 12.sp,
color = Doubao.Blue,
modifier = Modifier.width(22.dp),
)
Text(item, fontSize = 13.sp, color = doubaoText(), lineHeight = 19.sp)
}
}
Spacer(Modifier.height(4.dp))
Text(
"共 ${items.size} 项",
fontSize = 11.sp,
color = doubaoTextSecondary(),
)
}
}
}
else -> Text(
r.value.ifBlank { "(没有输出)" },
fontSize = 13.sp,
color = doubaoText(),
lineHeight = 19.sp,
)
}
}
/**
* 最终输出面板:多个输出用**标签页**切换。
*
* ★ 用户要求:"结果界面做个最终输出的标签页,最终结果可以是多个(用标签页形式
* 展现),可以是任意类型,不同类型的最终结果展现方式不同。"
*/
@Composable
private fun ResultsPanel(results: List<MeetingResult>) {
if (results.isEmpty()) return
var tab by remember(results) { mutableStateOf(0) }
val idx = tab.coerceIn(0, results.size - 1)
Column(Modifier.fillMaxWidth()) {
if (results.size > 1) {
// 多个输出才需要标签页;只有一个就直接展示,省一行
Row(
Modifier
.fillMaxWidth()
.horizontalScroll(rememberScrollState()),
) {
results.forEachIndexed { i, r ->
val on = i == idx
Text(
r.title.ifBlank { "输出 ${i + 1}" },
fontSize = 13.sp,
color = if (on) Color.White else doubaoTextSecondary(),
fontWeight = if (on) FontWeight.Medium else FontWeight.Normal,
modifier = Modifier
.padding(end = 8.dp)
.clip(RoundedCornerShape(8.dp))
.background(if (on) Doubao.Blue else Doubao.Blue.copy(alpha = 0.08f))
.clickable { tab = i }
.padding(horizontal = 12.dp, vertical = 6.dp),
)
}
}
Spacer(Modifier.height(10.dp))
}
val cur = results[idx]
Surface(
shape = RoundedCornerShape(10.dp),
color = Doubao.Blue.copy(alpha = 0.05f),
modifier = Modifier.fillMaxWidth(),
) {
Column(Modifier.padding(12.dp)) {
Text(
cur.title.ifBlank { "最终输出" } + "(${typeLabel(cur.type)})",
fontSize = 11.sp,
color = Doubao.Blue,
)
Spacer(Modifier.height(6.dp))
ResultValueView(cur)
}
}
}
}
/** 连线种类的中文名(选中提示里用) */
private fun kindLabel(kind: String): String = when (kind) {
"exec" -> "执行线"
@@ -1910,6 +2045,8 @@ private fun MeetingResultScreen(
liveOutputs: Map<String, String>,
/** 本次运行的**运行链**:按执行顺序记的 (节点id, 标题, 第几轮) */
liveTrace: List<TraceStep>,
/** 本次的最终输出(多个 / 任意类型) */
liveResults: List<com.doubao.lynxclone.data.MeetingResult>,
onBack: () -> Unit,
) {
var runs by remember { mutableStateOf<List<MeetingRun>>(emptyList()) }
@@ -2242,6 +2379,11 @@ if (liveTrace.isEmpty() && runs.isNotEmpty()) expanded = 0
)
if (open) {
Spacer(Modifier.height(8.dp))
// ★ 这一次的最终输出(可能有多个、类型各不相同)
if (run.results.isNotEmpty()) {
ResultsPanel(run.results)
Spacer(Modifier.height(12.dp))
}
// ★ **运行链**:按执行顺序把每一步的结果列出来。
//
// 不是"节点状态一览",而是"这条链是怎么一步步走下来的"——

View File

@@ -979,8 +979,14 @@ class KernelHandler(BaseHTTPRequestHandler):
parts.append('【输出要求】\n' + control)
# 变量说明拼在最后:它和"输出要求"一样是这一轮的约束,
# 但放在更后面,模型对"最后看到的东西"注意力更高
# 变量登记表里的**类型和描述**也一起给模型:
# 光有变量名,模型只能猜"这个 isRun 是次数还是个开关"。
var_meta = {
v.get('name'): {'type': v.get('type'), 'note': v.get('note')}
for v in ((item or {}).get('vars') or [])
}
var_text = meeting.variables_prompt(
variables, node.get('readVars'), node.get('writeVars'))
variables, node.get('readVars'), node.get('writeVars'), var_meta)
if var_text:
parts.append(var_text)
merged_agent = {**(agent or {}), 'systemPrompt': '\n\n'.join(parts)}
@@ -1057,6 +1063,8 @@ class KernelHandler(BaseHTTPRequestHandler):
final['output'] = event.get('output') or ''
final['aborted'] = bool(event.get('aborted'))
final['error'] = event.get('error') or ''
# 多个最终输出(结果界面按标签页展示)
final['results'] = event.get('results') or []
meeting.run_meeting(
meeting=item,
@@ -1077,6 +1085,7 @@ class KernelHandler(BaseHTTPRequestHandler):
'at': datetime.now(timezone.utc).isoformat().replace('+00:00', 'Z'),
'input': user_input,
'steps': steps,
'results': final.get('results') or [],
'output': final['output'],
'aborted': final['aborted'],
'error': final['error'],

View File

@@ -1,3 +1,4 @@
import json
"""会议模式:用「节点 + 连线」把多个智能体串成一条流水线。
和普通对话的区别:
@@ -67,6 +68,49 @@ CAST_KINDS = (
)
# (键, 名字, 输入类型, 输出类型, 要几个输入)
# --------------------------------------------------------------------------- #
# 列表
# --------------------------------------------------------------------------- #
#
# 列表就存成一个 JSON 数组的文本(`["a","b"]`)。
# **只支持追加和清除** —— 不做删除/插入/排序:列表在会议里的用途是"攒东西"
# (攒一轮轮的产出、攒要点),要精确编辑的场合本来就该用变量或智能体。
# 少一套操作 = 少一类出错方式,而且**给模型看的时候天然就是 JSON**
# (用户要的"列表类输入到模型以 json 方式展现",存成 JSON 就自动满足了)。
def list_parse(value) -> list:
"""把值解析成列表。不是合法 JSON 数组就当空列表。"""
text = str(value or '').strip()
if not text:
return []
try:
data = json.loads(text)
except (ValueError, TypeError):
return []
return data if isinstance(data, list) else []
def list_dump(items: list) -> str:
"""列表存回文本。ensure_ascii=False 让中文原样留着,模型读起来更自然。"""
return json.dumps(items, ensure_ascii=False)
def list_render(value) -> str:
"""
给模型看的形态:缩进好的 JSON。
空列表给个明确的 `[]`,而不是空字符串 —— 让模型知道"这是个空列表",
而不是"这里什么都没有"。
"""
return json.dumps(list_parse(value), ensure_ascii=False, indent=2)
# 列表运算(键, 名字, 要几个输入)
LIST_OPS = (
('append', '追加', 2),
('clear', '清除', 1),
)
OPS = (
('add', '加 +', 'num', 'num', 2),
('sub', '减 −', 'num', 'num', 2),
@@ -80,6 +124,8 @@ OPS = (
('lt', '小于 <', 'num', 'bool', 2),
('neg', '取反(负号)', 'num', 'num', 1),
('not', '逻辑非 !', 'bool', 'bool', 1),
('append', '追加到列表', 'list', 'list', 2),
('clear', '清空列表', 'list', 'list', 1),
)
_OPS_BY_KEY = {o[0]: o for o in OPS}
@@ -99,6 +145,19 @@ def cast_value(value, target: str) -> str:
→ bool:0 / 空 / false / no / off → 'false',其他 → 'true'
→ num :能解析就取数(去掉多余小数位),不能解析就 0
"""
if target == 'list':
# 转列表:本来就是列表就原样;是 JSON 数组文本也认;其他情况
# 当"单个元素"包成一项 —— 比丢掉好,用户能看见东西还在
text = str(value or '').strip()
if not text:
return list_dump([])
try:
data = json.loads(text)
if isinstance(data, list):
return list_dump(data)
except (ValueError, TypeError):
pass
return list_dump([text])
if target == 'bool':
return 'true' if truthy(value) else 'false'
if target == 'num':
@@ -128,6 +187,14 @@ def apply_op(op_key: str, a, b=None):
except (TypeError, ValueError):
return 0.0, f'「{str(v)[:20]}」不是数字'
# ---- 列表:只支持追加和清除 ----
if op_key == 'append':
items = list_parse(a)
items.append(b)
return list_dump(items), ''
if op_key == 'clear':
return list_dump([]), ''
if arity == 1:
if op_key == 'neg':
n, err = as_num(a)
@@ -274,28 +341,57 @@ def apply_sets(text: str, variables: dict, allowed) -> tuple:
return cleaned, changed
def variables_prompt(variables: dict, read_names, write_names) -> str:
def variables_prompt(variables: dict, read_names, write_names,
var_meta: dict = None) -> str:
"""
给智能体拼一段"你能看到哪些变量、能改哪些"的说明。
只读的不列写法说明,只写的不列当前值 —— 权限边界写清楚,
模型才不会去猜"我能不能改这个"。
★ var_meta:变量名 → {type, note},**描述位也要给智能体看** ——
光有变量名,模型只能靠猜"这个 isRun 到底是次数还是个开关"。
用户在变量表里写的描述本来就是给模型看的上下文,不给它等于白写。
★ 列表按 JSON 展开,并说明"只支持整体写入" ——
免得模型去写 [[SET x=...]] 想做删除/排序(列表只支持追加和清除)。
"""
reads = [n for n in (read_names or []) if n]
writes = [n for n in (write_names or []) if n]
if not reads and not writes:
return ''
meta = var_meta or {}
def describe(name: str) -> str:
info = meta.get(name) or {}
bits = []
vtype = str(info.get('type') or '')
if vtype:
bits.append({'list': '列表', 'num': '数字', 'bool': '真假'}.get(vtype, '文本'))
note = str(info.get('note') or '').strip()
if note:
bits.append(note)
return f'({",".join(bits)})' if bits else ''
parts = []
if reads:
lines = [f'- {n} = {variables.get(n, "(还没设过)")}' for n in reads]
lines = []
for n in reads:
value = variables.get(n, '(还没设过)')
if str((meta.get(n) or {}).get('type') or '') == 'list':
value = list_render(value)
lines.append(f'- {n} = {value} {describe(n)}'.rstrip())
parts.append('【你可以看到的变量】\n' + '\n'.join(lines))
if writes:
parts.append(
'【你可以修改的变量】' + '、'.join(writes) + '\n'
'【你可以修改的变量】'
+ '、'.join(n + describe(n) for n in writes) + '\n'
'要修改变量时,在回答的**最后**单独起一行写:\n'
'[[SET 变量名=新值]]\n'
'这一行不会显示给用户,会被系统取走并写入变量。'
'不需要修改就不要写这一行。'
'不需要修改就不要写这一行。\n'
'列表类型的变量只能**整体写入**一个 JSON 数组'
'(想追加就把原内容加一项再整体写回)。'
)
return '\n\n'.join(parts)
@@ -570,7 +666,8 @@ NODE_DATA_IN = {
# 写变量是汇:什么都能存(存进去的都是文本,读的时候按变量类型解释)
'var': ('str', 'bool', 'num'),
'while': ('bool',),
'end': ('str',),
# 最终输出只是展示,什么类型都能接(展示方式按类型不同)
'end': ('str', 'bool', 'num', 'list'),
# 转换:什么都收,出口由 castTo 决定
'cast': ('str', 'bool', 'num'),
# 运算:入口类型由运算本身决定(见 _data_in_type)
@@ -756,7 +853,7 @@ EXEC = 'exec'
DATA = 'data'
# 数据引脚的类型。和蓝图一样是**强类型**的:连错类型直接接不上。
PIN_TYPES = ('str', 'bool', 'num')
PIN_TYPES = ('str', 'bool', 'num', 'list')
# 老会议里没有 kind 的边当 exec —— 它们仍然负责"跑的顺序",
# 但**不再顺带传数据**。想传值就得画数据线(界面上现在很好画了)。
@@ -1038,6 +1135,8 @@ def run_meeting(*, meeting: dict, settings: dict, user_input: str,
max_steps = max(20, budget * 2 + len(nodes))
final_output = ''
# 所有 end 节点的产出(结果界面按标签页展示)
results = []
def can_run(node_id: str) -> bool:
node = by_id.get(node_id)
@@ -1362,8 +1461,20 @@ def run_meeting(*, meeting: dict, settings: dict, user_input: str,
})
elif node_type == 'end':
outputs[node_id] = (node.get('text') or '').strip() or incoming
final_output = outputs[node_id]
# ★ 最终输出可以有**多个**(结果界面用标签页展示),每个还能是不同类型、
# 展示方式不同。所以每个 end 节点都把自己那份结果和类型记下来。
value = (node.get('text') or '').strip() or incoming
outputs[node_id] = value
# 类型取数据入线的类型;没有数据线就按文本
kinds = [_kind(e) for e in _data_in(edges, node_id)]
rtype = kinds[0] if kinds else 'str'
final_output = value
results.append({
'nodeId': node_id,
'title': node.get('title') or '最终输出',
'type': rtype,
'value': value,
})
emit({'type': 'node_done', 'nodeId': node_id, 'nodeType': node_type, 'output': final_output, 'run': run_index})
next_ids = []
@@ -1393,5 +1504,5 @@ def run_meeting(*, meeting: dict, settings: dict, user_input: str,
emit({'type': 'meeting_done', 'output': final_output, 'aborted': True})
return {'output': final_output, 'aborted': True}
emit({'type': 'meeting_done', 'output': final_output})
return {'output': final_output}
emit({'type': 'meeting_done', 'output': final_output, 'results': results})
return {'output': final_output, 'results': results}