마스트라 수업
그만큼Mastra클래스는 모든 Mastra 애플리케이션의 중앙 조정자로서 Agent, Workflow, 스토리지, 로깅, Observability 등을 관리합니다. 일반적으로 단일 인스턴스를 생성합니다.Mastra귀하의 신청서를 조정합니다.
Mastra는 애플리케이션 전체에서 접근해야 하는 Agent, Workflow, Tool 및 기타 구성 요소를 등록하는 최상위 레지스트리라고 생각하면 됩니다.
사용예사용예에 대한 직접 링크
import { Mastra } from '@mastra/core'
import { PinoLogger } from '@mastra/loggers'
import { LibSQLStore } from '@mastra/libsql'
import { weatherWorkflow } from './workflows/weather-workflow'
import { weatherAgent } from './agents/weather-agent'
export const mastra = new Mastra({
workflows: { weatherWorkflow },
agents: { weatherAgent },
storage: new LibSQLStore({
id: 'mastra-storage',
url: ':memory:',
}),
logger: new PinoLogger({
name: 'Mastra',
level: 'info',
}),
})
지연된 알림 기록 및 알림 요약이 Workflow 스케줄러를 통해 자동으로 전달되어야 하는 경우 예약된 알림 발송을 활성화합니다.
export const mastra = new Mastra({
agents: { supportAgent },
storage,
notifications: {
dispatch: {
enabled: true,
cron: '*/1 * * * *',
batchSize: 100,
},
},
})
notifications.dispatch.enabled를 사용하면 내부 디스패처 Workflow가 기본 크론 */1 * * * *에 따라 실행됩니다. 디스패처는 스토리지에서 처리 시점이 된 알림 레코드를 읽고 agentId, resourceId, threadId별로 요약을 그룹화한 다음 Agent 스레드 런타임을 통해 신호를 내보냅니다. 이는 사용자용 진입점이 아닙니다. 디스패치 일정과 이를 지원하는 Workflow 스케줄러는 처음으로 지연 알림이나 요약 알림이 생성될 때 지연 활성화되므로, 알림을 연기하지 않는 앱에서는 스케줄러가 전혀 실행되지 않습니다.
생성자 매개변수생성자 매개변수에 대한 직접 링크
사용 가능한 모든 구성 옵션의 자세한 문서는 구성 레퍼런스를 참조하세요.
agents?:
tools?:
storage?:
vectors?:
logger?:
idGenerator?:
workflows?:
tts?:
observability?:
environment?:
production, staging, development)입니다. 설정하면 모든 Observability 신호에 자동으로 연결되므로, 호출할 때마다 tracingOptions.metadata.environment를 전달하지 않아도 환경별로 필터링할 수 있습니다. 설정하지 않으면 process.env.NODE_ENV를 사용하며, 둘 다 설정되지 않은 경우 undefined로 유지됩니다. 호출별 tracingOptions.metadata.environment가 항상 우선합니다.deployer?:
server?:
mcpServers?:
bundler?:
scorers?:
processors?:
gateways?:
memory?:
notifications?:
dispatch?:
enabled?:
false로 설정합니다.cron?:
batchSize?:
versions?:
agents?:
versionId?:
status?:
workers?:
false를 전달합니다(독립 실행형 워커를 별도로 실행할 때 유용함). 사용자 정의 워커를 추가하려면 MastraWorker[]를 전달합니다. 이 워커들은 자동 생성된 기본 워커와 병합되며, 기본 워커와 name이 같은 사용자 정의 워커가 기본 워커를 대체합니다.backgroundTasks?:
enabled?:
globalConcurrency?:
perAgentConcurrency?:
backpressure?:
defaultTimeoutMs?:
defaultRetries?:
scheduler?:
schedule을 선언하면 자동으로 활성화됩니다. 예약된 Workflow를 참조하세요.enabled?:
행동 양식행동 양식에 대한 직접 링크
recoverAllDurableAgents()recoveralldurableagents에 대한 직접 링크
등록된 모든 영속 Agent에서 고아 상태인 모든 running 영속 Agent 실행을 다시 구동합니다. recovery.durableAgents가 'auto'이면 부팅 시 자동으로 호출됩니다. 수동 복구를 위해 직접 호출하거나 예약된 작업에서 호출할 수도 있습니다.
영구 저장소가 필요합니다. Memory 내 저장소를 사용하면 프로세스를 다시 시작한 후 복구할 것이 없습니다.
const result = await mastra.recoverAllDurableAgents()
// { agents: 2, recovered: 3, succeeded: 3, failed: 0 }
보고: