L3: Multi-agent Customer Support Automation. OpenAI API Connection Error

While trying to execute the code for the lesson L3: Multi-agent Customer Support Automation. I am getting error as openai.APIConnectionError: Connection error.

This is the full Error Stack trace below,
Traceback (most recent call last):
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\httpx_transports\default.py”, line 67, in map_httpcore_exceptions
yield
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\httpx_transports\default.py”, line 231, in handle_request
resp = self._pool.handle_request(req)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\httpcore_sync\connection_pool.py”, line 216, in handle_request
raise exc from None
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\httpcore_sync\connection_pool.py”, line 196, in handle_request
response = connection.handle_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\httpcore_sync\connection.py”, line 99, in handle_request
raise exc
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\httpcore_sync\connection.py”, line 76, in handle_request
stream = self._connect(request)
^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\httpcore_sync\connection.py”, line 154, in _connect
stream = stream.start_tls(**kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\httpcore_backends\sync.py”, line 152, in start_tls
with map_exceptions(exc_map):
File “C:\Users\abera\AppData\Local\Programs\Python\Python311\Lib\contextlib.py”, line 155, in exit
self.gen.throw(typ, value, traceback)
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\httpcore_exceptions.py”, line 14, in map_exceptions
raise to_exc(exc) from exc
httpcore.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1002)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\openai_base_client.py”, line 952, in _request
response = self._client.send(
^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\httpx_client.py”, line 915, in send
response = self._send_handling_auth(
^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\httpx_client.py”, line 943, in _send_handling_auth
response = self._send_handling_redirects(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\httpx_client.py”, line 980, in _send_handling_redirects
response = self._send_single_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\httpx_client.py”, line 1016, in _send_single_request
response = transport.handle_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\httpx_transports\default.py”, line 230, in handle_request
with map_httpcore_exceptions():
File “C:\Users\abera\AppData\Local\Programs\Python\Python311\Lib\contextlib.py”, line 155, in exit
self.gen.throw(typ, value, traceback)
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\httpx_transports\default.py”, line 84, in map_httpcore_exceptions
raise mapped_exc(message) from exc
httpx.ConnectError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1002)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “C:\Users\abera\Documents\genai_test\src\crewai_test.py”, line 136, in
result = crew.kickoff(inputs=inputs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\crewai\crew.py”, line 252, in kickoff
result = self._run_sequential_process()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\crewai\crew.py”, line 293, in _run_sequential_process
output = task.execute(context=task_output)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\crewai\task.py”, line 173, in execute
result = self._execute(
^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\crewai\task.py”, line 182, in _execute
result = agent.execute_task(
^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\crewai\agent.py”, line 207, in execute_task
memory = contextual_memory.build_context_for_task(task, context)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\crewai\memory\contextual\contextual_memory.py”, line 22, in build_context_for_task
context.append(self._fetch_stm_context(query))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\crewai\memory\contextual\contextual_memory.py”, line 31, in _fetch_stm_context
stm_results = self.stm.search(query)
^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\crewai\memory\short_term\short_term_memory.py”, line 23, in search
return self.storage.search(query=query, score_threshold=score_threshold)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\crewai\memory\storage\rag_storage.py”, line 90, in search
else self.app.search(query, limit)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\embedchain\embedchain.py”, line 635, in search
return [{“context”: c[0], “metadata”: c[1]} for c in self.db.query(**params)]
^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\embedchain\vectordb\chroma.py”, line 220, in query
result = self.collection.query(
^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\chromadb\api\models\Collection.py”, line 327, in query
valid_query_embeddings = self._embed(input=valid_query_texts)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\chromadb\api\models\Collection.py”, line 633, in _embed
return self._embedding_function(input=input)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\chromadb\api\types.py”, line 193, in call
result = call(self, input)
^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\chromadb\utils\embedding_functions.py”, line 188, in call
embeddings = self._client.create(
^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\openai\resources\embeddings.py”, line 114, in create
return self._post(
^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\openai_base_client.py”, line 1240, in post
return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\openai_base_client.py”, line 921, in request
return self._request(
^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\openai_base_client.py”, line 976, in _request
return self._retry_request(
^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\openai_base_client.py”, line 1053, in _retry_request
return self._request(
^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\openai_base_client.py”, line 976, in _request
return self._retry_request(
^^^^^^^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\openai_base_client.py”, line 1053, in _retry_request
return self._request(
^^^^^^^^^^^^^^
File “C:\Users\abera\Documents\genai_test\venv\Lib\site-packages\openai_base_client.py”, line 986, in _request
raise APIConnectionError(request=request) from err
openai.APIConnectionError: Connection error.

After some triaging, I noticed that this error is coming when memory is enabled in the crew instance. if I remove the memory attribute, then I don’t get the error. Please help me identify this issue.

Note: I am running this code behind my company VPN network, so that may or may not be the issue.

Hi @Ankan54,

I have seen others complain about this as well. And their solution is the same as you described, to disable memory. For now, do that.

I’ll look into this in detail to see why this is happening.

Best,
Mubsi

Hi @Ankan54,

I was able to run the notebook with memory=True and it worked for me on the platform and locally.

Where were you trying to run the lab ?

Best,
Mubsi

In VS code as python file. I am using company laptop so behind company vpn network. Could that be the issue?

Hi @Ankan54,

That’s a possibility, that the VPN might be interfering with it.

You mentioned you are running locally using VS code. What do you get when you try to run the code on the platform, in the Jupyter notebook we have provided ?

Best,
Mubsi

I can’t run from the platform as the azure openai service I am using won’t connect from there. I have run from jupyter notebook locally within the vs code app, same issue.

Meanwhile, can you please guide me how to connect to any external memory components with crewai.
I am using postgres as vector DB. maybe I can use that server as the memory of the agent,which should be allowed by the VPN.

Hi @Ankan54,

The error you get says the same, you are getting a connection error, which means you are not able to connect to the open ai server when memory is set to true. Sadly, I don’t know how to help you with this, I don’t see why this should be an issue.

crewAI documentation has all the information you’d need for your questions. I don’t have much knowledge of crewAI outside of this course, so I can’t help you with that as well.

Best,
Mubsi