Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat(codex): add collab tool render (#15662)

Arvin Xufdd955404d8c
diff --git a/locales/en-US/plugin.json b/locales/en-US/plugin.json
index 179c28f09e7..51591eb0475 100644
--- a/locales/en-US/plugin.json
+++ b/locales/en-US/plugin.json
@@ -1,11 +1,21 @@
{
"arguments.moreParams": "{{count}} params in total",
"arguments.title": "Arguments",
+ "builtins.codex.apiName.collab_tool_call": "Coordinate subagents",
"builtins.codex.apiName.command_execution": "Run command",
"builtins.codex.apiName.file_change": "Edit files",
"builtins.codex.apiName.mcp_tool_call": "Call MCP tool",
"builtins.codex.apiName.todo_list": "Update tasks",
"builtins.codex.apiName.web_search": "Search the web",
+ "builtins.codex.collabTool.agentCount_one": "{{count}} subagent",
+ "builtins.codex.collabTool.agentCount_other": "{{count}} subagents",
+ "builtins.codex.collabTool.agentLabel": "Subagent {{index}}",
+ "builtins.codex.collabTool.agents": "Subagents",
+ "builtins.codex.collabTool.closeAgent": "Close subagent",
+ "builtins.codex.collabTool.instruction": "Instruction",
+ "builtins.codex.collabTool.sendInput": "Message subagent",
+ "builtins.codex.collabTool.spawnAgent": "Spawn subagent",
+ "builtins.codex.collabTool.wait": "Wait for subagents",
"builtins.codex.commandExecution.grep": "Search",
"builtins.codex.commandExecution.noResults": "No results",
"builtins.codex.commandExecution.readFile": "Read file",
diff --git a/locales/zh-CN/plugin.json b/locales/zh-CN/plugin.json
index b984850702d..ab7e8c82ba2 100644
--- a/locales/zh-CN/plugin.json
+++ b/locales/zh-CN/plugin.json
@@ -1,11 +1,21 @@
{
"arguments.moreParams": "等 {{count}} 个参数",
"arguments.title": "参数列表",
+ "builtins.codex.apiName.collab_tool_call": "协调子代理",
"builtins.codex.apiName.command_execution": "运行命令",
"builtins.codex.apiName.file_change": "编辑文件",
"builtins.codex.apiName.mcp_tool_call": "调用 MCP 工具",
"builtins.codex.apiName.todo_list": "更新任务",
"builtins.codex.apiName.web_search": "搜索网页",
+ "builtins.codex.collabTool.agentCount_one": "{{count}} 个子代理",
+ "builtins.codex.collabTool.agentCount_other": "{{count}} 个子代理",
+ "builtins.codex.collabTool.agentLabel": "子代理 {{index}}",
+ "builtins.codex.collabTool.agents": "子代理",
+ "builtins.codex.collabTool.closeAgent": "关闭子代理",
+ "builtins.codex.collabTool.instruction": "指令",
+ "builtins.codex.collabTool.sendInput": "发送消息给子代理",
+ "builtins.codex.collabTool.spawnAgent": "启动子代理",
+ "builtins.codex.collabTool.wait": "等待子代理",
"builtins.codex.commandExecution.grep": "搜索",
"builtins.codex.commandExecution.noResults": "没有结果",
"builtins.codex.commandExecution.readFile": "读取文件",
diff --git a/packages/builtin-tools/src/codex/CollabToolInspector.tsx b/packages/builtin-tools/src/codex/CollabToolInspector.tsx
new file mode 100644
index 00000000000..cac57b069ac
--- /dev/null
+++ b/packages/builtin-tools/src/codex/CollabToolInspector.tsx
@@ -0,0 +1,76 @@
+'use client';
+
+import {
+ highlightTextStyles,
+ inspectorTextStyles,
+ shinyTextStyles,
+} from '@lobechat/shared-tool-ui/styles';
+import type { BuiltinInspectorProps } from '@lobechat/types';
+import { cx } from 'antd-style';
+import type { TFunction } from 'i18next';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import type { CodexCollabToolArgs, CodexCollabToolState } from './collabToolUtils';
+import { getCollabAgentCount, getCollabPrompt, getCollabToolName } from './collabToolUtils';
+
+const getToolLabel = (t: TFunction<'plugin'>, toolName: string) => {
+ switch (toolName) {
+ case 'close_agent': {
+ return t('builtins.codex.collabTool.closeAgent', { defaultValue: 'Close subagent' });
+ }
+ case 'send_input': {
+ return t('builtins.codex.collabTool.sendInput', { defaultValue: 'Message subagent' });
+ }
+ case 'spawn_agent': {
+ return t('builtins.codex.collabTool.spawnAgent', { defaultValue: 'Spawn subagent' });
+ }
+ case 'wait': {
+ return t('builtins.codex.collabTool.wait', { defaultValue: 'Wait for subagents' });
+ }
+ default: {
+ return t('builtins.codex.apiName.collab_tool_call', {
+ defaultValue: 'Coordinate subagents',
+ });
+ }
+ }
+};
+
+const CollabToolInspector = memo<BuiltinInspectorProps<CodexCollabToolArgs, CodexCollabToolState>>(
+ ({ args, partialArgs, isArgumentsStreaming, isLoading, pluginState }) => {
+ const { t } = useTranslation('plugin');
+ const toolName = getCollabToolName(args, pluginState) || getCollabToolName(partialArgs);
+ const label = getToolLabel(t, toolName);
+
+ const prompt = getCollabPrompt(args, pluginState) || getCollabPrompt(partialArgs);
+ const agentCount = getCollabAgentCount(args, pluginState);
+ const target =
+ prompt.split('\n')[0].trim() ||
+ (agentCount > 0 ? t('builtins.codex.collabTool.agentCount', { count: agentCount }) : '');
+
+ if (isArgumentsStreaming && !target) {
+ return <div className={cx(inspectorTextStyles.root, shinyTextStyles.shinyText)}>{label}</div>;
+ }
+
+ return (
+ <div
+ className={cx(
+ inspectorTextStyles.root,
+ (isArgumentsStreaming || isLoading) && shinyTextStyles.shinyText,
+ )}
+ >
+ <span>{label}</span>
+ {target && (
+ <>
+ <span>: </span>
+ <span className={highlightTextStyles.primary}>{target}</span>
+ </>
+ )}
+ </div>
+ );
+ },
+);
+
+CollabToolInspector.displayName = 'CodexCollabToolInspector';
+
+export default CollabToolInspector;
diff --git a/packages/builtin-tools/src/codex/CollabToolRender.tsx b/packages/builtin-tools/src/codex/CollabToolRender.tsx
new file mode 100644
index 00000000000..5f2155d65d2
--- /dev/null
+++ b/packages/builtin-tools/src/codex/CollabToolRender.tsx
@@ -0,0 +1,128 @@
+'use client';
+
+import type { BuiltinRenderProps } from '@lobechat/types';
+import { Flexbox, Markdown, Text } from '@lobehub/ui';
+import { createStaticStyles, cx } from 'antd-style';
+import { memo } from 'react';
+import { useTranslation } from 'react-i18next';
+
+import type { CodexCollabToolArgs, CodexCollabToolState } from './collabToolUtils';
+import {
+ formatCollabStatus,
+ getCollabAgentEntries,
+ getCollabPrompt,
+ getCollabStatusTone,
+} from './collabToolUtils';
+
+const styles = createStaticStyles(({ css, cssVar }) => ({
+ agentHeader: css`
+ font-size: 12px;
+ color: ${cssVar.colorTextSecondary};
+ `,
+ agentRow: css`
+ padding-block: 8px;
+ padding-inline: 12px;
+ border-radius: ${cssVar.borderRadiusLG};
+ background: ${cssVar.colorFillQuaternary};
+ `,
+ promptBox: css`
+ padding-block: 8px;
+ padding-inline: 12px;
+ border-radius: ${cssVar.borderRadiusLG};
+ background: ${cssVar.colorFillTertiary};
+ `,
+ sectionLabel: css`
+ margin-block-end: 4px;
+ font-size: 12px;
+ color: ${cssVar.colorTextSecondary};
+ `,
+ statusDot: css`
+ flex: none;
+
+ width: 6px;
+ height: 6px;
+ border-radius: 50%;
+
+ background: ${cssVar.colorTextQuaternary};
+ `,
+ statusDotError: css`
+ background: ${cssVar.colorError};
+ `,
+ statusDotProcessing: css`
+ background: ${cssVar.colorInfo};
+ `,
+ statusDotSuccess: css`
+ background: ${cssVar.colorSuccess};
+ `,
+}));
+
+const STATUS_DOT_CLASS = {
+ error: styles.statusDotError,
+ muted: undefined,
+ processing: styles.statusDotProcessing,
+ success: styles.statusDotSuccess,
+};
+
+const CollabToolRender = memo<
+ BuiltinRenderProps<CodexCollabToolArgs, CodexCollabToolState, string>
+>(({ args, pluginState }) => {
+ const { t } = useTranslation('plugin');
+ const prompt = getCollabPrompt(args, pluginState);
+ const agents = getCollabAgentEntries(args, pluginState);
+
+ if (!prompt && agents.length === 0) return null;
+
+ return (
+ <Flexbox gap={12}>
+ {prompt && (
+ <div>
+ <Text className={styles.sectionLabel}>
+ {t('builtins.codex.collabTool.instruction', { defaultValue: 'Instruction' })}
+ </Text>
+ <Flexbox className={styles.promptBox}>
+ <Markdown style={{ maxHeight: 240, overflow: 'auto' }} variant={'chat'}>
+ {prompt}
+ </Markdown>
+ </Flexbox>
+ </div>
+ )}
+ {agents.length > 0 && (
+ <div>
+ <Text className={styles.sectionLabel}>
+ {t('builtins.codex.collabTool.agents', { defaultValue: 'Subagents' })}
+ </Text>
+ <Flexbox gap={8}>
+ {agents.map((agent, index) => (
+ <Flexbox className={styles.agentRow} gap={4} key={agent.id}>
+ <Flexbox horizontal align={'center'} className={styles.agentHeader} gap={6}>
+ <span
+ className={cx(
+ styles.statusDot,
+ STATUS_DOT_CLASS[getCollabStatusTone(agent.status)],
+ )}
+ />
+ <span>
+ {t('builtins.codex.collabTool.agentLabel', {
+ defaultValue: 'Subagent {{index}}',
+ index: index + 1,
+ })}
+ </span>
+ {agent.status && <span>· {formatCollabStatus(agent.status)}</span>}
+ </Flexbox>
+ {agent.message && (
+ <Markdown style={{ maxHeight: 320, overflow: 'auto' }} variant={'chat'}>
+ {agent.message}
+ </Markdown>
+ )}
+ </Flexbox>
+ ))}
+ </Flexbox>
+ </div>
+ )}
+ </Flexbox>
+ );
+});
+
+CollabToolRender.displayName = 'CodexCollabToolRender';
+
+export default CollabToolRender;
diff --git a/packages/builtin-tools/src/codex/collabToolUtils.test.ts b/packages/builtin-tools/src/codex/collabToolUtils.test.ts
new file mode 100644
index 00000000000..5843de95e63
--- /dev/null
+++ b/packages/builtin-tools/src/codex/collabToolUtils.test.ts
@@ -0,0 +1,98 @@
+import { describe, expect, it } from 'vitest';
+
+import {
+ formatCollabStatus,
+ getCollabAgentEntries,
+ getCollabPrompt,
+ getCollabStatusTone,
+ getCollabToolName,
+} from './collabToolUtils';
+
+const spawnArgs = {
+ agents_states: {},
+ prompt: 'Return a single short line stating what 2 + 2 equals.',
+ receiver_thread_ids: [],
+ sender_thread_id: 'thread_parent',
+ status: 'in_progress',
+ tool: 'spawn_agent',
+};
+
+const waitState = {
+ agents_states: {
+ thread_a: { message: '2 + 2 = 4', status: 'completed' },
+ },
+ prompt: null,
+ receiver_thread_ids: ['thread_a'],
+ sender_thread_id: 'thread_parent',
+ status: 'completed',
+ tool: 'wait',
+};
+
+describe('getCollabToolName', () => {
+ it('prefers the result state over call args', () => {
+ expect(getCollabToolName(spawnArgs, waitState)).toBe('wait');
+ expect(getCollabToolName(spawnArgs)).toBe('spawn_agent');
+ expect(getCollabToolName()).toBe('');
+ });
+});
+
+describe('getCollabPrompt', () => {
+ it('falls back to args when the state prompt is null', () => {
+ expect(getCollabPrompt(spawnArgs, waitState)).toBe(spawnArgs.prompt);
+ expect(getCollabPrompt(undefined, waitState)).toBe('');
+ });
+});
+
+describe('getCollabAgentEntries', () => {
+ it('reads final agent states from the result state', () => {
+ expect(getCollabAgentEntries(spawnArgs, waitState)).toEqual([
+ { id: 'thread_a', message: '2 + 2 = 4', status: 'completed' },
+ ]);
+ });
+
+ it('orders by receiver_thread_ids and appends extra state keys', () => {
+ const entries = getCollabAgentEntries(undefined, {
+ agents_states: {
+ thread_b: { message: null, status: 'pending_init' },
+ thread_extra: { message: 'done', status: 'completed' },
+ },
+ receiver_thread_ids: ['thread_b'],
+ tool: 'spawn_agent',
+ });
+
+ expect(entries.map((entry) => entry.id)).toEqual(['thread_b', 'thread_extra']);
+ expect(entries[0]).toEqual({ id: 'thread_b', message: undefined, status: 'pending_init' });
+ });
+
+ it('falls back to call args when the state has no agents', () => {
+ expect(getCollabAgentEntries(spawnArgs, { agents_states: {}, tool: 'spawn_agent' })).toEqual(
+ [],
+ );
+
+ const argsWithAgents = {
+ ...spawnArgs,
+ agents_states: { thread_c: { message: null, status: 'pending_init' } },
+ receiver_thread_ids: ['thread_c'],
+ };
+ expect(getCollabAgentEntries(argsWithAgents, undefined)).toEqual([
+ { id: 'thread_c', message: undefined, status: 'pending_init' },
+ ]);
+ });
+});
+
+describe('getCollabStatusTone', () => {
+ it('maps codex agent statuses to tones', () => {
+ expect(getCollabStatusTone('completed')).toBe('success');
+ expect(getCollabStatusTone('errored')).toBe('error');
+ expect(getCollabStatusTone('in_progress')).toBe('processing');
+ expect(getCollabStatusTone('pending_init')).toBe('muted');
+ expect(getCollabStatusTone()).toBe('muted');
+ });
+});
+
+describe('formatCollabStatus', () => {
+ it('humanizes snake_case statuses', () => {
+ expect(formatCollabStatus('pending_init')).toBe('pending init');
+ expect(formatCollabStatus()).toBe('');
+ });
+});
diff --git a/packages/builtin-tools/src/codex/collabToolUtils.ts b/packages/builtin-tools/src/codex/collabToolUtils.ts
new file mode 100644
index 00000000000..27960bd2c0d
--- /dev/null
+++ b/packages/builtin-tools/src/codex/collabToolUtils.ts
@@ -0,0 +1,91 @@
+'use client';
+
+export interface CodexCollabAgentState extends Record<string, unknown> {
+ message?: string | null;
+ status?: string;
+}
+
+export interface CodexCollabToolArgs extends Record<string, unknown> {
+ agents_states?: Record<string, CodexCollabAgentState>;
+ prompt?: string | null;
+ receiver_thread_ids?: string[];
+ sender_thread_id?: string;
+ status?: string;
+ tool?: string;
+}
+
+export type CodexCollabToolState = CodexCollabToolArgs;
+
+export interface CollabAgentEntry {
+ id: string;
+ message?: string;
+ status?: string;
+}
+
+export type CollabStatusTone = 'error' | 'muted' | 'processing' | 'success';
+
+const normalizeString = (value: unknown) => (typeof value === 'string' ? value.trim() : '');
+
+export const getCollabToolName = (args?: CodexCollabToolArgs, state?: CodexCollabToolState) =>
+ normalizeString(state?.tool) || normalizeString(args?.tool);
+
+export const getCollabPrompt = (args?: CodexCollabToolArgs, state?: CodexCollabToolState) =>
+ normalizeString(state?.prompt) || normalizeString(args?.prompt);
+
+/**
+ * Final agent states live on the tool result (`state`); the call-time `args`
+ * only carry the initial snapshot (usually empty / `pending_init`). Order
+ * follows `receiver_thread_ids` so agents render in spawn order, with any
+ * extra `agents_states` keys appended after.
+ */
+export const getCollabAgentEntries = (
+ args?: CodexCollabToolArgs,
+ state?: CodexCollabToolState,
+): CollabAgentEntry[] => {
+ const source = state?.agents_states && Object.keys(state.agents_states).length > 0 ? state : args;
+ const agentsStates = source?.agents_states || {};
+ const orderedIds = source?.receiver_thread_ids || [];
+
+ const ids = [
+ ...orderedIds,
+ ...Object.keys(agentsStates).filter((id) => !orderedIds.includes(id)),
+ ];
+
+ return ids.map((id) => {
+ const agentState = agentsStates[id];
+
+ return {
+ id,
+ message: normalizeString(agentState?.message) || undefined,
+ status: normalizeString(agentState?.status) || undefined,
+ };
+ });
+};
+
+export const getCollabAgentCount = (
+ args?: CodexCollabToolArgs,
+ state?: CodexCollabToolState,
+): number => getCollabAgentEntries(args, state).length;
+
+export const getCollabStatusTone = (status?: string): CollabStatusTone => {
+ switch (status) {
+ case 'completed': {
+ return 'success';
+ }
+ case 'cancelled':
+ case 'error':
+ case 'errored':
+ case 'failed': {
+ return 'error';
+ }
+ case 'in_progress':
+ case 'running': {
+ return 'processing';
+ }
+ default: {
+ return 'muted';
+ }
+ }
+};
+
+export const formatCollabStatus = (status?: string) => (status || '').replaceAll('_', ' ');
diff --git a/packages/builtin-tools/src/codex/displayControls.ts b/packages/builtin-tools/src/codex/displayControls.ts
index 8cda8996edf..283c2788e87 100644
--- a/packages/builtin-tools/src/codex/displayControls.ts
+++ b/packages/builtin-tools/src/codex/displayControls.ts
@@ -1,6 +1,7 @@
import type { RenderDisplayControl } from '@lobechat/types';
export const CodexRenderDisplayControls: Record<string, RenderDisplayControl> = {
+ collab_tool_call: 'expand',
command_execution: 'collapsed',
file_change: 'expand',
mcp_tool_call: 'expand',
diff --git a/packages/builtin-tools/src/codex/index.ts b/packages/builtin-tools/src/codex/index.ts
index 371187493b8..c342ef68afc 100644
--- a/packages/builtin-tools/src/codex/index.ts
+++ b/packages/builtin-tools/src/codex/index.ts
@@ -1,5 +1,7 @@
import { type BuiltinInspector, type BuiltinRender } from '@lobechat/types';
+import CollabToolInspector from './CollabToolInspector';
+import CollabToolRender from './CollabToolRender';
import CommandExecutionInspector from './CommandExecutionInspector';
import { CodexRenderDisplayControls } from './displayControls';
import FileChangeInspector from './FileChangeInspector';
@@ -12,6 +14,7 @@ import WebSearchInspector from './WebSearchInspector';
import WebSearchRender from './WebSearchRender';
export const CodexInspectors: Record<string, BuiltinInspector> = {
+ collab_tool_call: CollabToolInspector as BuiltinInspector,
command_execution: CommandExecutionInspector as BuiltinInspector,
file_change: FileChangeInspector as BuiltinInspector,
mcp_tool_call: McpToolInspector as BuiltinInspector,
@@ -20,6 +23,7 @@ export const CodexInspectors: Record<string, BuiltinInspector> = {
};
export const CodexRenders: Record<string, BuiltinRender> = {
+ collab_tool_call: CollabToolRender as BuiltinRender,
file_change: FileChangeRender as BuiltinRender,
mcp_tool_call: McpToolRender as BuiltinRender,
todo_list: TodoListRender as BuiltinRender,
diff --git a/packages/heterogeneous-agents/src/adapters/codex.test.ts b/packages/heterogeneous-agents/src/adapters/codex.test.ts
index 2f1ad2194b7..7825ab6f17a 100644
--- a/packages/heterogeneous-agents/src/adapters/codex.test.ts
+++ b/packages/heterogeneous-agents/src/adapters/codex.test.ts
@@ -654,6 +654,15 @@ describe('CodexAdapter', () => {
}),
expect.objectContaining({
content: 'Wait completed: 2 + 2 = 4',
+ pluginState: expect.objectContaining({
+ agents_states: {
+ '019dba1f-171e-7ae0-8d0d-2c659c15a4f0': {
+ message: '2 + 2 = 4',
+ status: 'completed',
+ },
+ },
+ tool: 'wait',
+ }),
toolCallId: 'item_4',
}),
]),
diff --git a/packages/heterogeneous-agents/src/adapters/codex.ts b/packages/heterogeneous-agents/src/adapters/codex.ts
index a88e6bde05b..b7db39bf364 100644
--- a/packages/heterogeneous-agents/src/adapters/codex.ts
+++ b/packages/heterogeneous-agents/src/adapters/codex.ts
@@ -267,6 +267,15 @@ const synthesizeMcpToolPluginState = (item: CodexMcpToolCallItem) => ({
tool: item.tool,
});
+const synthesizeCollabToolPluginState = (item: CodexCollabToolCallItem) => ({
+ agents_states: item.agents_states,
+ prompt: item.prompt,
+ receiver_thread_ids: item.receiver_thread_ids,
+ sender_thread_id: item.sender_thread_id,
+ status: item.status,
+ tool: item.tool,
+});
+
const pluralize = (count: number, singular: string, plural = `${singular}s`) =>
count === 1 ? singular : plural;
@@ -433,7 +442,9 @@ const getToolResultData = (item: CodexToolItem): ToolResultData => {
? synthesizeFileChangePluginState(item)
: isMcpToolCallItem(item)
? synthesizeMcpToolPluginState(item)
- : undefined;
+ : isCollabToolCallItem(item)
+ ? synthesizeCollabToolPluginState(item)
+ : undefined;
return {
content: output,
diff --git a/packages/locales/src/default/plugin.ts b/packages/locales/src/default/plugin.ts
index de27df99089..0680a37a0ba 100644
--- a/packages/locales/src/default/plugin.ts
+++ b/packages/locales/src/default/plugin.ts
@@ -82,11 +82,21 @@ export default {
'builtins.lobe-claude-code.todoWrite.allDone': 'All tasks completed',
'builtins.lobe-claude-code.todoWrite.currentStep': 'Current step',
'builtins.lobe-claude-code.todoWrite.todos': 'Todos',
+ 'builtins.codex.apiName.collab_tool_call': 'Coordinate subagents',
'builtins.codex.apiName.command_execution': 'Run command',
'builtins.codex.apiName.file_change': 'Edit files',
'builtins.codex.apiName.mcp_tool_call': 'Call MCP tool',
'builtins.codex.apiName.todo_list': 'Update tasks',
'builtins.codex.apiName.web_search': 'Search the web',
+ 'builtins.codex.collabTool.agentCount_one': '{{count}} subagent',
+ 'builtins.codex.collabTool.agentCount_other': '{{count}} subagents',
+ 'builtins.codex.collabTool.agentLabel': 'Subagent {{index}}',
+ 'builtins.codex.collabTool.agents': 'Subagents',
+ 'builtins.codex.collabTool.closeAgent': 'Close subagent',
+ 'builtins.codex.collabTool.instruction': 'Instruction',
+ 'builtins.codex.collabTool.sendInput': 'Message subagent',
+ 'builtins.codex.collabTool.spawnAgent': 'Spawn subagent',
+ 'builtins.codex.collabTool.wait': 'Wait for subagents',
'builtins.codex.commandExecution.grep': 'Search',
'builtins.codex.commandExecution.noResults': 'No results',
'builtins.codex.commandExecution.readFile': 'Read file',