본문으로 건너뛰기

대리인 승인

Agent는 때때로 동일한 것을 요구합니다human-in-the-loop리소스 삭제 또는 긴 프로세스 실행과 같은 민감한 작업을 처리하는 Tool을 호출할 때 Workflow에서 사용되는 감독입니다. Agent 승인을 사용하면 Tool 호출이 실행되기 전에 일시 중지하여 사람이 승인하거나 거부할 수 있도록 하거나, Tool이 스스로 일시 중지되어 사용자에게 추가 컨텍스트를 요청할 수 있습니다.

Agent 승인을 사용해야 하는 경우
Agent 승인을 사용해야 하는 경우에 대한 직접 링크

  • 파괴적이거나 되돌릴 수 없는 행위기록 삭제, 이메일 전송, 결제 처리 등.
  • 비용이 많이 드는 작업인수를 먼저 확인하려는 값비싼 타사 API를 호출하는 것과 같습니다.
  • 조건부 확인Tool이 실행을 시작한 다음 완료하기 전에 사용자가 추가 데이터를 확인하거나 제공해야 함을 발견하는 경우입니다.

빠른 시작
빠른 시작에 대한 직접 링크

Tool에 다음을 표시하십시오.requireApproval: true, then check for the tool-call-approval chunk in the stream to approve or decline:

src/mastra/agents/index.ts
import { Agent } from '@mastra/core/agent'
import { createTool } from '@mastra/core/tools'
import { z } from 'zod'

const deleteTool = createTool({
id: 'delete-record',
description: 'Delete a record by ID',
inputSchema: z.object({ id: z.string() }),
outputSchema: z.object({ deleted: z.boolean() }),
requireApproval: true,
execute: async ({ id }) => {
await db.delete(id)
return { deleted: true }
},
})

const agent = new Agent({
id: 'my-agent',
name: 'My Agent',
model: 'openai/gpt-5-mini',
tools: { deleteTool },
})

const stream = await agent.stream('Delete record abc-123')

for await (const chunk of stream.fullStream) {
if (chunk.type === 'tool-call-approval') {
const approved = await agent.approveToolCall({ runId: stream.runId })
for await (const c of approved.textStream) process.stdout.write(c)
}
}
노트

Agent 승인은 스냅샷을 사용하여 요청 상태를 캡처합니다. 구성storage provider 를 Mastra 인스턴스에 구성해야 합니다. 그렇지 않으면 "snapshot not found" 오류가 표시됩니다.

Agent 실행에 대한 스냅샷은 최소 재개 아티팩트입니다. 일시 중지된 실행을 재개하는 데 필요한 것만 보유하고 실행이 완료되면 삭제됩니다. 사용tracing for the execution record and memory for the conversation history.

승인 작동 방식
승인 작동 방식에 대한 직접 링크

Mastra는 Tool 호출을 일시 중지하기 위한 두 가지 고유한 메커니즘을 제공합니다.pre-execution approval and runtime suspension.

사전 실행 승인
사전 실행 승인에 대한 직접 링크

사전 실행 승인으로 Tool 호출이 일시 중지됩니다.before its execute 함수가 실행됩니다. LLM은 여전히 호출할 Tool을 결정하고 인수를 제공하지만, execute doesn't run until you explicitly approve.

플래그는 OR 논리와 결합하여 이를 제어합니다. 만약에either is true, the call pauses:

플래그설정 위치범위
requireToolApproval: truestream() / generate() optionsPauses every tool call for that request
requireApproval: truecreateTool() definitionPauses calls to that specific tool

스트림은tool-call-approval chunk containing the toolCallId, toolName, and args. Call approveToolCall() or declineToolCall() with the stream's runId to continue:

const stream = await agent.stream("What's the weather in London?", {
requireToolApproval: true,
})

for await (const chunk of stream.fullStream) {
if (chunk.type === 'tool-call-approval') {
console.log('Tool:', chunk.payload.toolName)
console.log('Args:', chunk.payload.args)

// Approve
const approved = await agent.approveToolCall({ runId: stream.runId })
for await (const c of approved.textStream) process.stdout.write(c)

// Or decline
const declined = await agent.declineToolCall({ runId: stream.runId })
for await (const c of declined.textStream) process.stdout.write(c)
}
}

기능이 포함된 조건부 승인
기능이 포함된 조건부 승인에 대한 직접 링크

