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
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
720
Paper Plane (Part 1)
katiecoart
PRO
2
11k
Designing for humans not robots
tammielis
254
26k
Deep Space Network (abreviated)
tonyrice
0
350
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.2k
Building Adaptive Systems
keathley
44
3.2k
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
890
KATA
mclloyd
PRO
35
16k
From π to Pie charts
rasagy
1
380
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
49
3.6k
The untapped power of vector embeddings
frankvandijk
2
1.9k
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