Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
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
79
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.1k
シニアエンジニアを超え、 スペシャリストとして組織の道を開拓する 「ソルバー」という働き方
mulyu
1
3k
コンテキストマップの継続的な活用に向けて
mulyu
1
370
ECSを活用してDigdagに安らぎを与える
mulyu
1
990
Featured
See All Featured
Rails Girls Zürich Keynote
gr2m
96
14k
How to train your dragon (web standard)
notwaldorf
97
6.8k
Chasing Engaging Ingredients in Design
codingconduct
0
280
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Mobile First: as difficult as doing things right
swwweet
225
10k
Git: the NoSQL Database
bkeepers
PRO
432
67k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.9k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
480
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
280
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
580
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
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