부울 대신requireToolApproval 는 각 Tool 호출별로 결정하는 함수를 받습니다. 이 함수는 toolName, the args the model passed, the requestContext, and the workspace. Return true to require approval for that call, or false 를 반환해 허용합니다. 이를 통해 런타임에 승인을 제어할 수 있습니다. 예를 들어 이름이 특정 패턴과 일치하는 Tool에만 승인을 요구할 수 있습니다:

const stream = await agent.stream('Clean up old records', {
requireToolApproval: ({ toolName }) => /^delete_/.test(toolName),
})

Tool 자체requireApproval 설정은 위의 함수보다 우선합니다. 이 설정의 규칙에 따라 해당 Tool에 승인이 필요한지가 결정됩니다. 함수에서 예외가 발생하면 안전을 위해 호출에 승인이 필요합니다.

노트

기능 기반requireToolApproval is only available on regular stream() / generate() 호출입니다. Durable Agent와 저장된 Agent는 옵션을 영속화하지만 함수는 직렬화할 수 없으므로 boolean만 허용합니다. 이러한 컨텍스트에서 함수를 전달하면 모든 Tool 호출에 승인을 요구하도록 대체 처리됩니다.

정확한 Tool 인수에 대한 승인 바인딩
정확한 Tool 인수에 대한 승인 바인딩에 대한 직접 링크

민감한 Tool의 경우 검토자에게 표시된 정확한 Tool 이름 및 인수에 승인을 연결합니다. 실행 전에 해당 인수가 표류하는 경우 Tool은 이전 승인 하에서 실행되어서는 안 됩니다.

그만큼tool-call-approval chunk already includes toolName, toolCallId, and args. 승인 요청이 표시될 때 이러한 필드의 지문을 생성할 수 있습니다. 아래 예제에서는 JSON 문자열을 지문으로 사용하지만, 프로덕션에서는 Tool 이름과 인수의 안정적인 해시를 사용해야 합니다:

src/mastra/agents/approval-bound-agent.ts
import { Agent } from '@mastra/core/agent'

// For your production usecase, build a stable hash of the tool name and args
function actionFingerprint(toolName: string, args: unknown) {
const payload = JSON.stringify({ toolName, args })
return `fingerprint-${payload}`
}

const sensitiveTools = new Set(['issue_refund', 'delete_record'])
const approvedFingerprints = new Set<string>()

export const approvalBoundAgent = new Agent({
id: 'approval-bound-agent',
name: 'Approval Bound Agent',
model: 'openai/gpt-5.6-sol',
tools: { issueRefundTool, deleteRecordTool },
hooks: {
beforeToolCall: ({ toolName, input }) => {
if (!sensitiveTools.has(toolName)) return

const fingerprint = actionFingerprint(toolName, input)
if (!approvedFingerprints.delete(fingerprint)) {
return {
proceed: false,
output: `Tool call blocked: approval did not match ${toolName} arguments.`,
}
}
},
},
})
const stream = await approvalBoundAgent.stream('Refund order ord-1042', {
requireToolApproval: ({ toolName }) => sensitiveTools.has(toolName),
})

async function consumeApprovalStream(currentStream: typeof stream) {
for await (const chunk of currentStream.fullStream) {
if (chunk.type === 'tool-call-approval') {
const { toolName, toolCallId, args } = chunk.payload
const fingerprint = actionFingerprint(toolName, args)

// Present toolName, args, and fingerprint to your approval UI.
const approved = await showApprovalDialog({ toolName, args, fingerprint })

const nextStream = approved
? await approveReviewedToolCall(currentStream.runId, toolCallId, fingerprint)
: await approvalBoundAgent.declineToolCall({ runId: currentStream.runId, toolCallId })

await consumeApprovalStream(nextStream)
}
}
}

async function approveReviewedToolCall(runId: string, toolCallId: string, fingerprint: string) {
approvedFingerprints.add(fingerprint)
return approvalBoundAgent.approveToolCall({ runId, toolCallId })
}

await consumeApprovalStream(stream)

프로덕션에서는 승인된 지문을 사용자, 실행, Tool 호출 및 정책 버전으로 범위가 지정된 내구성 있는 저장소에 저장합니다. 그만큼Set 는 경계를 명확하게 보여 주기 위해 의도적으로 간단하게 작성되었습니다. 승인은 한 번만 사용되며, 검토된 것과 동일한 정규화된 Tool 인수에만 적용됩니다.

런타임 중단suspend()
runtime-suspension-with-suspend에 대한 직접 링크

