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
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.3k
シニアエンジニアを超え、 スペシャリストとして組織の道を開拓する 「ソルバー」という働き方
mulyu
1
3.2k
コンテキストマップの継続的な活用に向けて
mulyu
1
380
ECSを活用してDigdagに安らぎを与える
mulyu
1
1k
Featured
See All Featured
The Invisible Side of Design
smashingmag
301
52k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
710
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
380
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
Chasing Engaging Ingredients in Design
codingconduct
0
370
Designing for Timeless Needs
cassininazir
1
530
A Modern Web Designer's Workflow
chriscoyier
699
190k
Thoughts on Productivity
jonyablonski
76
5.4k
Writing Fast Ruby
sferik
630
63k
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