LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangChain
  • Browser
  • Universal
  • Hub
  • Node
  • Load
  • Serializable
  • Encoder Backed
  • File System
  • In Memory
  • Tools
LangChain Core
  • Agents
  • Caches
  • Base
  • Dispatch
  • Web
  • Manager
  • Promises
  • Chat History
  • Context
  • Base
  • Langsmith
  • Documents
  • Embeddings
  • Errors
  • Example Selectors
  • Indexing
  • Base
  • Chat Models
  • Compat
  • Event
  • Llms
  • Openai Completions Stream
  • Profile
  • Stream
  • Structured Output
  • Load
  • Serializable
  • Memory
  • Messages
  • Tool
  • Output Parsers
  • Openai Functions
  • Openai Tools
  • Outputs
  • Prompt Values
  • Prompts
  • Retrievers
  • Document Compressors
  • Runnables
  • Graph
  • Singletons
  • Stores
  • Structured Query
  • Testing
  • Tools
  • Base
  • Console
  • Log Stream
  • Run Collector
  • Tracer Langchain
  • Stream
  • Async Caller
  • Chunk Array
  • Context
  • Env
  • Event Source Parse
  • Format
  • Function Calling
  • Gateway
  • Hash
  • Json Patch
  • Json Schema
  • Math
  • Ssrf
  • Standard Schema
  • Stream
  • Testing
  • Tiktoken
  • Types
  • Uuid
  • Vectorstores
Text Splitters
MCP Adapters
⌘I

Chat LangChain

What can I help with?

Enter to sendĀ·Shift+Enter new line

Menu

LangChain
BrowserUniversalHubNodeLoadSerializableEncoder BackedFile SystemIn MemoryTools
LangChain Core
AgentsCachesBaseDispatchWebManagerPromisesChat HistoryContextBaseLangsmithDocumentsEmbeddingsErrorsExample SelectorsIndexingBaseChat ModelsCompatEventLlmsOpenai Completions StreamProfileStreamStructured OutputLoadSerializableMemoryMessagesToolOutput ParsersOpenai FunctionsOpenai ToolsOutputsPrompt ValuesPromptsRetrieversDocument CompressorsRunnablesGraphSingletonsStoresStructured QueryTestingToolsBaseConsoleLog StreamRun CollectorTracer LangchainStreamAsync CallerChunk ArrayContextEnvEvent Source ParseFormatFunction CallingGatewayHashJson PatchJson SchemaMathSsrfStandard SchemaStreamTestingTiktokenTypesUuidVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScriptlangchainindexCreateAgentParamssystemPrompt
Propertyā—Since v1.1

systemPrompt

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:

  • Anthropic cache control: Use 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.
  • Multiple content blocks: When you need multiple text blocks with different metadata or formatting requirements.
  • Integration with existing code: When working with code that already produces SystemMessage instances.
Copy
systemPrompt: string | SystemMessage

Example 1

Copy
const agent = createAgent({
  model: "anthropic:claude-sonnet-4-5",
  systemPrompt: "You are a helpful assistant.",
  // ...
});

Example 2

Copy
const userRole = "premium";
const agent = createAgent({
  model: "anthropic:claude-sonnet-4-5",
  systemPrompt: `You are a helpful assistant for ${userRole} users.`,
  // ...
});

Example 3

Copy
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" },
      },
    ],
  }),
  // ...
});

Example 4

Copy
import { SystemMessage } from "@langchain/core/messages";

const agent = createAgent({
  model: "anthropic:claude-sonnet-4-5",
  systemPrompt: new SystemMessage("You are a helpful assistant."),
  // ...
});
View source on GitHub