Mastra、コードエージェント作成支援ツール「createCodingAgent」を発表
本文の状態
日本語全文を表示中
詳細モードで約4分の本文を読めます。
同じ出来事の情報源
この情報源を基点に整理
Mastra Blog
Mastra は開発者が独自のコーディングエージェントを構築するためのヘルパー関数 createCodingAgent と、振る舞いを定義する buildBasePrompt を導入した。
AI深層分析を開く2026年8月18日 03:06
AI深層分析
キーポイント
コーディングエージェントの簡易構築機能
createCodingAgent ヘルパーにより、モデルの設定やメモリ管理、ファイル読み書き、コマンド実行、バグ修正機能を備えたエージェントを容易に開発できる。
標準的な開発環境との統合
作成されたエージェントは AgentController と連携し、Mastra Code が使用するのと同じプリミティブ(サンドボックス、タスクリスト、ゴール判定プロンプト)を利用する。
柔軟な動作定義とカスタマイズ
buildBasePrompt を使用してリポジトリやブランチを指定し、計画モードと実装モードを切り替えるなど、振る舞いを細かく制御できる。
拡張機能の追加可能性
ワークスペースの置換やエラープロセッサの変更に加え、ウェブ検索や URL フェッチなどの組み込みツールを容易に追加可能である。
必要なバージョン要件
この機能を使用するには @mastra/core@1.48.0 以降が必要であり、PR #18695 で追加された。
重要な引用
Configure it with a model, instructions, and memory. It can read files, run commands, fix bugs, and track its own progress.
Agents created with createCodingAgent are like any other Mastra agent, they work with AgentController, and use the same primitives Mastra Code runs on.
Configure the agent with a model and memory. Build instructions dynamically per request, reading values from requestContext:
const mode = (requestContext.get("mode") as string) ?? "build";
編集コメントを表示
編集コメント
Mastra は、複雑なエージェント構築の障壁を下げるための具体的なライブラリを提供した。このアプローチにより、開発者は個別にサンドボックスやプロンプト設計を行う手間を省き、実用的なコーディング支援ツールを迅速に立ち上げられるようになる。
Source Article
元記事を日本語で読む
本文に関係しない購読案内、埋め込み通知、サイト内プロモーションは除いています。
現在、createCodingAgent を利用すれば、必要な機能をすべて備えた独自のコーディングエージェントを開発できます。モデルや指示、メモリを構成して設定するだけで、ファイルの読み込み、コマンドの実行、バグの修正、そして自身の進捗管理まで行うことができます。
コーディングエージェントを構築する際、createCodingAgent ヘルパーを使えば、ファイルの読み書きができるサンドボックスや、エージェントが実行・完了できるタスクリスト、変更内容を検証するためのゴール判定プロンプトといった、必要な基本機能から始められます。createCodingAgent で作成されたエージェントは他の Mastra エージェントと同様に動作し、AgentController と連携でき、同じく Mastra Code が使用する基盤機能を共有します。
お使いのブラウザは動画タグに対応していません。
エージェントの動作を定義するには、buildBasePrompt を使用してください。projectPath でリポジトリを指定し、gitBranch でブランチを設定します。変更を計画・提案するモードや、実際に実装を行うモードを選択できます。
また、リクエストごとに動作を変更するために requestContext にアクセスする関数として指示を渡すことも可能です。
createCodingAgent のデフォルト設定はカスタマイズ可能です。ワークスペースの差し替えやエラー処理プロセスの置き換え、独自のシグナルの追加、あるいはジャッジプロンプトの変更などが行えます。さらに機能を拡張したい場合は、Mastra の 組み込みツール を利用できます。これにはウェブ検索、URL 取得、ユーザーへの質問機能が含まれます。
はじめに
@mastra/core と @mastra/memory をインストールしてください:
npm install @mastra/core @mastra/memory注意
この機能には @mastra/core@1.48.0 以降が必要です。これは PR #18695 で追加されました。
エージェントには、model と memory を設定します。また、各リクエストごとに動的にビルド指示を作成し、requestContext から値を読み取ります。
import { buildBasePrompt, createCodingAgent } from "@mastra/core/coding-agent";
import { webSearchTool, webFetchTool, askUserTool } from "@mastra/core/tools";
import { Memory } from "@mastra/memory";
export const codingAgent = createCodingAgent({
id: "coding-agent",
name: "Coding Agent",
instructions: ({ requestContext }) => {
const mode = (requestContext.get("mode") as string) ?? "build";
const projectPath = (requestContext.get("projectPath") as string) ?? process.cwd();
const projectName = (requestContext.get("projectName") as string) ?? "my-app";
const gitBranch = (requestContext.get("gitBranch") as string) ?? "main";
return buildBasePrompt({
mode,
projectPath,
projectName,
gitBranch,
modelId: "anthropic/claude-sonnet-4.6",
productName: "Acme Coder",
coAuthorName: "Acme Bot",
coAuthorEmail: "bot@acme.dev"
});
},
defaultOptions: {
maxSteps: 50
},
model: "anthropic/claude-sonnet-4.6",
memory: new Memory(),
tools: { webSearchTool, webFetchTool, askUserTool }
});サンドボックスのカスタマイズ
デフォルトの LocalSandbox はホストマシン上でコマンドを実行します。エージェントに隔離環境が必要であれば、E2B などのリモートサンドボックスに切り替えてください。
import { createCodingAgent } from "@mastra/core/coding-agent";
import { LocalFilesystem, Workspace } from "@mastra/core/workspace";
import { E2BSandbox } from "@mastra/e2b";
export const codingAgent = createCodingAgent({
// ...
workspace: new Workspace({
filesystem: new LocalFilesystem({ basePath: process.cwd() }),
sandbox: new E2BSandbox()
})
});タスク追跡のカスタマイズ
メモリが設定されている場合、デフォルトの TaskSignalProvider が渡すすべてのシグナルに自動的に追加されます。独自の信号プロバイダーを指定した場合でも、タスク追跡機能は有効なままです。
import { createCodingAgent } from "@mastra/core/coding-agent";
import { WebhookSignalProvider } from "@mastra/core/signals";
import { Memory } from "@mastra/memory";
export const codingAgent = createCodingAgent({
// ...
memory: new Memory(),
signals: [
new WebhookSignalProvider({
extractResourceId: (payload) => (payload as { repository: string }).repository
})
]
});エラー再試行のカスタマイズ
デフォルトの再試行スタックでは、ECONNRESET や不正なリクエストエラー、プリフィル/履歴の互換性に関する問題に対応しています。再試行回数や遅延時間、マッチ条件を調整したい場合は、独自の StreamErrorRetryProcessor に置き換えてください。
import { createCodingAgent } from "@mastra/core/coding-agent";
import { StreamErrorRetryProcessor } from "@mastra/core/processors";
export const codingAgent = createCodingAgent({
// ...
errorProcessors: [
new StreamErrorRetryProcessor({
retryUnknownErrors: true,
maxRetries: 5,
delayMs: ({ retryCount }) => Math.min(1000 * 2 ** retryCount, 30000)
})
]
});ゴール判定器のカスタマイズ
独自の judge モデル、実行バジェット、および prompt 指示を使用して、ゴール をカスタマイズできます:
import { createCodingAgent } from "@mastra/core/coding-agent";
export const codingAgent = createCodingAgent({
//...
goal: {
judge: "anthropic/claude-haiku-4.5",
maxRuns: 50,
prompt: "Return `complete` when the code compiles and tests pass."
}
});詳細や完全な設定オプションについては、以下のリファレンスをご覧ください。
原文を表示
You can now use createCodingAgent to develop your own coding agent with all the essentials it needs. Configure it with a model, instructions, and memory. It can read files, run commands, fix bugs, and track its own progress.
If you're building a coding agent, the createCodingAgent helper starts you off with the right primitives: a sandbox for reading and writing files, a task list the agent can work through and complete, and a goal-judge prompt to validate the changes. Agents created with createCodingAgent are like any other Mastra agent, they work with AgentController, and use the same primitives Mastra Code runs on.
Your browser does not support the video tag.
Use the buildBasePrompt to define your agent's behavior. Point it at your repo with projectPath, and set a branch using gitBranch. Use a mode to plan and propose changes, or build when it should implement them. Pass instructions as a function that accesses requestContext to modify behavior per request.
The createCodingAgent defaults can be customized — swap the workspace, replace the error processors, add your own signals, or modify the judge prompt. For additional functionality, you can drop in Mastra's built-in tools — web search, URL fetch, and ask-user prompts.
Get started
Install @mastra/core and @mastra/memory:
npm install @mastra/core @mastra/memorynote
Requires @mastra/core@1.48.0 or later, added in PR #18695.
Configure the agent with a model and memory. Build instructions dynamically per request, reading values from requestContext:
import { buildBasePrompt, createCodingAgent } from "@mastra/core/coding-agent";
import { webSearchTool, webFetchTool, askUserTool } from "@mastra/core/tools";
import { Memory } from "@mastra/memory";
export const codingAgent = createCodingAgent({
id: "coding-agent",
name: "Coding Agent",
instructions: ({ requestContext }) => {
const mode = (requestContext.get("mode") as string) ?? "build";
const projectPath = (requestContext.get("projectPath") as string) ?? process.cwd();
const projectName = (requestContext.get("projectName") as string) ?? "my-app";
const gitBranch = (requestContext.get("gitBranch") as string) ?? "main";
return buildBasePrompt({
mode,
projectPath,
projectName,
gitBranch,
modelId: "anthropic/claude-sonnet-4.6",
productName: "Acme Coder",
coAuthorName: "Acme Bot",
coAuthorEmail: "bot@acme.dev"
});
},
defaultOptions: {
maxSteps: 50
},
model: "anthropic/claude-sonnet-4.6",
memory: new Memory(),
tools: { webSearchTool, webFetchTool, askUserTool }
});Customize the sandbox
The default LocalSandbox runs commands on the host machine. Swap in a remote sandbox like E2B when the agent needs isolation:
import { createCodingAgent } from "@mastra/core/coding-agent";
import { LocalFilesystem, Workspace } from "@mastra/core/workspace";
import { E2BSandbox } from "@mastra/e2b";
export const codingAgent = createCodingAgent({
// ...
workspace: new Workspace({
filesystem: new LocalFilesystem({ basePath: process.cwd() }),
sandbox: new E2BSandbox()
})
});Customize task tracking
With memory configured, the default TaskSignalProvider is added to any signals you pass. Task tracking remains enabled when you pass your own signal providers:
import { createCodingAgent } from "@mastra/core/coding-agent";
import { WebhookSignalProvider } from "@mastra/core/signals";
import { Memory } from "@mastra/memory";
export const codingAgent = createCodingAgent({
// ...
memory: new Memory(),
signals: [
new WebhookSignalProvider({
extractResourceId: (payload) => (payload as { repository: string }).repository
})
]
});Customize error retries
The default retry stack handles ECONNRESET, bad-request errors, and prefill/history compatibility. Replace it with your own StreamErrorRetryProcessor to tune retry counts, delays, or matchers:
import { createCodingAgent } from "@mastra/core/coding-agent";
import { StreamErrorRetryProcessor } from "@mastra/core/processors";
export const codingAgent = createCodingAgent({
// ...
errorProcessors: [
new StreamErrorRetryProcessor({
retryUnknownErrors: true,
maxRetries: 5,
delayMs: ({ retryCount }) => Math.min(1000 * 2 ** retryCount, 30000)
})
]
});Customize the goal judge
Customize the goal with your own judge model, run budget, and prompt instructions:
import { createCodingAgent } from "@mastra/core/coding-agent";
export const codingAgent = createCodingAgent({
//...
goal: {
judge: "anthropic/claude-haiku-4.5",
maxRuns: 50,
prompt: "Return `complete` when the code compiles and tests pass."
}
});For more information and full configuration options, see:
- createCodingAgent reference
- buildBasePrompt reference
- Agent reference
- AgentController reference
- TaskSignalProvider reference
- Workspace reference
関連記事
News to Guide
ニュースの次に確認する
発表内容を、現在の料金や仕様と照らし合わせられる関連ガイドです。
今日のまとめ
AIデイリーブリーフで今日の重要ニュースをまとめ読み