-
Notifications
You must be signed in to change notification settings - Fork 45
langchain: dynamic system prompt w/ middleware docs #592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds documentation for dynamic system prompts using middleware in LangChain agents. The feature allows developers to modify system prompts dynamically at runtime based on context or agent state.
- Adds
DynamicSystemPromptMiddleware
documentation to the middleware page with comprehensive examples - Integrates dynamic prompt examples into the agents page to show practical usage
- Updates navigation and cross-references between middleware and agents documentation
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/oss/langchain/middleware.mdx | Adds complete documentation section for DynamicSystemPromptMiddleware with examples for both context-based and conversation-length-based prompts |
src/oss/langchain/agents.mdx | Adds a subsection on dynamic prompts with middleware to show integration with agent creation |
Preview ID generated: preview-srdyna-1758241143-49d6752 |
Co-authored-by: Christian Bromann <[email protected]>
Co-authored-by: Christian Bromann <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
Preview ID generated: preview-srdyna-1758245605-9bcb701 |
Co-authored-by: Christian Bromann <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
Preview ID generated: preview-srdyna-1758309488-c704e9e |
Preview ID generated: preview-srdyna-1758663482-f8412db |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Preview ID generated: preview-srdyna-1758663628-24b4adb |
5b4fb93
to
668b0f0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Preview ID generated: preview-srdyna-1758745243-7ad6f94 |
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
|
||
```python | ||
from typing import TypedDict | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import order doesn't follow Python conventions. Standard library imports should come first, followed by third-party imports, then local imports. Move from typing import TypedDict
to the top of the imports section.
Copilot uses AI. Check for mistakes.
user_role: str | ||
|
||
@modify_model_request | ||
def dynamic_system_prompt(state: AgentState, request: ModelRequest, runtime: Runtime[Context]) -> ModelRequest: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ModelRequest
type is referenced but never imported or defined in the example. This will cause import errors when users try to run the code. Add the necessary import statement.
Copilot uses AI. Check for mistakes.
|
||
const agent = createAgent({ | ||
model: "openai:gpt-4o", | ||
tools: [...], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ellipsis [...]
in the tools array is unclear and not valid TypeScript syntax. Replace with a comment like // your tools here
or show actual tool examples for clarity.
tools: [...], | |
tools: [/* your tools here */], |
Copilot uses AI. Check for mistakes.
user_role: str | ||
|
||
@modify_model_request | ||
def dynamic_system_prompt(state: AgentState, request: ModelRequest, runtime: Runtime[Context]) -> ModelRequest: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the middleware.mdx file, the ModelRequest
type is used without being imported. Add the necessary import statement to make this example runnable.
Copilot uses AI. Check for mistakes.
|
||
const agent = createAgent({ | ||
model: "openai:gpt-4o", | ||
tools: [/* ... */], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment /* ... */
in the tools array should be more descriptive. Consider using /* your tools here */
or provide an actual example tool to make the documentation more helpful.
tools: [/* ... */], | |
tools: [ | |
{ | |
name: "calculator", | |
description: "Performs basic arithmetic operations", | |
func: async ({ a, b }) => a + b, | |
}, | |
], |
Copilot uses AI. Check for mistakes.
Preview ID generated: preview-srdyna-1758745406-14f2e46 |
In Python we're now exposing decorators that can be used to generate simple middlewares w/ one hook.
TBD what we're doing in JS.