Tool은 일시 중지할 수도 있습니다.during its execute function by calling suspend(). 이는 Tool이 실행을 시작한 후 완료하기 전에 추가 사용자 입력이나 확인이 필요하다는 사실을 발견하는 경우에 유용합니다.

스트림은tool-call-suspended 청크를 Tool의 suspendSchema. You resume by calling resumeStream() with data matching the tool's resumeSchema.

const weatherTool = createTool({
id: 'get-weather',
inputSchema: z.object({
location: z.string().optional(),
}),
suspendSchema: z.object({
question: z.string(),
}),
resumeSchema: z.object({
location: z.string(),
}),
execute: async ({ location }, context) => {
if (!location) {
return await context?.agent?.suspend({
question: 'Which city would you like the weather for?',
})
}
return await fetchWeather(location)
},
})
노트

suspend()던지지 않고 호출한 후 즉시 반환합니다(예:return await suspend({ ... })). Code after await suspend(...) still runs before the tool pauses.

Tool 승인generate()
tool-approval-with-generate에 대한 직접 링크

Tool 승인은 다음에서도 작동합니다.generate() 비스트리밍 사용 사례에 사용합니다. Tool에 승인이 필요한 경우 generate() returns immediately with finishReason: 'suspended', a suspendPayload containing the tool call details (toolCallId, toolName, args), and a runId:

const output = await agent.generate('Find user John', {
requireToolApproval: true,
})

if (output.finishReason === 'suspended') {
console.log('Tool requires approval:', output.suspendPayload.toolName)

// Approve
const result = await agent.approveToolCallGenerate({
runId: output.runId,
toolCallId: output.suspendPayload.toolCallId,
})
console.log('Final result:', result.text)

// Or decline
const result = await agent.declineToolCallGenerate({
runId: output.runId,
toolCallId: output.suspendPayload.toolCallId,
})
}

스트리밍과 생성 비교
스트리밍과 생성 비교에 대한 직접 링크

측면stream()generate()
응답 유형스트리밍 청크전체 응답
승인 감지tool-call-approval chunkfinishReason: 'suspended'
Approve methodapproveToolCall({ runId })approveToolCallGenerate({ runId, toolCallId })
Decline methoddeclineToolCall({ runId })declineToolCallGenerate({ runId, toolCallId })
ResultStream to iterateFull output object

:::notetoolCallId 는 네 가지 메서드 모두에서 선택 사항입니다. 여러 Tool 호출이 대기 중일 수 있는 경우(감독자 Agent에서 흔함) 전달하세요. 생략하면 Agent가 가장 최근에 일시 중단된 Tool 호출을 재개합니다. :::

Tool 수준 승인
Tool 수준 승인에 대한 직접 링크

Agent 수준에서 모든 Tool 호출을 일시 중지하는 대신 개별 Tool을 승인이 필요한 것으로 표시할 수 있습니다. 세부적인 제어가 가능합니다. 특정 Tool만 일시 중지되고 다른 Tool은 즉시 실행됩니다.

다음을 사용하여 승인requireApproval
approval-using-requireapproval에 대한 직접 링크

세트requireApproval: true 를 Tool 정의에 설정하세요. requireToolApproval is set on the agent:

src/mastra/tools/test-tool.ts
export const testTool = createTool({
id: 'test-tool',
description: 'Fetches weather for a location',
inputSchema: z.object({
location: z.string(),
}),
outputSchema: z.object({
weather: z.string(),
}),
resumeSchema: z.object({
approved: z.boolean(),
}),
execute: async inputData => {
const response = await fetch(`https://wttr.in/${inputData.location}?format=3`)
const weather = await response.text()

return { weather }
},
requireApproval: true,
})

언제requireApproval is true, the stream emits tool-call-approval 청크를 Agent 수준 승인과 동일한 방식으로 처리합니다. approveToolCall() or declineToolCall() to continue:

const stream = await agent.stream("What's the weather in London?")

for await (const chunk of stream.fullStream) {
if (chunk.type === 'tool-call-approval') {
console.log('Approval required for:', chunk.payload.toolName)
}
}

const handleApproval = async () => {
const approvedStream = await agent.approveToolCall({ runId: stream.runId })

for await (const chunk of approvedStream.textStream) {
process.stdout.write(chunk)
}
process.stdout.write('\n')
}

다음을 사용하여 승인suspend()
approval-using-suspend에 대한 직접 링크

이 접근 방식을 사용하면 Agent나 Tool 모두 사용하지 않습니다.requireApproval. Instead, the tool's execute function calls suspend() 를 사용하여 특정 지점에서 실행을 일시 중지하고 사용자에게 컨텍스트 또는 확인 Prompt를 반환하세요. 이는 승인이 무조건 필요한 것이 아니라 런타임 조건에 따라 달라지는 경우에 유용합니다.

src/mastra/tools/test-tool-b.ts
export const testToolB = createTool({
id: 'test-tool-b',
description: 'Fetches weather for a location',
inputSchema: z.object({
location: z.string(),
}),
outputSchema: z.object({
weather: z.string(),
}),
resumeSchema: z.object({
approved: z.boolean(),
}),
suspendSchema: z.object({
reason: z.string(),
}),
execute: async (inputData, context) => {
const { resumeData: { approved } = {}, suspend } = context?.agent ?? {}

if (!approved) {
return suspend?.({ reason: 'Approval required.' })
}

const response = await fetch(`https://wttr.in/${inputData.location}?format=3`)
const weather = await response.text()

return { weather }
},
})

이 접근 방식을 사용하면 스트림에 다음이 포함됩니다.tool-call-suspended chunk, and the suspendPayload contains the reason defined by the tool's suspendSchema. Call resumeStream with the resumeSchema data and runId to continue:

const stream = await agent.stream("What's the weather in London?")

for await (const chunk of stream.fullStream) {
if (chunk.type === 'tool-call-suspended') {
console.log(chunk.payload.suspendPayload)
}
}

const handleResume = async () => {
const resumedStream = await agent.resumeStream({ approved: true }, { runId: stream.runId })

for await (const chunk of resumedStream.textStream) {
process.stdout.write(chunk)
}
process.stdout.write('\n')
}

자동 Tool 재개
자동 Tool 재개에 대한 직접 링크

호출하는 Tool을 사용할 때suspend(), 사용자의 다음 메시지를 기반으로 Agent가 일시 중단된 Tool을 재개하도록 자동 재개를 활성화할 수 있습니다. autoResumeSuspendedTools to true in the agent's default options or per-request:

src/mastra/agents/my-agent.ts
import { Agent } from '@mastra/core/agent'
import { Memory } from '@mastra/memory'

const agent = new Agent({
id: 'my-agent',
name: 'My Agent',
instructions: 'You are a helpful assistant',
model: 'openai/gpt-5-mini',
tools: { weatherTool },
memory: new Memory(),
defaultOptions: {
autoResumeSuspendedTools: true,
},
})

활성화되면 Agent는 다음 사용자 메시지의 메시지 기록에서 일시 중단된 Tool을 감지합니다. 추출한다resumeData based on the tool's resumeSchema, then automatically resumes the tool.

다음 예에서는 전체 대화 흐름을 보여줍니다.

src/mastra/tools/weather-tool.ts
import { createTool } from '@mastra/core/tools'
import { z } from 'zod'

const weatherTool = createTool({
id: 'weather-tool',
description: 'Fetches weather for a city',
inputSchema: z.object({
city: z.string(),
}),
outputSchema: z.object({
weather: z.string(),
}),
suspendSchema: z.object({
message: z.string(),
}),
resumeSchema: z.object({
city: z.string(),
}),
execute: async (inputData, context) => {
const { resumeData, suspend } = context?.agent ?? {}

// If no city provided, ask the user
if (!inputData.city && !resumeData?.city) {
return suspend?.({ message: 'What city do you want to know the weather for?' })
}

const city = resumeData?.city ?? inputData.city
const response = await fetch(`https://wttr.in/${city}?format=3`)
const weather = await response.text()

return { weather: `${city}: ${weather}` }
},
})
const stream = await agent.stream("What's the weather like?")

for await (const chunk of stream.fullStream) {
if (chunk.type === 'tool-call-suspended') {
console.log(chunk.payload.suspendPayload)
}
}

// User sends follow-up on the same thread
const resumedStream = await agent.stream('San Francisco')
for await (const chunk of resumedStream.textStream) {
process.stdout.write(chunk)
}
Console output
User: "What's the weather like?"
Agent: "What city do you want to know the weather for?"

User: "San Francisco"
Agent: "The weather in San Francisco is: San Francisco: ☀️ +72°F"

두 번째 메시지는 일시 중단된 Tool을 자동으로 재개합니다. Agent가 추출합니다.{ city: "San Francisco" } from the user's message and passes it as resumeData.

요구사항
요구사항에 대한 직접 링크

