Skip to content

Base Classes and Exceptions

cortex_agents.base.BaseAgent

BaseAgent(account_url: str | None = None, pat: str | None = None, enable_logging: bool = True, token_type: str | None = None)

Bases: ABC

Base class for Cortex Agent and Analyst clients.

Provides shared functionality for credential management and validation, URL construction, and request/response logging.

Attributes:

Name Type Description
account_url str

Snowflake account URL.

pat str

Personal access token.

Initialize base agent.

Parameters:

Name Type Description Default
account_url str | None

Snowflake account URL. Defaults to SNOWFLAKE_ACCOUNT_URL environment variable.

None
pat str | None

Personal access token. Defaults to SNOWFLAKE_PAT environment variable.

None
enable_logging bool

Enable request/response logging. Defaults to True.

True
token_type str | None

Authorization token type. Set to "KEYPAIR_JWT" when authenticating with a key-pair JWT instead of a PAT. When provided, the X-Snowflake-Authorization-Token-Type header is included in all requests.

None
Source code in cortex_agents/base.py
def __init__(
    self,
    account_url: str | None = None,
    pat: str | None = None,
    enable_logging: bool = True,
    token_type: str | None = None,
) -> None:
    """Initialize base agent.

    Args:
        account_url: Snowflake account URL. Defaults to SNOWFLAKE_ACCOUNT_URL
            environment variable.
        pat: Personal access token. Defaults to SNOWFLAKE_PAT environment
            variable.
        enable_logging: Enable request/response logging. Defaults to True.
        token_type: Authorization token type. Set to ``"KEYPAIR_JWT"`` when
            authenticating with a key-pair JWT instead of a PAT. When
            provided, the ``X-Snowflake-Authorization-Token-Type`` header
            is included in all requests.
    """
    self._enable_logging = enable_logging
    self._token_type = token_type
    self.account_url: str
    self.pat: str
    self.account_url, self.pat = self._load_credentials(account_url, pat)

close abstractmethod

close() -> None

Close and cleanup resources.

Source code in cortex_agents/base.py
@abstractmethod
def close(self) -> None:
    """Close and cleanup resources."""
    pass

cortex_agents.base.SnowflakeAPIError

SnowflakeAPIError(message: str, status_code: int | None = None, request_id: str | None = None, response_body: str | None = None)

Bases: Exception

Custom exception for Snowflake API errors.

Attributes:

Name Type Description
message

Error message

status_code

HTTP status code (if applicable)

request_id

Snowflake request ID (if applicable)

response_body

Raw response body (if applicable)

Source code in cortex_agents/base.py
def __init__(
    self,
    message: str,
    status_code: int | None = None,
    request_id: str | None = None,
    response_body: str | None = None,
) -> None:
    self.message = message
    self.status_code = status_code
    self.request_id = request_id
    self.response_body = response_body
    super().__init__(self.message)