Closed Travis-Barton closed 1 year ago
You could check out https://python.langchain.com/en/latest/modules/agents/toolkits.html# for inspiration.
Related blog: https://blog.langchain.dev/agent-toolkits/
@Travis-Barton - Were you able to make this work? I'm stuck here as well.
@matthiasthomas yeah! I did this:
from langchain.agents import ZeroShotAgent, Tool, AgentExecutor
from langchain import OpenAI, LLMChain
from langchain.utilities import GoogleSearchAPIWrapper
from langchain import OpenAI, LLMMathChain, SerpAPIWrapper
from langchain.agents import initialize_agent, Tool
from langchain.chat_models import ChatOpenAI
from langchain.memory import ConversationBufferMemory
import os
os.environ["OPENAI_API_KEY"] = "..."
os.environ["SERPAPI_API_KEY"] = "..."
llm = ChatOpenAI(temperature=0)
llm1 = OpenAI(temperature=0)
search = SerpAPIWrapper()
llm_math_chain = LLMMathChain(llm=llm1, verbose=True)
tools = [
Tool(
name="Search",
func=search.run,
description="useful for when you need to answer questions about current events. "
"You should ask targeted questions"
)
]
prefix = """Have a conversation with a human, answering the following questions as best you can. You have access to the following tools:"""
suffix = """Begin!"
{chat_history}
Question: {input}
{agent_scratchpad}"""
prompt = ZeroShotAgent.create_prompt(
tools,
prefix=prefix,
suffix=suffix,
input_variables=["input", "chat_history", "agent_scratchpad"]
)
memory = ConversationBufferMemory(memory_key="chat_history")
llm_chain = LLMChain(llm=OpenAI(temperature=0), prompt=prompt)
agent = ZeroShotAgent(llm_chain=llm_chain, tools=tools, verbose=True)
agent_chain = AgentExecutor.from_agent_and_tools(agent=agent, tools=tools, verbose=True, memory=memory)
agent_chain.run(input="How many people live in canada?")
agent_chain.run(input="Whats the national Anthem of that nation?")
agent_chain.run(input="What is the capital of that nation?")
Were you able to fix this?
/usr/local/lib/python3.9/dist-packages/langchain/agents/agent.py", line 792, in _call
next_step_output = self._take_next_step(
File "/usr/local/lib/python3.9/dist-packages/langchain/agents/agent.py", line 672, in _take_next_step
output = self.agent.plan(intermediate_steps, **inputs)
File "/usr/local/lib/python3.9/dist-packages/langchain/agents/agent.py", line 385, in plan
return self.output_parser.parse(full_output)
File "/usr/local/lib/python3.9/dist-packages/langchain/agents/mrkl/output_parser.py", line 20, in parse
raise ValueError(f"Could not parse LLM output: `{text}`")
ValueError: Could not parse LLM output: `Thought: This is just a greeting, no specific action needed.`
@Kav-K I was not, I just changed my method
@Travis-Barton Can you please share the code that worked, i have the same issue. Thanks
I was having the same issue, and I used this approach and worked.
tools = [
Tool(
name="Search",
func=search.run,
description="useful for when you need to answer questions about current events. "
"You should ask targeted questions"
)
]
llm = ChatOpenAI(temperature=1, client=None)
memory = ConversationSummaryBufferMemory(llm=llm, memory_key="chat_history", return_messages=True, human_prefix="user", ai_prefix="assistant")
system_prompt_template = " An AI Assistant .... "
custom_agent = ConversationalChatAgent.from_llm_and_tools(llm=llm, tools=tools, system_message=system_prompt_template)
agent_executor = AgentExecutor.from_agent_and_tools(agent=custom_agent, tools=tools, memory=memory)
agent_executor.verbose = True
print(agent_executor.run("How many people live in canada?"))
Basically this uses LLMChain under the hood and the key is this ConversationalChatAgent
class
Hi, @Travis-Barton! 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.
Based on the comments, it seems like you encountered an error when trying to instantiate the ConversationChain
class to create a conversational bot with memory, agents, and tools. However, you were able to resolve the issue by checking out the documentation and related blog for inspiration. Great job on finding a solution!
On the other hand, Kav-K encountered a different error and asked for help, but it remains unresolved at the moment. If you are still experiencing the same issue or have any updates, please let the LangChain team know by commenting on this issue.
If the issue is no longer relevant or you have resolved it yourself, feel free to close the issue. Otherwise, if there is no further activity, the issue will be automatically closed in 7 days.
Thank you for your contribution to the LangChain repository!
Hey all,
I'm trying to make a bot that can use the math and search functions while still using tools. What I have so far is this:
Unfortunately the last line gives this error:
How can I make a conversational bot that also has access to tools/agents and has memory?
(preferably with load_tools)