Skip to content

Commit

Permalink
fix: on topic guardrail
Browse files Browse the repository at this point in the history
changes guardrail's prompt to take into consideration the conversation instead of just the latest message.
changes the agent's messages to be AI to give the guardrail an opportunity to distinguish between user and ai messages correctly.
  • Loading branch information
Erez Sharim committed Aug 14, 2024
1 parent 71921a7 commit 7ad7b8d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/llm/guardrails/on_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ def on_topic_guard():
"assistant capabilities inquiry",
"information gathering about applications",
"information gathering about access",
"asking for clarification about the conversation or previous messages",
"action repetition request",
]
template = """
Your job is to determine if the user's input is on topic.
Your job is to determine if the conversation is on topic.
Any of the following topics are allowed, together or individually:
{allowed_topics}
The conversation is valid if the entire conversation is on topic or if the latest human message
tries to bring it back on topic.
{format_instructions}
"""
pv = {
Expand Down
4 changes: 2 additions & 2 deletions app/llm/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import json
from types import coroutine

from langchain_core.messages import AIMessage, HumanMessage, ToolMessage
from langchain_core.messages import AIMessage, ToolMessage

from app.llm.guardrails.on_topic import topical_guardrail
from app.llm.tools.deny_access_tool import create_deny_provision_tool
Expand Down Expand Up @@ -43,7 +43,7 @@ def agent_node(state, agent_creator, name):
if isinstance(result, ToolMessage):
pass
else:
result = HumanMessage(content=result["output"], name=name)
result = AIMessage(content=result["output"], name=name)

return {
MEMORY_KEY: [result],
Expand Down

0 comments on commit 7ad7b8d

Please sign in to comment.