システムプロンプト

システムプロンプトでは、エージェントの動作を制限したり、ドメイン固有のコンテキストを追加したり、応答のトーンやスタイルを設定したりできます。

デフォルトでは、SDK は組み込みのシステムプロンプトを使用し、ファイル編集、コード検索、シェルアクセスなどのコア機能をエージェントに付与します。このプロンプトを完全に置き換えるか、追加の指示を追加することができます。

デフォルトプロンプトを置換

systemPrompt オプションに文字列を渡して、組み込みのシステムプロンプトを完全に置き換えます。エージェントの動作を完全に制御する必要があり、デフォルトの手順を必要としない場合に使用します。

import { createCortexCodeSession } from "cortex-code-agent-sdk";

const session = await createCortexCodeSession({
  cwd: process.cwd(),
  systemPrompt: `You are a code review assistant.
Prioritize finding bugs, security issues, and maintainability risks.
Explain the issue and suggest concrete fixes.`,
});

警告

デフォルトのプロンプトを置き換えると、ツールの使用ガイダンスと安全ガードレールを含むすべての組み込み指示が削除されます。エージェントの動作を完全に制御する必要がある場合にのみ、プロンプトを置き換えてください。

デフォルトプロンプトに追加

組み込みの機能を維持しながら独自の指示を追加するには、 append フィールドでシステムプロンプトの事前設定オブジェクトを使用します。事前設定された名前は暗黙的であるため、 {"type": "preset", "append": ...} のみが必要です。これにより、デフォルトのシステムプロンプトの後に指示が追加されます。

import { createCortexCodeSession } from "cortex-code-agent-sdk";

const session = await createCortexCodeSession({
  cwd: process.cwd(),
  systemPrompt: {
    type: "preset",
    append: "Focus on Python files. Always run pytest after making changes.",
  },
});

両方の SDKs も追加のみの簡略形を指定します。

import { createCortexCodeSession } from "cortex-code-agent-sdk";

const session = await createCortexCodeSession({
  cwd: process.cwd(),
  appendSystemPrompt: "Focus on Python files. Always run pytest after making changes.",
});

一般的なパターン

レビューにフォーカスしたコードレビューアー

エージェントの動作について、分析優先のコードレビューを行うようバイアスをかけます。

import { createCortexCodeSession } from "cortex-code-agent-sdk";

const session = await createCortexCodeSession({
  cwd: process.cwd(),
  appendSystemPrompt: `You are a code reviewer. Follow these rules:
- Prioritize reading code and analyzing behavior before proposing changes.
- Do not modify files unless the user explicitly asks for an implementation.
- Identify bugs, security issues, and style problems.
- Provide specific line numbers and suggested fixes in your response.`,
});

ドメイン固有のエキスパート

エージェントが特定のテクノロジーまたはドメインに焦点を当てるようにします。

import { createCortexCodeSession } from "cortex-code-agent-sdk";

const session = await createCortexCodeSession({
  cwd: process.cwd(),
  appendSystemPrompt: `You are a SQL and database specialist working with Snowflake.
- Write efficient SQL queries optimized for Snowflake's columnar storage.
- Use Snowflake-specific features like VARIANT columns and FLATTEN.
- Always include LIMIT clauses in exploratory queries.
- Validate SQL syntax before suggesting changes.`,
});

スタイルエンフォーサー

エージェントが特定のコーディング標準に従っていることを確認してください。

import { createCortexCodeSession } from "cortex-code-agent-sdk";

const session = await createCortexCodeSession({
  cwd: process.cwd(),
  appendSystemPrompt: `Enforce these coding standards in all changes:
- Use TypeScript strict mode conventions.
- Prefer const over let; never use var.
- All functions must have explicit return types.
- Use async/await instead of raw Promises.
- Run "npm run lint" after every file change.`,
});

ベストプラクティス

追加と置換のタイミング

デフォルトプロンプトに追加

デフォルトプロンプトを置換

ドメインコンテキストまたは制約を追加する必要がある場合

エージェントの動作を完全に制御する必要がある場合

組み込みのツールの使用ガイダンスを保持する必要がある場合

高度に専門化されたエージェントを構築中である場合

安全ガードレールを維持する必要がある場合

デフォルトの手順がユースケースと競合する場合