MCPcopy
hub / github.com/lobehub/lobehub / BlockingAgent

Class BlockingAgent

packages/agent-runtime/src/core/__tests__/runtime.test.ts:1346–1384  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1344 it('should stop execution when encountering blocking status', async () => {
1345 // Agent that returns mixed instructions with approval
1346 class BlockingAgent implements Agent {
1347 tools = {
1348 safe_tool: vi.fn().mockResolvedValue({ result: 'safe_result' }),
1349 };
1350
1351 async runner(context: AgentRuntimeContext, _state: AgentState) {
1352 if (context.phase === 'user_input') {
1353 // Return array: safe tool + approval request
1354 return [
1355 {
1356 payload: {
1357 parentMessageId: 'user-msg-id',
1358 toolCalling: {
1359 id: 'call_safe',
1360 type: 'default' as const,
1361 apiName: 'safe_tool',
1362 identifier: 'safe_tool',
1363 arguments: '{}',
1364 },
1365 },
1366 type: 'call_tool' as const,
1367 },
1368 {
1369 pendingToolsCalling: [
1370 {
1371 apiName: 'danger_tool',
1372 arguments: '{}',
1373 id: 'call_danger',
1374 identifier: 'danger_tool',
1375 type: 'default' as const,
1376 },
1377 ],
1378 type: 'request_human_approve' as const,
1379 },
1380 ];
1381 }
1382 return { type: 'finish' as const, reason: 'completed' as const };
1383 }
1384 }
1385
1386 const agent = new BlockingAgent();
1387 const runtime = new AgentRuntime(agent);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected