An optional system message for the model.
Use a string for simple, static system prompts. This is the most common use case
and works well with template literals for dynamic content. When a string is provided,
it's converted to a single text block internally.
Use a SystemMessage when you need advanced features that require structured content:
SystemMessage with array content to enable per-block
cache control settings (e.g., cache_control: { type: "ephemeral" }). This allows you
to have different cache settings for different parts of your system prompt.SystemMessage instances.systemPrompt: string | SystemMessageconst agent = createAgent({
model: "anthropic:claude-sonnet-4-5",
systemPrompt: "You are a helpful assistant.",
// ...
});const userRole = "premium";
const agent = createAgent({
model: "anthropic:claude-sonnet-4-5",
systemPrompt: `You are a helpful assistant for ${userRole} users.`,
// ...
});import { SystemMessage } from "@langchain/core/messages";
const agent = createAgent({
model: "anthropic:claude-sonnet-4-5",
systemPrompt: new SystemMessage({
content: [
{
type: "text",
text: "You are a helpful assistant.",
},
{
type: "text",
text: "Today's date is 2024-06-01.",
cache_control: { type: "ephemeral" },
},
],
}),
// ...
});import { SystemMessage } from "@langchain/core/messages";
const agent = createAgent({
model: "anthropic:claude-sonnet-4-5",
systemPrompt: new SystemMessage("You are a helpful assistant."),
// ...
});