langchain
langchain copied to clipboard
Question: System messages with AgentExecutors
Hi!
I am working with AgentExecutors, which are being created with the create_llama_chat_agent() function. The relevant part of the code looks like this:
llm = OpenAI(temperature=0, model_name="gpt-3.5-turbo")
return create_llama_chat_agent(
toolkit,
llm,
memory=memory,
verbose=True
)
It works perfectly, but I want to add system messages to every request. Can you help me with this? Every answer is appreciated, if you have an alternative for system messages, that could be useful as well. My use-case is that I have a document describing how should I handle different type of users. I am trying to pass the type of the user in system messages so the AI can response according to the system message and the description provided in context.
Thanks in advance!
Here's an example for using a custom system message
Here's the relevant snippet for your own custom agent:
class ChatZeroShotAgent(ZeroShotAgent):
@classmethod
def create_prompt(
cls,
tools: Sequence[BaseTool]
) -> PromptTemplate:
tool_strings = "\n".join(
[f" {tool.name}: {tool.description}" for tool in tools]
)
tool_names = ", ".join([tool.name for tool in tools])
format_instructions = FORMAT_INSTRUCTIONS.format(
tool_names=tool_names, tool_strings=tool_strings
)
human_prompt = PromptTemplate(
template=QUESTION_PROMPT,
input_variables=["input"],
partial_variables={"tool_strings": tool_strings},
)
human_message_prompt = HumanMessagePromptTemplate(prompt=human_prompt)
ai_message_prompt = AIMessagePromptTemplate.from_template(SUFFIX)
system_message_prompt = SystemMessagePromptTemplate.from_template(
format_instructions
)
return ChatPromptTemplate.from_messages(
[system_message_prompt, human_message_prompt, ai_message_prompt]
)
Hi, @pelyhe! I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.
From what I understand, the issue is about adding system messages to requests made with AgentExecutors in the OpenAI API. The user wants to pass the type of user in system messages to get AI responses tailored to the user type. User whitead has provided an example for using a custom system message and shared a relevant code snippet for creating a custom agent.
Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself or it will be automatically closed in 7 days.
Thank you for your contribution!