Skip to content

Commit 0b05456

Browse files
committed
feat: update agent framework with new termination modes and enhance event visualization
- Updated agent termination mode count from 5 to 6 - Renamed SubagentTerminateMode to AgentTerminateMode and added new ABORTED and ERROR_NO_COMPLETE_TASK_CALL modes - Updated documentation and UI to reflect new termination modes - Modified HookEventAnimation to show 11 event types with enhanced visual grouping - Added BeforeAgent, AfterAgent, and Notification event types to visualization - Adjusted grid layout for better event type display in HookEventAnimation
1 parent 5724535 commit 0b05456

4 files changed

Lines changed: 40 additions & 15 deletions

File tree

src/pages/AgentFramework.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function QuickSummary({ isExpanded, onToggle }: { isExpanded: boolean; onToggle:
4545
<div className="text-xs text-[var(--text-muted)]">Agent 类型</div>
4646
</div>
4747
<div className="bg-[var(--bg-card)] rounded-lg p-3 text-center border border-[var(--border-subtle)]">
48-
<div className="text-2xl font-bold text-[var(--terminal-green)]">5</div>
48+
<div className="text-2xl font-bold text-[var(--terminal-green)]">6</div>
4949
<div className="text-xs text-[var(--text-muted)]">终止模式</div>
5050
</div>
5151
<div className="bg-[var(--bg-card)] rounded-lg p-3 text-center border border-[var(--border-subtle)]">
@@ -156,13 +156,14 @@ export function AgentFramework() {
156156
style TURN fill:#1a1a2e,stroke:#00d4ff,stroke-width:2px`;
157157

158158
const agentTypesCode = `// Agent 终止模式
159-
// packages/core/src/subagents/types.ts:172-193
160-
export enum SubagentTerminateMode {
159+
// packages/core/src/agents/types.ts
160+
export enum AgentTerminateMode {
161161
ERROR = 'ERROR', // 执行错误
162162
TIMEOUT = 'TIMEOUT', // 超时
163163
GOAL = 'GOAL', // 成功完成
164164
MAX_TURNS = 'MAX_TURNS', // 达到轮次上限
165-
CANCELLED = 'CANCELLED', // 被取消
165+
ABORTED = 'ABORTED', // 外部中止信号
166+
ERROR_NO_COMPLETE_TASK_CALL = 'ERROR_NO_COMPLETE_TASK_CALL', // 未调用 complete_task
166167
}
167168
168169
// 基础 Agent 定义
@@ -855,8 +856,13 @@ this.emitActivity('ERROR', { error: errorMessage, context: 'tool_call' });`;
855856
<td className="py-2 px-3 text-red-400"></td>
856857
</tr>
857858
<tr className="border-b border-[var(--border-subtle)]/50">
858-
<td className="py-2 px-3 text-red-400 font-bold">CANCELLED</td>
859-
<td className="py-2 px-3 text-[var(--text-secondary)]">用户取消 (AbortSignal)</td>
859+
<td className="py-2 px-3 text-red-400 font-bold">ABORTED</td>
860+
<td className="py-2 px-3 text-[var(--text-secondary)]">外部中止信号 (AbortSignal)</td>
861+
<td className="py-2 px-3 text-red-400"></td>
862+
</tr>
863+
<tr className="border-b border-[var(--border-subtle)]/50">
864+
<td className="py-2 px-3 text-red-400 font-bold">ERROR_NO_COMPLETE_TASK_CALL</td>
865+
<td className="py-2 px-3 text-[var(--text-secondary)]">停止调用工具但未调用 complete_task</td>
860866
<td className="py-2 px-3 text-red-400"></td>
861867
</tr>
862868
</tbody>

src/pages/HookEventAnimation.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,18 @@ function Introduction({ isExpanded, onToggle }: { isExpanded: boolean; onToggle:
5656

5757
<div className="bg-[var(--bg-terminal)]/50 rounded-lg p-4 border-l-4 border-[var(--cyber-blue)]">
5858
<h4 className="text-[var(--cyber-blue)] font-bold mb-2">🔧 11 种事件类型</h4>
59-
<div className="grid grid-cols-2 md:grid-cols-4 gap-2 mt-2 text-xs">
59+
<div className="grid grid-cols-3 md:grid-cols-4 gap-2 mt-2 text-xs">
6060
<div className="bg-[var(--bg-card)] p-2 rounded text-center text-[var(--terminal-green)]">BeforeTool</div>
6161
<div className="bg-[var(--bg-card)] p-2 rounded text-center text-[var(--terminal-green)]">AfterTool</div>
62+
<div className="bg-[var(--bg-card)] p-2 rounded text-center text-cyan-400">BeforeAgent</div>
63+
<div className="bg-[var(--bg-card)] p-2 rounded text-center text-cyan-400">AfterAgent</div>
6264
<div className="bg-[var(--bg-card)] p-2 rounded text-center text-[var(--cyber-blue)]">BeforeModel</div>
6365
<div className="bg-[var(--bg-card)] p-2 rounded text-center text-[var(--cyber-blue)]">AfterModel</div>
6466
<div className="bg-[var(--bg-card)] p-2 rounded text-center text-[var(--amber)]">SessionStart</div>
6567
<div className="bg-[var(--bg-card)] p-2 rounded text-center text-[var(--amber)]">SessionEnd</div>
6668
<div className="bg-[var(--bg-card)] p-2 rounded text-center text-[var(--purple)]">PreCompress</div>
6769
<div className="bg-[var(--bg-card)] p-2 rounded text-center text-[var(--purple)]">BeforeToolSelection</div>
70+
<div className="bg-[var(--bg-card)] p-2 rounded text-center text-orange-400">Notification</div>
6871
</div>
6972
</div>
7073

src/pages/ToolSchedulerDetails.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ private async checkAndNotifyCompletion(): Promise<void> {
417417
}
418418
}`;
419419

420-
const toolCallStatusCode = `// packages/core/src/core/coreToolScheduler.ts:46-123
420+
const toolCallStatusCode = `// packages/core/src/scheduler/types.ts:38-115
421421
422422
// 工具调用状态类型定义
423423
export type ValidatingToolCall = {
@@ -453,7 +453,7 @@ export type ExecutingToolCall = {
453453
request: ToolCallRequestInfo;
454454
tool: AnyDeclarativeTool;
455455
invocation: AnyToolInvocation;
456-
liveOutput?: ToolResultDisplay; // 实时输出
456+
liveOutput?: string | AnsiOutput; // 实时输出(ANSI 格式)
457457
startTime?: number;
458458
outcome?: ToolConfirmationOutcome;
459459
pid?: number; // 进程 ID (Shell 工具)

src/pages/TurnStateMachine.tsx

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function Introduction({
8080
<h4 className="text-green-400 font-bold mb-2">📊 关键数字</h4>
8181
<div className="grid grid-cols-2 md:grid-cols-4 gap-3">
8282
<div className="text-center">
83-
<div className="text-xl font-bold text-purple-400">14</div>
83+
<div className="text-xl font-bold text-purple-400">17</div>
8484
<div className="text-xs text-gray-500">事件类型</div>
8585
</div>
8686
<div className="text-center">
@@ -213,12 +213,28 @@ function EventTypesSection() {
213213
example: '{ type: "max_session_turns" }',
214214
},
215215
{
216-
type: 'SessionTokenLimitExceeded',
217-
icon: '📈',
216+
type: 'ContextWindowWillOverflow',
217+
icon: '⚠️',
218+
color: 'amber',
219+
description: '上下文窗口即将溢出',
220+
when: 'Token 数接近模型上限时',
221+
example: '{ type: "context_window_will_overflow" }',
222+
},
223+
{
224+
type: 'InvalidStream',
225+
icon: '🚫',
218226
color: 'red',
219-
description: '超过会话 Token 限制',
220-
when: 'totalTokens > sessionTokenLimit 时',
221-
example: '{ type: "session_token_limit_exceeded", value: { currentTokens: 150000, limit: 100000 } }',
227+
description: '无效的流数据',
228+
when: '流解析失败或格式错误时',
229+
example: '{ type: "invalid_stream" }',
230+
},
231+
{
232+
type: 'ModelInfo',
233+
icon: 'ℹ️',
234+
color: 'blue',
235+
description: '返回当前模型信息',
236+
when: '获取模型元数据时',
237+
example: '{ type: "model_info", value: { model: "gemini-pro", ... } }',
222238
},
223239
];
224240

0 commit comments

Comments
 (0)