Add System message in the LLMSingleActionAgent
Labels: name: area: agent, name: auto:improvement

### Issue you'd like to raise.

template = """Answer the following questions as best you can. You have access to the following tools:

{tools}
{chat_history}

Use the following format:

Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question

Begin!  



Question: {input}
{agent_scratchpad}

"""
tool_names = [tool.name for tool in tools]
agent = LLMSingleActionAgent(
    llm_chain=llm_chain, 
    output_parser=output_parser,
    stop=["\nObservation:"], 
    allowed_tools=tool_names, 
)

agent_executor = AgentExecutor.from_agent_and_tools(agent=agent, 
                                                    tools=tools,
                                                    verbose=True,
                                                    memory = memory,
                                                    system_message = system_message, 
                                                    agent_kwargs = agent_kwargs,
                                                    handle_parsing_errors=True,
                                                    )


template = """
after answering each user questions you MUST append a mutiple follow up question whose purpose it get the user to engage more with you based on the topic so that the conversation can keep flowing
Instructions
'''
1. Your task is to engage with the user and make the user take a trivia quiz alongside the chat . You will start by asking in the beginning ```Before we start, Do you want to play a trivia and get a chance to enter a draw to win a prize?``` If user gives a positive response
   then, you should take a quiz with 5 questions with 4 options each . Quiz should be taken from the following question bank {question_bank}.If the user says no you should ask randomly in between ```Do you want to play a trivia and get a chance to enter a draw to win a prize?``` If user gives a positive response
   then, you should take a quiz with 5 questions with 4 options each . Quiz should be taken from the following question bank {question_bank}. If the user says no and hasnt responded positively or a yes ever to take the quiz only and only then in the end you should ask the user ```Do you want to play a trivia and get a chance to enter a draw to win a prize?``` If user gives a positive response
   then, you should take a quiz with 5 questions with 4 options each . Quiz should be taken from the following question bank {question_bank}.
'''
Above Instructions should be strictly followed
""".format(question_bank = questions)

This is the following peice of code and I need to make this prompt in such as way that it would be able to take quiz whenever it is asked to take quiz. 

I need to pass system message in this so that it follows the provided instructions

This is the Link of the source code:-
https://python.langchain.com/docs/modules/agents/how_to/custom_agent_with_tool_retrieval



### Suggestion:

I tried to add the template as a system message but it was not able to follow the instructions


tool_names = [tool.name for tool in tools]
agent = LLMSingleActionAgent(
    llm_chain=llm_chain, 
    output_parser=output_parser,
    stop=["\nObservation:"], 
    allowed_tools=tool_names, 
)

agent_executor = AgentExecutor.from_agent_and_tools(agent=agent, 
                                                    tools=tools,
                                                    verbose=True,
                                                    memory = memory,
                                                    system_message = system_message, 
                                                    agent_kwargs = agent_kwargs,
                                                    handle_parsing_errors=True,
                                                    )


But this was not working

Source code link:-
https://python.langchain.com/docs/modules/agents/how_to/custom_agent_with_tool_retrieval