Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
mastra code reading
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Mulyu
July 17, 2025
82
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
mastra code reading
Mulyu
July 17, 2025
More Decks by Mulyu
See All by Mulyu
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
3.2k
シニアエンジニアを超え、 スペシャリストとして組織の道を開拓する 「ソルバー」という働き方
mulyu
1
3.1k
コンテキストマップの継続的な活用に向けて
mulyu
1
380
ECSを活用してDigdagに安らぎを与える
mulyu
1
1k
Featured
See All Featured
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
The Curious Case for Waylosing
cassininazir
1
550
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
420
Six Lessons from altMBA
skipperchong
29
4.5k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
590
The Mindset for Success: Future Career Progression
greggifford
PRO
0
530
Exploring anti-patterns in Rails
aemeredith
4
520
The SEO identity crisis: Don't let AI make you average
varn
0
580
Utilizing Notion as your number one productivity tool
mfonobong
4
610
How Software Deployment tools have changed in the past 20 years
geshan
2
35k
Transcript
Mastraのコードリーディングガイド 1
背景 会社でMastraをAIエージェント開発の標準として採用 支援ツール開発に向けて最近コードを読み始めた これから読む人へのガイドとして共有 2
便利なMastra 標準でPlaygroundが用意されている APIも自動で生えてくる 一見ほとんど全部用意されてるじゃん! でも、それってどこで実装されてるの? 3
ここを読め server deployer この2つのパッケージを読めば、便利機能の仕組みが見えてくる 4
packages/の構成 core deployer server memory (現在読解中) etc... 太字: 今回説明する部分 5
serverパッケージ agent, memoryなどの操作の実装を提供 export async function getAgentsHandler({ mastra, runtimeContext }:
Context & { runtimeContext: RuntimeContext }) { const agents = mastra.getAgents(); const serializedAgentsMap = await Promise.all( Object.entries(agents).map(async ([id, agent]) => { const instructions = await agent.getInstructions({ runtimeContext }); const tools = await agent.getTools({ runtimeContext }); // ... 6
ここからわかること 標準の挙動を詳しく調べたいとき 微妙に違う実装にカスタムしたいとき → serverパッケージを見るべし 7
deployerパッケージ 操作をAPIにマッピング app.get( '/api/agents', describeRoute({ description: 'Get all available agents',
tags: ['agents'], responses: { 200: { description: 'List of all agents', }, }, }), getAgentsHandler, ); 8
ここからわかること あまり明示されていないMastraのAPI仕様を調べられる Honoを使ってAPIサーバーを実装している ミドルウェアなどの仕組みもHonoに乗っかっている 9
番外編: memory, storage エージェントにおけるメモリ 会話の文脈を保持 過去のやり取りを記憶 エージェントの状態管理 Mastraにおけるメモリ リソース: ユーザー単位など好きなスコープで切るもの
スレッド: 会話単位で切るもの 10
リソース リソースIDをユーザーIDにすると、ユーザーごとのメモリになる エージェントIDで切ると、エージェントごとのメモリになる グローバルとローカルなメモリを切り替えられると捉えている 11
おすすめの読み方 公式ドキュメント → examples/ → packages/ 公式ドキュメントが使用方法ベースで構成 ドキュメントのコード例から実装を辿る 例:エージェント作成 ドキュメントのサンプルコード
examples/でフル実装を確認 importからpackages/の該当箇所へ 12