자동 Tool 재개가 작동하려면:

  • 구성된 Memory: Agent는 메시지 전체에서 일시 중지된 Tool을 추적하기 위해 Memory가 필요합니다.
  • 같은 스레드: 후속 메시지는 동일한 Memory 스레드 및 리소스 식별자를 사용해야 합니다.
  • resumeSchema한정된: Tool은 다음을 정의해야 합니다.resumeSchema 를 설정하여 Agent가 사용자 메시지에서 추출할 데이터 구조를 알 수 있게 하세요

수동 및 자동 재개
수동 및 자동 재개에 대한 직접 링크

접근사용 사례
수동 (resumeStream())프로그래밍 방식 제어, 웹훅, 버튼 클릭, 외부 트리거
자동(autoResumeSuspendedTools)사용자가 자연어로 재개 데이터를 제공하는 대화형 흐름

두 접근 방식 모두 동일한 Tool 정의로 작동합니다. 자동 재개는 일시 중단된 Tool이 메시지 기록에 존재하고 사용자가 동일한 스레드에서 새 메시지를 보내는 경우에만 트리거됩니다.

재시작 후 재개
재시작 후 재개에 대한 직접 링크

위의 예는 다음과 같습니다.stream.runId 를 일시 중단과 승인 사이에 유지합니다. 프로세스가 계속 실행되는 동안에는 이 방식이 작동하지만, 프로덕션에서는 페이지 새로 고침이나 서버 재시작 후 또는 로드 밸런서 뒤의 다른 서버 인스턴스에서 승인이 나중에 도착하는 경우가 많습니다.

사용listSuspendedRuns() 를 사용하여 스토리지에서 대화의 대기 중인 실행을 다시 찾으세요:

// In the request handler that receives the user's decision
const { runs } = await agent.listSuspendedRuns({
threadId: 'thread-123',
resourceId: 'user-456',
})

const run = runs[0]
const toolCall = run?.toolCalls[0]

if (run && toolCall) {
let stream
if (toolCall.requiresApproval) {
// Suspended by requireApproval — approve or decline the tool call
stream = await agent.approveToolCall({ runId: run.runId, toolCallId: toolCall.toolCallId })
} else {
// Suspended by suspend() — resume with the data the tool asked for
console.log('Tool asked:', toolCall.suspendPayload)
stream = await agent.resumeStream({ name: 'San Francisco' }, { runId: run.runId })
}
for await (const chunk of stream.textStream) process.stdout.write(chunk)
}

반환된 각 실행에는 일시 중단된 Tool 호출(toolCallId, toolName, args, and requiresApproval). Approval suspensions (requiresApproval: true) are answered with approveToolCall() / declineToolCall(), while suspend()-based suspensions carry their suspendPayload and expect resumeStream() 와 재개 데이터를 함께 제공하므로, 메모리에 상태를 보관하지 않고도 어느 흐름에 대해서든 적절한 UI를 다시 구성할 수 있습니다.

sendToolApproval()동일한 스토리지 지원 검색을 자동으로 사용합니다. 스레드에 대한 Memory에서 활성 실행이 발견되지 않으면 실패하기 전에 스토리지에서 일시 중단된 실행을 조회합니다. 여러 개의 일시 중단된 실행이 스레드와 일치하는 경우toolCallId to disambiguate.

HTTP를 통해 동일한 검색이 가능합니다.GET /agents/:agentId/suspended-runs and in the client SDK as agent.listSuspendedRuns(). 따라서 브라우저 기반 승인 UI에서 대기 중인 실행을 직접 다시 찾을 수 있습니다.

노트

일시 중단된 실행은 Mastra 인스턴스가 영구 인스턴스로 구성된 경우 다시 시작해도 유지됩니다.storage provider. 기본 인메모리 스토어는 프로세스가 종료되면 스냅샷을 잃습니다.

Tool 승인: 감독 Agent
Tool 승인: 감독 Agent에 대한 직접 링크

에이supervisor agent coordinates multiple subagents using .stream() or .generate(). 하위 Agent가 승인이 필요한 Tool을 호출하면 요청이 위임 체인을 따라 상위로 전파되어 감독자 수준에 표시됩니다:

  1. 감독자는 하위 Agent에게 작업을 위임합니다.
  2. 하위 Agent는 다음이 있는 Tool을 호출합니다.requireApproval: true or uses suspend().
  3. 승인 요청은 감독자에게 전달됩니다.
  4. 감독자 수준에서 승인하거나 거부합니다.
  5. 결정은 하위 Agent로 다시 전파됩니다.

