LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Agent
  • Middleware
  • Backends
  • Sandboxes
  • Skills
  • Subagents
  • Configuration
  • Types
Modal
Daytona
Deno
Node VFS
Sandbox Standard Tests
  • Vitest
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewAgentMiddlewareBackendsSandboxesSkillsSubagentsConfigurationTypes
Modal
Daytona
Deno
Node VFS
Sandbox Standard Tests
Vitest
Language
Theme
JavaScriptdeepagentsmiddlewareprependToSystemMessage
Function●Since v1.6

prependToSystemMessage

Prepend text to a system message.

Creates a new SystemMessage with the text prepended to the existing content. If the original message has content, the new text is separated by two newlines.

Copy
prependToSystemMessage(
  systemMessage: SystemMessage<MessageStructure<MessageToolSet>> | null | undefined,
  text: string
): SystemMessage

Parameters

NameTypeDescription
systemMessage*SystemMessage<MessageStructure<MessageToolSet>> | null | undefined

Existing system message or null/undefined.

text*string

Text to prepend to the system message.

Example

Copy
const original = new SystemMessage({ content: "Always be concise." });
const updated = prependToSystemMessage(original, "You are a helpful assistant.");
// Result: SystemMessage with content "You are a helpful assistant.\n\nAlways be concise."
View source on GitHub