Skip to content

Commit 33cf6cb

Browse files
sasha-gitgcopybara-github
authored andcommitted
fix: raise eagerly on importing AgentRegistry if a2a-sdk is missing
- Clean up the unused private _ProtocolType import Co-authored-by: Sasha Sobran <asobran@google.com> PiperOrigin-RevId: 913817935
1 parent 2d423e8 commit 33cf6cb

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

src/google/adk/integrations/agent_registry/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from .agent_registry import _ProtocolType
1615
from .agent_registry import AgentRegistry
1716

1817
__all__ = [

src/google/adk/integrations/agent_registry/agent_registry.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,7 @@
2828
from typing import TypedDict
2929
from urllib.parse import urlparse
3030

31-
from a2a.types import AgentCapabilities
32-
from a2a.types import AgentCard
33-
from a2a.types import AgentSkill
34-
from a2a.types import TransportProtocol as A2ATransport
3531
from google.adk.agents.readonly_context import ReadonlyContext
36-
from google.adk.agents.remote_a2a_agent import RemoteA2aAgent
3732
from google.adk.auth.auth_credential import AuthCredential
3833
from google.adk.auth.auth_schemes import AuthScheme
3934
from google.adk.integrations.agent_identity.gcp_auth_provider_scheme import GcpAuthProviderScheme
@@ -49,6 +44,20 @@
4944
from mcp import StdioServerParameters
5045
from typing_extensions import override
5146

47+
# pylint: disable=g-import-not-at-top
48+
try:
49+
from a2a.types import AgentCapabilities
50+
from a2a.types import AgentCard
51+
from a2a.types import AgentSkill
52+
from a2a.types import TransportProtocol as A2ATransport
53+
from google.adk.agents.remote_a2a_agent import RemoteA2aAgent
54+
except ImportError as e:
55+
raise ImportError(
56+
"AgentRegistry requires the 'a2a-sdk' package. "
57+
"Please install it using 'pip install google-adk[a2a]'."
58+
) from e
59+
# pylint: enable=g-import-not-at-top
60+
5261
logger = logging.getLogger("google_adk." + __name__)
5362

5463
AGENT_REGISTRY_BASE_URL = "https://agentregistry.googleapis.com/v1alpha"

tests/unittests/integrations/agent_registry/test_agent_registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
from google.adk.agents.remote_a2a_agent import RemoteA2aAgent
2323
from google.adk.auth.auth_credential import AuthCredential
2424
from google.adk.auth.auth_credential import OAuth2Auth
25-
from google.adk.integrations.agent_registry import _ProtocolType
2625
from google.adk.integrations.agent_registry import AgentRegistry
26+
from google.adk.integrations.agent_registry.agent_registry import _ProtocolType
2727
from google.adk.telemetry.tracing import GCP_MCP_SERVER_DESTINATION_ID
2828
from google.adk.tools.mcp_tool.mcp_toolset import McpToolset
2929
import httpx

0 commit comments

Comments
 (0)