-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: agent jump example, enhanced state docs for JS and more #1590
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
…ware (#1587) More clarity on changing behavior of dynamic system prompt middleware
|
Mintlify preview ID generated: preview-cbimpr-1763851614-4162242 |
|
Mintlify preview ID generated: preview-cbimpr-1763852422-6d89282 |
|
Mintlify preview ID generated: preview-cbimpr-1763853024-4a27815 |
|
Mintlify preview ID generated: preview-cbimpr-1763853761-497e4b2 |
| beforeModel: { | ||
| canJumpTo: ["end"], | ||
| hook: (state) => { | ||
| if (state.messages.at(-1)?.content.includes("BLOCKED")) { | ||
| return { | ||
| messages: [new AIMessage("I cannot respond to that request.")], |
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.
| beforeModel: { | |
| canJumpTo: ["end"], | |
| hook: (state) => { | |
| if (state.messages.at(-1)?.content.includes("BLOCKED")) { | |
| return { | |
| messages: [new AIMessage("I cannot respond to that request.")], | |
| afterModel: { | |
| canJumpTo: ["end"], | |
| hook: (state) => { | |
| if (state.messages.at(-1)?.content.includes("BLOCKED")) { | |
| return { | |
| messages: [ | |
| ...state.messages.slice(0, -1), | |
| { | |
| ...state.messages.at(-1), | |
| content: "I cannot respond to that request." | |
| } | |
| ], |
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.
It might be better if we had an afterModel example that updates the agent message, either here or in the guardrails docs. What do you think?
Edit: Actually, we already have this in guardrails, but using afterAgent. Having another example with afterModel still makes sense.
| ``` | ||
|
|
||
| const result = await agent.invoke({ | ||
| messages: "Hello, world! BLOCKED" |
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.
| messages: "Hello, world! BLOCKED" | |
| messages: "Hello, world! Return a message that contains BLOCKED" |
|
Closing in favor of #1608 |
Some further improvements on: