diff --git a/autogpt_platform/backend/backend/api/features/chat/tools/utils.py b/autogpt_platform/backend/backend/api/features/chat/tools/utils.py index 4f514c5524..c48cd09458 100644 --- a/autogpt_platform/backend/backend/api/features/chat/tools/utils.py +++ b/autogpt_platform/backend/backend/api/features/chat/tools/utils.py @@ -8,6 +8,7 @@ from backend.api.features.library import model as library_model from backend.api.features.store import db as store_db from backend.data.graph import GraphModel from backend.data.model import ( + Credentials, CredentialsFieldInfo, CredentialsMetaInput, HostScopedCredentials, @@ -288,13 +289,15 @@ def find_matching_credential( available_creds: list[Credentials], field_info: CredentialsFieldInfo, ) -> Credentials | None: - """Find a credential that matches the required provider, type, and scopes.""" + """Find a credential that matches the required provider, type, scopes, and host.""" for cred in available_creds: if cred.provider not in field_info.provider: continue if cred.type not in field_info.supported_types: continue - if not _credential_has_required_scopes(cred, field_info): + if cred.type == "oauth2" and not _credential_has_required_scopes(cred, field_info): + continue + if cred.type == "host_scoped" and not _credential_is_for_host(cred, field_info): continue return cred return None