Repository navigation
Add create and update support to Snowflake Cortex Agent hook - #70703
Conversation
|
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. |
8aa8c8e to
7a75da7
Compare
|
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. |
7a75da7 to
583f1ba
Compare
potiuk
left a comment
There was a problem hiding this comment.
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.
583f1ba to
a2b2261
Compare
a2b2261 to
d8d4af0
Compare
d8d4af0 to
af0c79a
Compare
af0c79a to
c0d341e
Compare
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.
c0d341e to
c6adbc0
Compare
Remove the premature OAuth token-type header expectations from the create and update agent tests so they match the hook's current request behavior.
c6adbc0 to
5ead101
Compare
Description
This change extends
SnowflakeCortexAgentHookwith support for creating and updating Snowflake Cortex Agent Objects.The hook now exposes
create_agent()andupdate_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 supportedCreateModevalues and omits unset optional fields from the request payload.create_agent()andupdate_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.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()anddelete_agent()are unaffected.Was generative AI tooling used to co-author this PR?
Generated-by: [GPT 5.5] following the guidelines