Skip to content

Add Cortex Agent management methods to SnowflakeCortexAgentHook - #70101

Open
SameerMesiah97 wants to merge 2 commits into
apache:mainfrom
SameerMesiah97:SnowflakeCortexAgentHook-Extension
Open

Add Cortex Agent management methods to SnowflakeCortexAgentHook#70101
SameerMesiah97 wants to merge 2 commits into
apache:mainfrom
SameerMesiah97:SnowflakeCortexAgentHook-Extension

Conversation

@SameerMesiah97

@SameerMesiah97 SameerMesiah97 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Description

This change extends SnowflakeCortexAgentHook with support for managing Snowflake Cortex Agent Objects.

The hook now exposes methods to describe, list and delete Cortex Agents using the Snowflake Cortex Agent REST API. To support these endpoints, the internal request helper has been updated to accept optional query parameters while continuing to centralize authentication, request execution and error handling.

Rationale

The existing hook supports executing Cortex Agents through run_agent(), but the Snowflake Cortex Agent REST API also provides endpoints for managing Cortex Agent Objects. Exposing these operations through the hook allows users to inspect and manage agents without needing to invoke the REST API directly.

Adding query parameter support to the shared request helper also provides a reusable foundation for additional Cortex Agent management operations in future enhancements.

Tests

Added unit tests verifying that:

  • describe_agent() sends the expected request and returns the API response.
  • list_agents() correctly forwards optional query parameters and returns the list of agents.
  • delete_agent() issues the expected DELETE request, including both values of the if_exists parameter.
  • _request() returns {} for successful empty dict responses.
  • Cortex Agent methods raise when Snowflake returns an unexpected top-level response shape.

@boring-cyborg boring-cyborg Bot added area:providers provider:snowflake Issues related to Snowflake provider labels Jul 19, 2026
@SameerMesiah97
SameerMesiah97 force-pushed the SnowflakeCortexAgentHook-Extension branch from ebdbed1 to 1b8cab7 Compare July 24, 2026 20:03
@SameerMesiah97
SameerMesiah97 marked this pull request as ready for review July 24, 2026 21:36
@SameerMesiah97
SameerMesiah97 requested a review from potiuk as a code owner July 24, 2026 21:36
@SameerMesiah97
SameerMesiah97 force-pushed the SnowflakeCortexAgentHook-Extension branch from 1b8cab7 to 25b776e Compare July 27, 2026 19:27
@potiuk potiuk added the ready for maintainer review Set after triaging when all criteria pass. label Jul 28, 2026
@SameerMesiah97
SameerMesiah97 force-pushed the SnowflakeCortexAgentHook-Extension branch from 25b776e to 22bfa6a Compare July 28, 2026 21:52
@SameerMesiah97
SameerMesiah97 marked this pull request as draft July 29, 2026 19:34
@SameerMesiah97
SameerMesiah97 marked this pull request as ready for review July 29, 2026 19:34
@SameerMesiah97
SameerMesiah97 force-pushed the SnowflakeCortexAgentHook-Extension branch from 784409d to 652bd4c Compare July 29, 2026 19:35
@SameerMesiah97

Copy link
Copy Markdown
Contributor Author

Requesting review for this.

@SameerMesiah97
SameerMesiah97 force-pushed the SnowflakeCortexAgentHook-Extension branch 2 times, most recently from 9dc3357 to 5663c69 Compare August 1, 2026 13:04
@SameerMesiah97
SameerMesiah97 requested a review from shahar1 August 1, 2026 14:13
@SameerMesiah97
SameerMesiah97 force-pushed the SnowflakeCortexAgentHook-Extension branch 2 times, most recently from 2a75bae to 8d4802f Compare August 1, 2026 19:43
@vikramkoka

Copy link
Copy Markdown
Contributor

cc: @kaxil
Similar to the other PR conversation

@SameerMesiah97
SameerMesiah97 force-pushed the SnowflakeCortexAgentHook-Extension branch from 8d4802f to e1033c6 Compare August 16, 2026 16:40
Comment on lines +164 to +172
return cast(
"dict[str, Any]",
self._request(
method="POST",
endpoint=endpoint,
payload=payload,
timeout=timeout,
),
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big fan of cast. How do we know for sure that this is not a list of dicts? Is it an API contract, or can it be guessed from the combination of input parameters?

I suggest defining overloads for self._request (e.g. one configuration of inputs that returns a dict and one that returns list[dict]), or if that's impossible, something like

response = self._request(...)
if not isinstance(response, dict):
    raise TypeError(f"Expected a dict response, got { type(response).__name__ }")
return response  # guaranteed to be dict now

...and similarly for the other methods.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify, this is what I had in mind for the overloads:

from typing import Literal, overload

# 1. Define the overload signature for "POST"
@overload
def make_request(method: Literal["POST"]) -> dict:
    ...

# 2. Define the overload signature for "GET"
@overload
def make_request(method: Literal["GET"]) -> list[dict]:
    ...

# 3. Define the implementation function
def make_request(method: str) -> dict | list[dict]:
    if method == "POST":
        return {"status": "created"}
    elif method == "GET":
        return [{"status": "item1"}, {"status": "item2"}]
    else:
        raise ValueError(f"Unsupported method: {method}")

# --- Usage Example ---

# Type checker knows `res_post` is a `dict`
res_post = make_request("POST")

# Type checker knows `res_get` is a `list[dict]`
res_get = make_request("GET")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type of the response object is not necessarily determined by the HTTP method. I have followed the spirit of your suggestion by defining overloads for the _request method, which uses a response_type parameter to determine the return type.

@ashb

ashb commented Aug 17, 2026

Copy link
Copy Markdown
Member

Please don't merge this just yet - we are looking at unifying this in to common.ai

@SameerMesiah97

Copy link
Copy Markdown
Contributor Author

Please don't merge this just yet - we are looking at unifying this in to common.ai

I appreciate the heads up. But would it not take a substantial amount of time for the maintainers to align on the final abstraction? There is also a possibility we may decide against it. I wonder if we could let these PRs merge whilst that discussion continues.

@SameerMesiah97
SameerMesiah97 force-pushed the SnowflakeCortexAgentHook-Extension branch from e1033c6 to e5fe3b1 Compare August 23, 2026 16:47
Sameer Mesiah added 2 commits August 23, 2026 18:05
This change extends SnowflakeCortexAgentHook with support for
managing Cortex Agent Objects through the Snowflake REST API.

The hook now supports describing, listing and deleting Cortex
Agents in addition to executing them via run_agent().

The internal request helper has also been enhanced to support
query parameters, enabling endpoints such as list_agents() and
delete_agent() to pass optional REST query parameters while
reusing the existing request implementation.
…lper validate the expected top-level response shape. Remove endpoint-level casts and handle successful empty responses as empty dictionaries for dict-shaped endpoints.
@SameerMesiah97
SameerMesiah97 force-pushed the SnowflakeCortexAgentHook-Extension branch from e5fe3b1 to 0d5d47e Compare August 23, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:snowflake Issues related to Snowflake provider ready for maintainer review Set after triaging when all criteria pass.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants