Prevent Langgraph Agent from searching for answers outside the tools #326
Replies: 2 comments 1 reply
-
🤖 Hey @Stallonaros, great to see you diving into another challenge with LangChain! How's everything going on your end? Based on your question, it seems like you want to restrict the LangChain agent to only use the specified tools (retriever tool and Jira connection) for answering questions, and prevent it from generating answers based on its own knowledge. You can achieve this by creating a conversational retrieval agent and passing the desired tools to the from langchain.tools import RetrieverTool, JiraConnectionTool
from langchain_core.language_models import ChatOpenAI
# Initialize the tools
retriever_tool = RetrieverTool()
jira_connection_tool = JiraConnectionTool()
# Initialize the language model
llm = ChatOpenAI()
# Create the agent
agent = create_conversational_retrieval_agent(
llm=llm,
tools=[retriever_tool, jira_connection_tool],
remember_intermediate_steps=False
) In this example, You can find more details in the openai_functions.py file. Additionally, you can ensure that the language model only returns answers that are present in the ingested TXT database, rather than using its pre-trained information. This can be achieved by using the Here is the relevant code: QUESTION_PROMPT = PromptTemplate(
template=question_prompt_template, input_variables=["context", "question"]
)
combine_prompt_template = """Given the following extracted parts of a long document and a question, create a final answer with references ("SOURCES").
If you don't know the answer, just say that you don't know. Don't try to make up an answer.
ALWAYS return a "SOURCES" part in your answer.
QUESTION: {question}
=========
{summaries}
=========
FINAL ANSWER:"""
COMBINE_PROMPT = PromptTemplate(
template=combine_prompt_template, input_variables=["summaries", "question"]
) You can find more details in the map_reduce_prompt.py file. I hope this helps! Let me know if you have any other questions. Sources
|
Beta Was this translation helpful? Give feedback.
-
is it complusry to use tools in langraph |
Beta Was this translation helpful? Give feedback.
-
Checked other resources
Commit to Help
Example Code
Description
Hello , i am trying to implement a langgraph with using 2 tools, one tool is the retriever tool which searches on the embedded docs and another one which i use to connect to jira, i dont want the agent to use only these tools to answer questions and not trying to answer on its own, if i dont specify to the agent to search the docs or the jira, agent will answer based on its own knowledge. Is there a way to prevent this?
System Info
Package Information
Beta Was this translation helpful? Give feedback.
All reactions