> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ko/llms.txt # 실행.스트림() 그만큼`.stream()`메서드를 사용하면 Workflow에서 응답을 실시간 스트리밍할 수 있습니다. 그것은`ReadableStream`직접 이벤트를 진행합니다. ## 사용예 ```typescript const run = await workflow.createRun() const stream = await run.stream({ inputData: { value: 'initial data', }, }) for await (const chunk of stream) { console.log(chunk) } ``` ## 매개변수 **inputData** (`z.infer`): Workflow의 입력 스키마와 일치하는 입력 데이터 **requestContext** (`RequestContext`): Workflow 실행 중 사용할 요청 컨텍스트 데이터 **tracingContext** (`TracingContext`): 하위 스팬을 생성하고 메타데이터를 추가하기 위한 Tracing 컨텍스트입니다. **tracingContext.currentSpan** (`Span`): 하위 스팬을 생성하고 메타데이터를 추가하기 위한 현재 스팬입니다. **tracingOptions** (`TracingOptions`): Tracing 구성 옵션입니다. **tracingOptions.metadata** (`Record`): 루트 Trace 스팬에 추가할 메타데이터입니다. **tracingOptions.requestContextKeys** (`string[]`): 이 Trace의 메타데이터로 추출할 추가 RequestContext 키입니다. 중첩 값에 점 표기법(예: 'user.id')을 지원합니다. **tracingOptions.traceId** (`string`): 이 실행에 사용할 Trace ID(1\~32자의 16진수)입니다. 제공하면 이 Trace가 지정된 Trace의 일부가 됩니다. **tracingOptions.parentSpanId** (`string`): 이 실행에 사용할 상위 스팬 ID(1\~16자의 16진수)입니다. 제공하면 루트 스팬이 이 스팬의 하위로 생성됩니다. **tracingOptions.tags** (`string[]`): 이 Trace에 적용할 태그입니다. Trace를 분류하고 필터링하기 위한 문자열 레이블입니다. **closeOnSuspend** (`boolean`): Workflow가 일시 중단될 때 스트림을 닫을지, 아니면 Workflow가 성공 또는 오류로 종료될 때까지 스트림을 열어 둘지 지정합니다. 기본값은 true입니다. ## 보고 비동기 이터러블 인터페이스를 구현하고(`for await...of` 루프에서 직접 사용 가능) 스트림과 Workflow 실행 결과에 대한 접근을 제공하는 `WorkflowRunOutput` 객체를 반환합니다. **fullStream** (`ReadableStream`): 실시간으로 진행 상황을 추적할 수 있도록 반복 처리 가능한 Workflow 이벤트의 ReadableStream입니다. WorkflowRunOutput 객체 자체를 직접 반복 처리할 수도 있습니다. **result** (`Promise>`): 최종 Workflow 결과로 이행되는 Promise입니다. **status** (`WorkflowRunStatus`): 현재 Workflow 실행 상태('running', 'suspended', 'success', 'failed', 'canceled' 또는 'tripwire')입니다. **usage** (`Promise<{ inputTokens: number; outputTokens: number; totalTokens: number, reasoningTokens?: number, cachedInputTokens?: number }>`): 토큰 사용량 통계로 이행되는 Promise입니다. ## 확장된 사용 예 ```typescript const run = await workflow.createRun() const stream = run.stream({ inputData: { value: 'initial data', }, }) // Iterate over stream events (you can iterate over stream directly or use stream.fullStream) for await (const chunk of stream) { console.log(chunk) } // Access the final result const result = await stream.result console.log('Final result:', result) // Access token usage const usage = await stream.usage console.log('Token usage:', usage) // Check current status console.log('Status:', stream.status) ``` ## 이벤트 스트리밍 스트림은 Workflow 실행 중 이벤트 유형을 방출합니다. 각 이벤트에는 `type` 필드와 관련 데이터가 담긴 `payload`가 있습니다. - **`workflow-start`**: Workflow 실행이 시작됩니다. - **`workflow-step-start`**: 단계 실행이 시작됩니다. - **`workflow-step-output`**: 단계의 사용자 정의 출력입니다. - **`workflow-step-progress`**: foreach 단계가 반복별 진행 상황을 보고합니다(`completedCount`, `totalCount`, `currentIndex`, `iterationStatus` 및 선택적 `iterationOutput` 포함). - **`workflow-step-result`**: 단계가 결과와 함께 완료됩니다. - **`workflow-finish`**: 사용량 통계와 함께 Workflow 실행이 완료됩니다. 성공적으로 실행된 경우 `payload.finalWorkflowResult`에 Workflow의 최종 결과가 담기므로 스트림 소비자가 후속 가져오기를 수행할 필요가 없습니다. ## 관련된 - [Workflow 개요](https://mastra.zisheng.pro/ko/docs/workflows/overview) - [Workflow.createRun()](https://mastra.zisheng.pro/ko/reference/workflows/workflow-methods/create-run) - [실행.이력스트림()](https://mastra.zisheng.pro/ko/reference/streaming/workflows/resumeStream)