crewai - ✅(Solved) Fix [FEATURE] Snowflake Cortex Agent Tool [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
crewAIInc/crewAI#5732Fetched 2026-05-07 03:39:52
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Author
Timeline (top)
closed ×1commented ×1cross-referenced ×1labeled ×1

Fix Action

Fixed

PR fix notes

PR #5734: feat(tools): add SnowflakeCortexAgentTool for Cortex Agents API (closes #5732)

Description (problem / solution / changelog)

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):

  • Keeps semantic models, RBAC, and governance in Snowflake.
  • Gets the quality of Cortex Analyst's text-to-SQL on structured data and Cortex Search's retrieval on unstructured data.
  • Lets the Cortex Agent reflect across both tool families and pick the right one — the CrewAI agent simply chooses to delegate when the question is best answered with Snowflake data.

Implementation details:

  • New tool at lib/crewai-tools/src/crewai_tools/tools/snowflake_cortex_agent_tool/ with module README.
  • Supports both Cortex Agents Run API endpoints:
    • agent object: POST /api/v2/databases/{db}/schemas/{schema}/agents/{name}:run when database, snowflake_schema, and agent_name are all provided.
    • inline: POST /api/v2/cortex/agent:run when tools (and optionally tool_resources, models, instructions, orchestration) are provided.
  • Bearer-token auth via auth_token or the SNOWFLAKE_CORTEX_AGENT_TOKEN env var (PAT, OAuth, or JWT). Account from account or SNOWFLAKE_ACCOUNT. Optional host override for private link.
  • Sends stream: false and parses the JSON response. Concatenates all content[].text items as the answer; falls back to the full JSON when only tool calls/citations are present so the calling agent still has something useful.
  • HTTP errors and requests.RequestException are returned as strings starting with Snowflake Cortex Agent returned HTTP … / Error calling Snowflake Cortex Agent … so the calling agent can react instead of crashing.
  • Registered in crewai_tools.__init__ and crewai_tools.tools.__init__. tool.specs.json is regenerated automatically by the existing generate-tool-specs.yml workflow, so it is intentionally not edited in this PR.
  • 17 unit tests covering credential validation, URL building (agent object vs inline, host override, env-var fallback), payload shape, success/error paths, and top-level export. All requests calls are mocked — no network access in tests.

Example usage:

from crewai_tools import SnowflakeCortexAgentTool

tool = SnowflakeCortexAgentTool(
    account="myorg-myaccount",
    auth_token="<programmatic-access-token>",
    database="MY_DB",
    snowflake_schema="MY_SCHEMA",
    agent_name="SALES_AGENT",
)

answer = tool.run(query="What was total revenue last quarter, by region?")

Review & Testing Checklist for Human

  • Verify the tool actually works against a real Snowflake Cortex Agent (PAT auth, agent-object endpoint). The unit tests fully mock requests.Session.post, so they validate request shape and response handling but not the live API contract.
  • Confirm the response parsing covers the response shape your account returns. The implementation extracts content[].text items 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.
  • Confirm the auth model fits your deployment. The tool uses a single bearer token. If you primarily use Snowflake-driver key-pair JWTs, you may want to pre-mint a JWT and pass it in via auth_token, or extend the tool with a JWT-from-private-key path similar to SnowflakeSearchTool.
  • Sanity-check the env var names (SNOWFLAKE_CORTEX_AGENT_TOKEN, SNOWFLAKE_ACCOUNT). I picked SNOWFLAKE_CORTEX_AGENT_TOKEN to avoid colliding with anything the existing SnowflakeSearchTool may use.

Suggested test plan:

  1. Create a Snowflake PAT with the SNOWFLAKE.CORTEX_AGENT_USER (or SNOWFLAKE.CORTEX_USER) role granted and a network policy attached.
  2. Either (a) create a Cortex Agent object in DB.SCHEMA.NAME referencing a Cortex Analyst semantic model and/or a Cortex Search service, or (b) skip the agent object and use the inline tools=[…] form shown in the README.
  3. Instantiate the tool with account, auth_token, and either the database/snowflake_schema/agent_name triple or tools/tool_resources.
  4. Call tool.run(query="…") with a representative question and confirm a sensible textual answer comes back.

Notes

  • The deprecated crewAIInc/crewAI-tools repo was not touched; per its README this work belongs in lib/crewai-tools/ of the monorepo.
  • I did not regenerate lib/crewai-tools/tool.specs.json; the Generate Tool Specifications workflow will commit the regenerated file automatically once this PR is opened. I verified locally that ToolSpecExtractor produces a complete spec for SnowflakeCortexAgentTool (humanized name Snowflake Cortex Agent, single query run param, env vars listed, package_dependencies = ["requests"]).
  • No new optional dependency is added — the tool only uses requests, which is already a hard dep of crewai-tools.

Link to Devin session: https://app.devin.ai/sessions/a7c5b5ee33ee431eb39f408d99bb248a

Changed files

  • lib/crewai-tools/src/crewai_tools/__init__.py (modified, +6/-0)
  • lib/crewai-tools/src/crewai_tools/tools/__init__.py (modified, +6/-0)
  • lib/crewai-tools/src/crewai_tools/tools/snowflake_cortex_agent_tool/README.md (added, +105/-0)
  • lib/crewai-tools/src/crewai_tools/tools/snowflake_cortex_agent_tool/__init__.py (added, +10/-0)
  • lib/crewai-tools/src/crewai_tools/tools/snowflake_cortex_agent_tool/snowflake_cortex_agent_tool.py (added, +324/-0)
  • lib/crewai-tools/tests/tools/snowflake_cortex_agent_tool_test.py (added, +248/-0)
  • lib/crewai-tools/tool.specs.json (modified, +255/-0)
RAW_BUFFERClick to expand / collapse

Feature Area

Integration with external tools

Is your feature request related to a an existing bug? Please link it here.

NA

Describe the solution you'd like

Problem

Developers building multi-system agentic workflows with CrewAI don't currently have a good way to leverage all Snowflake does for data questions. Currently, they have to write raw SQL via a connector tool, losing governance, text-to-sql quality, retrieval quality, and semantic understanding. The common CrewAI pattern requires the agent to generate SQL from scratch, bypassing Cortex Analyst's semantic models and Cortex Search's retrieval quality, and the Cortex Agent's ability to reason between those tools.

There is no first-class way to use a Cortex Agent as a governed, intelligent tool within CrewAI. Today, this exists in langchain: https://reference.langchain.com/python/langchain-snowflake/agents

Proposal

Add CortexAgentTool. This would be a CrewAI-compatible tool class that wraps the Cortex Agents REST API. When a CrewAI agent determines that a question involves Snowflake data, it delegates to the Cortex Agent tool. Instead of generating the SQL in CrewAI or determining between Cortex Analyst vs Cortex Search (RAG) in CrewAI, the Cortex Agent tool takes the natural language data question and runs all the logic inside Snowflake (governance, retrieval, reasoning), and only the final answer is returned to the CrewAI orchestration layer for use in downstream workflow steps.

Note

This is not running an agent externally. The Cortex Agent executes inside Snowflake. CrewAI simply holds a reference to it and routes questions there when appropriate. This is the same way an agent routes to any tool. The LLM-powered CrewAI agent naturally recognizes when a question is better served by the Cortex Agent (based on the tool's description) and sends the prompt there.

Describe alternatives you've considered

You can wrap the Cortex Agents API yourself. That's less convenient.

Additional context

No response

Willingness to Contribute

Yes, I'd be happy to submit a pull request

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING