Find answers from the community

Updated 2 months ago

Langchain agent

Thanks, but how to add it into the agent? I’m not using a query function
L
p
17 comments
You'll have to change the agent prompt. This is usually controlled using the "prefix" parameter, and the prefix defaults to an explanation of the agent being an assistant and it can do all these things Blah blah lol
Where do I need to put that prompt?? 😭

Plain Text
retriever = PineconeHybridSearchRetriever(embeddings=embeddings, index=index, tokenizer=tokenizer, top_k=3)

retrieval_qa = RetrievalQA.from_chain_type(llm=llm, chain_type="map_rerank", retriever=retriever)


tools = [
    Tool(
        name="IUTH",
        func=retrieval_qa.run,
        description="useful for when you need to answer questions about IUTH university, also known as мутиг/вуз/университет/university."
    )
]

agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True, max_iterations=3, early_stopping_method="generate")

response_text = agent.run(query)
Inside initialize agent

..., agent_kwargs={"prefix": "my prompt"})
I just used this yesterday actually lol had to read source code to figure it out
If you change the agent type, you might need to adjust the prefix slightly. You can see which agent is mapped to which type here
https://github.com/hwchase17/langchain/blob/master/langchain/agents/loading.py#L21
Thank you Logan! I don't know what I'd do without your help 😭
💪 :dotsHARDSTYLE:
well 🙂 seems like it does not follow my instructions...
Plain Text
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True, max_iterations=3,
                         early_stopping_method="force",
                         prefix="Answer the following questions in Russian (IMPORTANT) as best you can. You have access to the following tools:",
                         suffix=
                         """Reply with a greeting if the user has just greeted you and don't forget to always respond in Russian language! Begin!
Question: {input}
Thought: {agent_scratchpad}
""")
and it responds in English
You missed something
You need to pass prefix and suffix under the agent_kwargs variable

initialize_agent(..., agent_kwargs={"prefix": ..., "suffix": ...})
Oh gosh... Let me try 🙇‍♂️
Add a reply
Sign up and join the conversation on Discord