Tool 승인은 여러 수준의 위임을 통해서도 전파됩니다. 감독자가 하위 Agent A에게 위임하고, 하위 Agent A는 다음 Tool이 있는 하위 Agent B에게 위임하는 경우requireApproval: true, 승인 요청은 여전히 최상위 감독자에 표시됩니다.

감독 Agent 승인 및 거부
감독 Agent 승인 및 거부에 대한 직접 링크

아래 예에서는 승인이 필요한 Tool을 사용하여 하위 Agent를 만듭니다. Tool이 승인 요청을 트리거하면 감독자의 스트림에tool-call-approval chunk:

import { Agent } from '@mastra/core/agent'
import { createTool } from '@mastra/core/tools'
import { Memory } from '@mastra/memory'
import { z } from 'zod'

const findUserTool = createTool({
id: 'find-user',
description: 'Finds user by ID in the database',
inputSchema: z.object({
userId: z.string(),
}),
outputSchema: z.object({
user: z.object({
id: z.string(),
name: z.string(),
email: z.string(),
}),
}),
requireApproval: true,
execute: async input => {
const user = await database.findUser(input.userId)
return { user }
},
})

const dataAgent = new Agent({
id: 'data-agent',
name: 'Data Agent',
description: 'Handles database queries and user data retrieval',
model: 'openai/gpt-5-mini',
tools: { findUserTool },
})

const supervisorAgent = new Agent({
id: 'supervisor',
name: 'Supervisor Agent',
instructions: `You coordinate data retrieval tasks.
Delegate to data-agent for user lookups.`,
model: 'openai/gpt-5.6-sol',
agents: { dataAgent },
memory: new Memory(),
})

const stream = await supervisorAgent.stream('Find user with ID 12345')

for await (const chunk of stream.fullStream) {
if (chunk.type === 'tool-call-approval') {
console.log('Tool requires approval:', chunk.payload.toolName)
console.log('Arguments:', chunk.payload.args)

// Approve the tool call
const resumeStream = await supervisorAgent.approveToolCall({
runId: stream.runId,
toolCallId: chunk.payload.toolCallId,
})

for await (const resumeChunk of resumeStream.textStream) {
process.stdout.write(resumeChunk)
}

// To decline instead, use:
const declineStream = await supervisorAgent.declineToolCall({
runId: stream.runId,
toolCallId: chunk.payload.toolCallId,
})
}
}

사용suspend() in supervisor agents
use-suspend-in-supervisor-agents에 대한 직접 링크

Tool도 사용할 수 있습니다suspend() 를 사용하여 실행을 일시 중지하고 사용자에게 컨텍스트를 반환하세요. 이 접근 방식은 requireApproval 와 동일한 방식으로 감독자 위임 체인을 통해 작동합니다. 즉, 일시 중단이 감독자 수준에 표시됩니다:

src/mastra/tools/conditional-tool.ts
const conditionalTool = createTool({
id: 'conditional-operation',
description: 'Performs an operation that may require confirmation',
inputSchema: z.object({
operation: z.string(),
}),
suspendSchema: z.object({
message: z.string(),
}),
resumeSchema: z.object({
confirmed: z.boolean(),
}),
execute: async (input, context) => {
const { resumeData } = context?.agent ?? {}

if (!resumeData?.confirmed) {
return context?.agent?.suspend({
message: `Confirm: ${input.operation}?`,
})
}

// Proceed with operation
return await performOperation(input.operation)
},
})
// When using this tool through a subagent in supervisor agents
for await (const chunk of stream.fullStream) {
if (chunk.type === 'tool-call-suspended') {
console.log('Tool suspended:', chunk.payload.suspendPayload.message)

// Resume with confirmation
const resumeStream = await supervisorAgent.resumeStream(
{ confirmed: true },
{ runId: stream.runId },
)

for await (const resumeChunk of resumeStream.textStream) {
process.stdout.write(resumeChunk)
}
}
}

다음을 통한 감독자 승인generate()
supervisor-approval-with-generate에 대한 직접 링크

Tool 승인 전파는 다음에서도 작동합니다.generate() in supervisor agents:

const output = await supervisorAgent.generate('Find user with ID 12345', {
maxSteps: 10,
})

if (output.finishReason === 'suspended') {
console.log('Tool requires approval:', output.suspendPayload.toolName)

// Approve
const result = await supervisorAgent.approveToolCallGenerate({
runId: output.runId,
toolCallId: output.suspendPayload.toolCallId,
})

console.log('Final result:', result.text)
}