feat(tools): add SnowflakeCortexAgentTool for Cortex Agents API (closes #5732)#5734
Open
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Open
feat(tools): add SnowflakeCortexAgentTool for Cortex Agents API (closes #5732)#5734devin-ai-integration[bot] wants to merge 2 commits intomainfrom
devin-ai-integration[bot] wants to merge 2 commits intomainfrom
Conversation
Closes #5732 Adds a new tool that wraps the Snowflake Cortex Agents REST API so a CrewAI agent can delegate natural language data questions to a governed Cortex Agent running inside Snowflake. The Cortex Agent plans, routes between Cortex Analyst (text-to-SQL on structured data) and Cortex Search (retrieval over unstructured data), executes, and returns a final answer. The tool supports both endpoints: - agent object: POST /api/v2/databases/{db}/schemas/{schema}/agents/{name}:run - inline: POST /api/v2/cortex/agent:run Auth uses a bearer token (PAT, OAuth, or JWT) provided via auth_token or the SNOWFLAKE_CORTEX_AGENT_TOKEN env var; the account identifier can be passed via account or SNOWFLAKE_ACCOUNT, with an optional host override for private link. Tests cover credential validation, URL building (agent object vs inline, host override, env-var fallback), payload shape, success/error paths, and top-level export. Co-Authored-By: João <joao@crewai.com>
Contributor
Author
|
Prompt hidden (unlisted session) |
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #5732.
Adds
SnowflakeCortexAgentTool, a first-class CrewAI tool that wraps the Snowflake Cortex Agents REST API. A CrewAI agent can hand off a natural language data question to a governed Cortex Agent inside Snowflake instead of writing raw SQL or picking between retrieval (Cortex Search) and text-to-SQL (Cortex Analyst) itself — all of that planning happens inside Snowflake's secure perimeter and only the final answer is returned for downstream steps.Why this is useful (per the issue):
Implementation details:
lib/crewai-tools/src/crewai_tools/tools/snowflake_cortex_agent_tool/with module README.POST /api/v2/databases/{db}/schemas/{schema}/agents/{name}:runwhendatabase,snowflake_schema, andagent_nameare all provided.POST /api/v2/cortex/agent:runwhentools(and optionallytool_resources,models,instructions,orchestration) are provided.auth_tokenor theSNOWFLAKE_CORTEX_AGENT_TOKENenv var (PAT, OAuth, or JWT). Account fromaccountorSNOWFLAKE_ACCOUNT. Optionalhostoverride for private link.stream: falseand parses the JSON response. Concatenates allcontent[].textitems as the answer; falls back to the full JSON when only tool calls/citations are present so the calling agent still has something useful.requests.RequestExceptionare returned as strings starting withSnowflake Cortex Agent returned HTTP …/Error calling Snowflake Cortex Agent …so the calling agent can react instead of crashing.crewai_tools.__init__andcrewai_tools.tools.__init__.tool.specs.jsonis regenerated automatically by the existinggenerate-tool-specs.ymlworkflow, so it is intentionally not edited in this PR.requestscalls are mocked — no network access in tests.Example usage:
Review & Testing Checklist for Human
requests.Session.post, so they validate request shape and response handling but not the live API contract.content[].textitems and joins them with newlines; if your agent emits citations or tool-call items only, the tool falls back to returning the full JSON — check whether you'd prefer a different default.auth_token, or extend the tool with a JWT-from-private-key path similar toSnowflakeSearchTool.SNOWFLAKE_CORTEX_AGENT_TOKEN,SNOWFLAKE_ACCOUNT). I pickedSNOWFLAKE_CORTEX_AGENT_TOKENto avoid colliding with anything the existingSnowflakeSearchToolmay use.Suggested test plan:
SNOWFLAKE.CORTEX_AGENT_USER(orSNOWFLAKE.CORTEX_USER) role granted and a network policy attached.DB.SCHEMA.NAMEreferencing a Cortex Analyst semantic model and/or a Cortex Search service, or (b) skip the agent object and use the inlinetools=[…]form shown in the README.account,auth_token, and either thedatabase/snowflake_schema/agent_nametriple ortools/tool_resources.tool.run(query="…")with a representative question and confirm a sensible textual answer comes back.Notes
crewAIInc/crewAI-toolsrepo was not touched; per its README this work belongs inlib/crewai-tools/of the monorepo.lib/crewai-tools/tool.specs.json; theGenerate Tool Specificationsworkflow will commit the regenerated file automatically once this PR is opened. I verified locally thatToolSpecExtractorproduces a complete spec forSnowflakeCortexAgentTool(humanized nameSnowflake Cortex Agent, singlequeryrun param, env vars listed,package_dependencies = ["requests"]).requests, which is already a hard dep ofcrewai-tools.Link to Devin session: https://app.devin.ai/sessions/a7c5b5ee33ee431eb39f408d99bb248a