See below, agent trace. Notice the python error, and how the agent essentially plows on, abandoning the effort to gather the information it needed from the original tool call attempt.
Two things:
-
The agents consistently ignore the venv configuration of the current project when issuing commands. What is the best way to fix this issue? E.g., I’m not sure where in Cursor would be the best place to admonish the AI to always use the venv python when issuing commands…
-
When errors related to the python environment occur, the agents consistently abandon the test they were trying and continue without noticing there is a simple fix (use the venv) for the issue.
One way to fix the issue would be to ensure that the execution environment of the agent is always in the venv, but I don’t know where to configure that execution environment – e.g., so I can cause the agent’s shell to always run a config (.bashrc etc) preamble…
It’s not clear to me whether the right approach is to define a SKILL (e.g., called “run-python”) or create a user RULE or what; and it’s also not clear how to ensure the agents don’t assume a failed tool call to run some debug code is not immediately abandoned, which I’ve seen happen even when fixing that failure is relevant to addressing the user’s prompt.
Agent Trace
I see the issue! The model is being loaded 4 times even though the cache shows only 1 model. This suggests the problem is happening inside the SentenceTransformer initialization, not at our caching layer. Let me investigate what’s happening.
python3 -c "
import sys
sys.path.insert(0, 'rag_component')
# Test if SentenceTransformer loads multiple times on init
print('Testing SentenceTransformer initialization...')
from sentence_transformers import SentenceTransformer
print('\\nLoading model for the FIRST time:')
model1 = SentenceTransformer('all-MiniLM-L6-v2')
print('Model 1 loaded')
print('\\nLoading model for the SECOND time (should use HF cache):')
model2 = SentenceTransformer('all-MiniLM-L6-v2')
print('Model 2 loaded')
print('\\nBoth models are same object?', model1 is model2)
print('Test complete')
"
Output:
Testing SentenceTransformer initialization...
Traceback (most recent call last):
File "<string>", line 7, in <module>
from sentence_transformers import SentenceTransformer
ModuleNotFoundError: No module named 'sentence_transformers'
The module isn’t installed in the global Python. Let me check if the issue is related to how sentence-transformers internally loads models. The problem is that even though our cache is working (showing 1 model), we’re seeing 4 separate “Loading weights” progress bars.
Let me check the sentence-transformers source code behavior and see if there’s verbosity settings or if it’s loading sub-models.
Let me check if there’s something in the SentenceTransformer initialization that causes multiple loads, and examine the actual flow when files are dropped: