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
86
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
mastra code reading
Mulyu
July 17, 2025
Transcript
12 slides
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
More Decks by Mulyu
See All by Mulyu
AIによる開発の民主化を支える コンテキスト管理のこれまでとこれから
mulyu
3
3.4k
シニアエンジニアを超え、 スペシャリストとして組織の道を開拓する 「ソルバー」という働き方
mulyu
1
3.2k
コンテキストマップの継続的な活用に向けて
mulyu
1
410
ECSを活用してDigdagに安らぎを与える
mulyu
1
1k
Featured
See All Featured
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
580
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
540
How to make the Groovebox
asonas
2
2.6k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
970
Everyday Curiosity
cassininazir
0
440
Reality Check: Gamification 10 Years Later
codingconduct
0
2.4k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
70
70k
A Modern Web Designer's Workflow
chriscoyier
699
190k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
1k
Docker and Python
trallard
47
4.3k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
540
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.8k