Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/oss/javascript/releases/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ A chronological log of updates and improvements to LangChain JavaScript.
* [Summarization middleware](/oss/langchain/middleware/built-in#summarization): Updated to support flexible trigger points using model profiles for context-aware summarization.
* [Structured output](/oss/langchain/structured-output): `ProviderStrategy` support (native structured output) can now be inferred from model profiles.
* [`SystemMessage` for `createAgent`](/oss/langchain/middleware/custom#working-with-system-messages): Support for passing `SystemMessage` instances directly to `createAgent`'s `systemPrompt` parameter and a new `concat` method for extending system messages. Enables advanced features like cache control and structured content blocks.
* [Dynamic system prompt middleware](/oss/langchain/agents#dynamic-system-prompt): Return values from `dynamicSystemPromptMiddleware` are now purely additive. When returning a @[`SystemMessage`] or `string`, they are merged with existing system messages rather than replacing them, making it easier to compose multiple middleware that modify the prompt.
* [Model retry middleware](/oss/langchain/middleware/built-in#model-retry): New middleware for automatically retrying failed model calls with configurable exponential backoff, improving agent reliability.
* [Content moderation middleware](/oss/langchain/middleware/built-in#content-moderation): OpenAI content moderation middleware for detecting and handling unsafe content in agent interactions. Supports checking user input, model output, and tool results.
* * __Compatibility improvements:__ Fixed error handling for Zod v4 validation errors in structured output and tool schemas, ensuring detailed error messages are properly displayed.
* __Compatibility improvements:__ Fixed error handling for Zod v4 validation errors in structured output and tool schemas, ensuring detailed error messages are properly displayed.

### Resources

Expand Down
19 changes: 18 additions & 1 deletion src/oss/langchain/middleware/custom.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,8 @@ class CachedContextMiddleware(AgentMiddleware):
:::

:::js
Modify system messages in middleware using the `systemMessage` field in `ModelRequest`. It contains a @[`SystemMessage`] object (even if the agent was created with a string @[`systemPrompt`]).

**Example: Chaining middleware** - Different middleware can use different approaches:

```typescript
Expand All @@ -1060,7 +1062,7 @@ const myMiddleware = createMiddleware({
wrapModelCall: async (request, handler) => {
return handler({
...request,
systemMessage: request.systemMessage.concat(`\nAdditional context.`),
systemMessage: request.systemMessage.concat(`Additional context.`),
});
},
});
Expand Down Expand Up @@ -1093,6 +1095,21 @@ const agent = createAgent({
});
```

The resulting system message will be:
```typescript
new SystemMessage({
content: [
{ type: "text", text: "You are a helpful assistant." },
{ type: "text", text: "Additional context." },
{
type: "text",
text: " More additional context. This will be cached.",
cache_control: { type: "ephemeral", ttl: "5m" },
},
],
});
```

Use @[`SystemMessage.concat`] to preserve cache control metadata or structured content blocks created by other middleware.

:::
Expand Down
Loading