# systemPrompt

> **Property** in `langchain`

📖 [View in docs](https://reference.langchain.com/javascript/langchain/index/CreateAgentParams/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.

## Signature

```javascript
systemPrompt: string | SystemMessage
```

## Examples

### Example 1

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

### Example 2

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

### Example 3

```ts
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

```ts
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](https://github.com/langchain-ai/langchainjs/blob/a5f7f6aedbbe6bf18610399c93045050e22339f7/libs/langchain/src/agents/types.ts#L695)