Skip to content

Add create and update support to Snowflake Cortex Agent hook - #70703

Merged
shahar1 merged 4 commits into
apache:mainfrom
SameerMesiah97:SnowflakeCortexAgentHook-Create-Update
Oct 3, 2026
Merged

shahar1 merged 4 commits into
apache:mainfrom
SameerMesiah97:SnowflakeCortexAgentHook-Create-Update

Conversation

@SameerMesiah97

@SameerMesiah97 SameerMesiah97 commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

This change extends SnowflakeCortexAgentHook with support for creating and updating Snowflake Cortex Agent Objects.

The hook now exposes create_agent() and update_agent() methods using the Snowflake Cortex Agent REST API. A shared helper constructs agent definition payloads while omitting unset optional fields, reducing duplication between the two operations.

Rationale

The existing hook already supports executing, describing, listing and deleting Cortex Agents, but the Snowflake Cortex Agent REST API also provides endpoints for creating and updating Cortex Agent Objects. Exposing these operations completes the core Cortex Agent management lifecycle and allows users to provision and modify agents directly from Airflow without invoking the REST API themselves.

Notes

Although the Snowflake documentation describes the update endpoint as returning a JSON status object, the endpoint can return a successful response with an empty body. The internal request helper now supports empty responses when explicitly enabled, and update_agent() opts into this behavior. Other hook methods continue to reject unexpected empty responses.

Tests

Added unit tests verifying that:

  • create_agent() sends the expected request for all supported CreateMode values and omits unset optional fields from the request payload.
  • create_agent() and update_agent() URL-encode dynamic endpoint path segments.
  • update_agent() sends the expected request and returns an empty dictionary for a successful response with an empty body.
  • Empty update responses are handled without attempting JSON deserialization.

Backward Compatibility

This change is fully backward compatible.

The new hook methods are additive and do not modify the behavior or signatures of existing public APIs. Existing consumers of run_agent(), describe_agent(), list_agents() and delete_agent() are unaffected.

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: [GPT 5.5] following the guidelines

@boring-cyborg boring-cyborg Bot added area:providers provider:snowflake Issues related to Snowflake provider labels Jul 29, 2026
@SameerMesiah97

SameerMesiah97 commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor Author

Depends on PR #70101. Please do not review this until that is merged.

A separate PR was opened for these 2 methods as I wanted to gather feedback on the original management methods before extending the hook further with these less commonly used management APIs.

@SameerMesiah97
SameerMesiah97 force-pushed the SnowflakeCortexAgentHook-Create-Update branch 6 times, most recently from 8aa8c8e to 7a75da7 Compare August 1, 2026 20:01
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.

@github-actions github-actions Bot added the stale Stale PRs per the .github/workflows/stale.yml policy file label Sep 20, 2026
@SameerMesiah97
SameerMesiah97 force-pushed the SnowflakeCortexAgentHook-Create-Update branch from 7a75da7 to 583f1ba Compare September 20, 2026 18:29
@SameerMesiah97
SameerMesiah97 marked this pull request as ready for review September 20, 2026 19:50
@github-actions github-actions Bot removed the stale Stale PRs per the .github/workflows/stale.yml policy file label Sep 21, 2026

@potiuk potiuk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for splitting this out — the shape matches the existing hook methods well, and I checked the endpoint details against Snowflake's REST API docs: createMode as a query param with those three values, and name correctly absent from the PUT body, are both right.

Five things, one of which I'd like your input on before this lands.

The one that matters: what are the update semantics? _build_agent_payload omits unset fields, so update_agent(comment="x") reads like a partial patch — but PUT /agents/{name} is conventionally a full replace, which would mean that call silently wipes the agent's tools, models and instructions. Snowflake's public docs don't say which it is. Could you confirm against a live account and record the answer in the docstring? If it is a replace, the method probably needs a louder warning, or a describe-then-merge path.

The rest are in the inline comments: the update_agent docstring is missing seven of its parameters (create_agent three lines up documents all of them), create_mode.value breaks if a caller passes the plain string "orReplace", and four of the seven new payload branches aren't exercised by the tests.

Also: your "don't review until #70101 is merged" comment is now stale — that one landed, and the stale bot has since flagged this PR. Worth a rebase/comment to keep it alive.


This review was drafted by an AI-assisted tool and
confirmed by an Apache Airflow maintainer. The findings
below are observations, not blockers; an Apache Airflow
maintainer — a real person — will take the next look at the
PR. If you think a finding is mis-applied, please reply on
the PR and a maintainer will weigh in.

More on how Apache Airflow handles maintainer review:
contributing-docs/05_pull_requests.rst.

Comment thread providers/snowflake/tests/unit/snowflake/hooks/test_snowflake_cortex_agent.py Outdated
@SameerMesiah97
SameerMesiah97 force-pushed the SnowflakeCortexAgentHook-Create-Update branch from 583f1ba to a2b2261 Compare September 23, 2026 22:55
@SameerMesiah97
SameerMesiah97 marked this pull request as draft September 23, 2026 22:59
@SameerMesiah97
SameerMesiah97 marked this pull request as ready for review September 24, 2026 19:18
@SameerMesiah97
SameerMesiah97 force-pushed the SnowflakeCortexAgentHook-Create-Update branch from a2b2261 to d8d4af0 Compare September 25, 2026 19:11

@subhramit subhramit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit

@SameerMesiah97
SameerMesiah97 force-pushed the SnowflakeCortexAgentHook-Create-Update branch from d8d4af0 to af0c79a Compare September 28, 2026 21:35

@subhramit subhramit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lgtm, thanks Sameer

@SameerMesiah97
SameerMesiah97 force-pushed the SnowflakeCortexAgentHook-Create-Update branch from af0c79a to c0d341e Compare September 30, 2026 19:43
@SameerMesiah97
SameerMesiah97 marked this pull request as draft September 30, 2026 20:27
Sameer Mesiah added 2 commits October 2, 2026 21:32
This change extends SnowflakeCortexAgentHook with support for
creating and updating Cortex Agent Objects through the
Snowflake Cortex Agent REST API.

The internal request helper has also been enhanced to gracefully
handle successful responses with empty bodies, matching the
behavior of the Cortex Agent update endpoint.

Additional unit tests have been added to cover the new hook
methods and the updated request handling behaviour.
@SameerMesiah97
SameerMesiah97 force-pushed the SnowflakeCortexAgentHook-Create-Update branch from c0d341e to c6adbc0 Compare October 2, 2026 20:32
Remove the premature OAuth token-type header expectations from the create and
update agent tests so they match the hook's current request behavior.
@SameerMesiah97
SameerMesiah97 force-pushed the SnowflakeCortexAgentHook-Create-Update branch from c6adbc0 to 5ead101 Compare October 2, 2026 21:08
@SameerMesiah97
SameerMesiah97 marked this pull request as ready for review October 2, 2026 21:41
@shahar1
shahar1 merged commit 9c14681 into apache:main Oct 3, 2026
162 checks passed
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants