langchain icon indicating copy to clipboard operation
langchain copied to clipboard

Error communicating with OpenAI when running agent in async

Open usama04 opened this issue 1 year ago • 4 comments

Hi fellas. Langchain is awesome. I have an agent that I created for an app and it will be interacted with via an api. The agent of course needs to run asynchronously. I can run it without any issues synchronously but with agent.arun(inputs) I cannot connect with openai. It throws the "Error communicating with OpenAI" error. before I followed this notebook with my own amends to the task at hand: https://python.langchain.com/en/latest/modules/agents/agents/custom_llm_chat_agent.html and just changed the final part from agent.run to agent.arun according to the blogpost. But clearly this wasnt enough and I went on youtube and came accross this video: https://youtu.be/eAikW9o1Ros I followed what he was doing for a simple agent and customized mine by creating this function: async def async_agent_executor(inputs): manager = CallbackManager([StdOutCallbackHandler()]) llm = ChatOpenAI(temperature=0, callback_manager=manager) llm_chain = LLMChain(llm=llm, prompt=custom_prompt, callback_manager=manager) async_tools = load_tools(["serpapi"], llm=llm, callback_manager=manager) agent = LLMSingleActionAgent( llm_chain=llm_chain, output_parser=output_parser, stop=["\nObservation:"], allowed_tools=tool_names, callback_manager=manager ) agent_executor = AgentExecutor.from_agent_and_tools(agent=agent, tools=async_tools, verbose=True, callback_manager=manager) return await agent_executor.arun(inputs)

I dont have too much experience working with async as well. Can you please help why it cannot connect with OpenAI in serial execution but not in async? Thank you.

usama04 avatar Apr 18 '23 04:04 usama04

How's your progress on this? Also to check, would an agent not be expected to run sequentially rather than async, since it has a thought process (ReAct framework) to follow?

kennethleungty avatar Apr 27 '23 03:04 kennethleungty

How's your progress on this? Also to check, would an agent not be expected to run sequentially rather than async, since it has a thought process (ReAct framework) to follow?

I have discovered what was the problem. It is my VPN on which, openai Async didnt work. Therefore the async function of the Agent executor (arun) also didnt work as my agent is based on ChatOpenai.

Which to the second part. There are sync tools and async tools. Agents can run asynchronously. Openai also also allows asynchronous API calls. You can look into that documentation. The reason I needed an Async Agent is because I have deployed in a project that already has users. You can take a look at it. https://aalimbot.com . Async allows for handling several requests at once from users of this project. So far, I have not seen performance degradation.

usama04 avatar Apr 28 '23 16:04 usama04

If you are using a Mac computer, please use ClashX Pro and enable the Enhanced Mode to solve this problem.

Lil-Vincent avatar May 02 '23 12:05 Lil-Vincent

Installing the python certificate works for me: https://stackoverflow.com/questions/27835619/urllib-and-ssl-certificate-verify-failed-error

I'm using macOS with no vpn.

ericlin94 avatar May 13 '23 17:05 ericlin94

bash /Applications/Python*/Install\ Certificates.command

fixed it for me. I'm on MacOS

tonyadastra avatar Jul 18 '23 16:07 tonyadastra

How's your progress on this? Also to check, would an agent not be expected to run sequentially rather than async, since it has a thought process (ReAct framework) to follow?

I have discovered what was the problem. It is my VPN on which, openai Async didnt work. Therefore the async function of the Agent executor (arun) also didnt work as my agent is based on ChatOpenai.

Which to the second part. There are sync tools and async tools. Agents can run asynchronously. Openai also also allows asynchronous API calls. You can look into that documentation. The reason I needed an Async Agent is because I have deployed in a project that already has users. You can take a look at it. https://aalimbot.com . Async allows for handling several requests at once from users of this project. So far, I have not seen performance degradation.

I've faced the same problem caused by VPN, have you solved this?

NiDHanWang avatar Aug 14 '23 08:08 NiDHanWang

Hi, @usama04! I'm Dosu, and I'm here to help the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.

Based on my understanding, you were experiencing an issue with running your agent asynchronously with OpenAI. You mentioned that the problem was caused by your VPN, which was preventing the async function of the Agent executor from working. You mentioned that you needed an async agent because you have deployed it in a project with multiple users. Some users suggested using ClashX Pro or installing the Python certificate to solve the issue.

Before we close this issue, we wanted to check if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on this issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.

Thank you for your understanding and cooperation. Let us know if you have any further questions or concerns!

Best regards, Dosu

dosubot[bot] avatar Nov 13 '23 16:11 dosubot[bot]