Snowflake Cortex Agents
Give a Snowflake Cortex Agent web search and page reading as two custom tools. One SQL script creates the network rule, the secret and the External Access Integration, two Python functions that call SpecStream's Search API and Extract API, and the agent that uses them.
SpecStream for Snowflake Cortex AgentsAgent frameworks & buildersWhat you need
- A Snowflake account where you can use the
ACCOUNTADMINrole. Creating an External Access Integration needs theCREATE INTEGRATIONprivilege on the account. - A SpecStream key. Get your key on the Search API screen of your SpecStream workspace. New accounts start with $10 of credit, no card.
- 1
1. Create the role, database and warehouse
In a Snowsight worksheet, run this as
ACCOUNTADMIN. The role is the one your agent's users get; the warehouse runs the two functions.Snowflake worksheet - 2
2. Allow calls to api.specstream.ai
Create a network rule for SpecStream's host, a secret that holds your key, and the External Access Integration that binds them. Put your key in place of
YOUR_SPECSTREAM_KEY. Snowflake stores it encrypted, and no query prints it.Snowflake worksheet - 3
3. Create the web_search function
A Python function that posts the query to
POST /v1/web-searchand returns the reply'sdataas aVARIANT. Withspeedset tofast, it runs the fast search, which returns results only.Snowflake worksheet - 4
4. Create the read_pages function
The same shape for the Extract API. It takes up to 20 URLs as one comma separated string and returns the main text of each page or document as Markdown.
Snowflake worksheet - 5
5. Try both from SQL
Both functions are scalar and return
VARIANT, so you read the reply with:fieldpaths andFLATTEN, in anySELECT:Snowflake worksheet - 6
6. Create the agent
Register both functions as custom tools. Each
tool_specof typegenericgives the agent the tool's inputs, andtool_resourcesmaps it to its function and the warehouse that runs it. The specification is YAML; this one is written as JSON, which YAML reads as it is.Snowflake worksheet - 7
7. Ask the agent
In Snowsight, open AI & ML, then Agents, and select WEB_RESEARCH_AGENT. On the agent details page, enter a question in the agent playground:
Agent playground
Why a search tool of your own when Cortex has web search
Cortex Agents have a built-in Web search tool. Snowflake's docs say it uses the Brave Web Search API, and an ACCOUNTADMIN turns it on for the whole account before any agent can use it. The agent gets results to blend into its answer.
The SpecStream functions are tools you own. A reply carries an answer with the page it was read from and the time it was read, the results with their published dates, and the text of whole pages and PDFs from the Extract API. They run under your own key, with its own spending limit and request log, and the same functions work in any SELECT, so a table gets the same search the agent uses. The Search API scores 97.9 F-score on all 1,000 SimpleQA Verified questions and 64.0 item F1 on all 200 WideSearch tasks. Scores and method are on the benchmarks page.
What comes back
web_searchreturns the Search API'sdata:answerfor a question with one answer (value, thepageit was read from, thesourcesthat print it andseen_at),rowsfor a request for many results, andsources, the results in rank order withurl,title,site,snippetandpublishedwhen the page states it.- With
speedset tofast, the call returnssourcesonly, with noanswerand norows. read_pagesreturnsresults, one for each URL in the order sent, each withurl,status(ok,blocked,not_found,empty,unsupported,invalid_urlorfailed),text,title,publishedandread_from.- Both replies carry
request_idandprice_usd, what the call cost. - A refused call returns
statusanderrorin place of a Python error, so the agent reads why it stopped.
What each call costs
More results cost in the same proportion for each started block of 10. Calls come out of your SpecStream balance with no quote and no approval, and every call is in your account's request log. Snowflake bills the warehouse that runs the functions, as it bills any warehouse.
| Call | Price |
|---|---|
web_search | $5 per 1,000 searches of up to 10 results |
web_search with speed fast | $1 per 1,000 searches of up to 10 results |
read_pages | $0.80 per 1,000 pages. A page with no text is not charged. |
Keep the key and the spend in bounds
The role gets USAGE on the two functions, not on the integration or the secret, so its users can search and read pages but cannot read the key or reach another host. Snowflake asks the same of every custom tool: users need USAGE on its function or procedure.
Give Snowflake a key of its own with a spending limit, made in Agents & API. With PATCH https://api.specstream.ai/v1/account/keys/{id}, set zero_retention to true and no search made with the key keeps its request text or its answer after the reply, or set eu_egress_only to true and its searches leave only from SpecStream's server in Madrid.
To change the key, run ALTER SECRET specstream.tools.specstream_api_key SET SECRET_STRING = 'NEW_KEY';. The functions read it on their next call.
Limits and errors
- Custom tools take no parameter of type
object, soread_pagestakes its URLs as one comma separated string, and reads the first 20. status401: the key in the secret was refused. Check it and runALTER SECRET.status402: the SpecStream balance is empty.status403: the key has nofinds:spendscope or is over its limit.status422: the query is empty or over 2,000 characters.status503 withRetry-After: the account used its calls for the minute, or search is busy. Nothing is charged, and the agent can call again.- A Python error that names
api.specstream.ai: the network rule does not allow the host. Check it withSHOW NETWORK RULESandDESCRIBE EXTERNAL ACCESS INTEGRATION specstream_api_access.
Every match as rows
When the job is a list where every row must meet your conditions, with a source URL and read time on every value, use Deep Search. It reads the request, quotes the most it can cost, and delivers the rows after you approve, through the REST API or the MCP server.
Go back
Run DROP AGENT specstream.tools.web_research_agent;, then DROP FUNCTION for specstream.tools.web_search(STRING, INTEGER, STRING) and specstream.tools.read_pages(STRING), and DROP INTEGRATION specstream_api_access;. Questions: [email protected].
More
SpecStream for Snowflake Cortex Agents covers what it does in Snowflake Cortex Agents on one page. Every other tool has its guide in Connect your tools. You see the most a request can cost before it starts, and the matches are paid from your balance. Billing has the details. For help, email [email protected].