Closed chazzhou closed 1 month ago
To resolve the issue with the Google Gemini provider in Dify version 0.6.10, where calling the same tool twice at the same time causes an error, you need to ensure that the tool runtime is properly managed to handle concurrent invocations. Implementing a locking mechanism or using asynchronous calls can help manage concurrent tool invocations.
Here is a possible approach using a threading lock to ensure that the tool is not invoked concurrently:
from typing import Any
from threading import Lock
from core.tools.errors import ToolProviderCredentialValidationError
from core.tools.provider.builtin.google.tools.google_search import GoogleSearchTool
from core.tools.provider.builtin_tool_provider import BuiltinToolProviderController
class GoogleProvider(BuiltinToolProviderController):
_lock = Lock()
def _validate_credentials(self, credentials: dict[str, Any]) -> None:
with self._lock:
try:
GoogleSearchTool().fork_tool_runtime(
runtime={
"credentials": credentials,
}
).invoke(
user_id='',
tool_parameters={
"query": "test",
"result_type": "link"
},
)
except Exception as e:
raise ToolProviderCredentialValidationError(str(e))
This code introduces a threading lock (_lock
) to ensure that the GoogleSearchTool
is not invoked concurrently. The with self._lock
statement ensures that the block of code is executed by only one thread at a time, thus preventing concurrent invocations [1].
To continue talking to Dosu, mention @dosu.
Self Checks
Dify version
0.6.10
Cloud or Self Hosted
Cloud, Self Hosted (Docker), Self Hosted (Source)
Steps to reproduce
You can easily replicate this with the following DSL with Gemini 1.5 Pro:
✔️ Expected Behavior
❌ Actual Behavior
api\core\agent\fc_agent_runner.py
fails to process the function calls and save the agent thought correctly.Additional info:
FunctionCallAgentRunner(BaseAgentRunner)
class, specifically therun()
function.run()
function's logic.Suggestion: I'm happy to submit a PR to address this issue, but I believe it would be best handled by the Dify team members.
Please let me know if you need any further information or assistance.