Snowflake Cortex Agents Research
Give a Snowflake Cortex Agent a research tool. One SQL script creates a stored procedure that takes a question and returns a written report from the live web, with a numbered list of the pages it cites and when each was read. You register it as a custom tool of resource type Procedure, in SQL or in Snowsight.
SpecStream for Snowflake Cortex Agents ResearchAgent 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. Allow calls to api.specstream.ai
In a Snowsight worksheet, run this as
ACCOUNTADMIN. It creates the role your agent's users get, a warehouse that runs the tools, 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 ofYOUR_SPECSTREAM_KEY. Snowflake stores it encrypted, and no query prints it.Each statement is
IF NOT EXISTS. If you already followed the Cortex Agents web search guide, it keeps your role, secret and integration, and you can go to the next step.Snowflake worksheet - 2
2. Create the research procedure
research_reporttakes the question and a depth:quick,standardordeep. It starts the report withPOST /v1/research, then readsGET /v1/research/{id}every 5 seconds for up to 90 seconds. A quick report takes about a minute, so it usually comes back in the same call: the text with[1]markers, then a Sources list with each cited page's title, URL and read time.A standard report takes about four minutes and a deep report about five. For those, the call returns the report ID, which starts with
rr_, and the next step's function reads the report when it is done.It is a procedure, not a function, because it starts paid work: a function could run once for every row of a
SELECT.EXECUTE AS OWNERlets it use the secret while the agent's role has no access to it.Snowflake worksheet - 3
3. Create the read function
read_research_reporttakes a report ID and returns the finished report, or the stage the report is in: planning, searching, reading, writing or checking. It only reads and costs nothing, so it is a function.Snowflake worksheet - 4
4. Try both from SQL
The
CALLstarts one quick report. SpecStream takes its $0.10 from your balance when the report is delivered.Snowflake worksheet - 5
5. Create the agent
Register both as custom tools. Each
tool_specof typegenericgives the agent the tool's inputs, andtool_resourcesmaps it to its procedure or function and the warehouse that runs it. The instructions make the agent say the price and wait for a yes before it starts a report. The budget gives one answer 300 seconds, enough for the 90 seconds the procedure waits. The specification is YAML. This one is written as JSON, which YAML reads as it is.Snowflake worksheet - 6
6. Ask the agent
In Snowsight, open AI & ML, then Agents, and select RESEARCH_AGENT. Ask a question in the agent playground. The agent names the price, and after your yes it returns the report with its sources.
Agent playground
Add the tool to an agent you already have
An agent your team already uses takes the same procedure, with no new agent. Snowflake's docs now list Snowflake Intelligence as Snowflake CoWork (opens in a new tab), and an agent your users reach there is edited in the same place. Grant its role USAGE on the procedure and the function first, then add each one in Snowsight:
- In the navigation menu, select AI & ML, then Agents, select the agent and select Edit.
- Select Tools, find Custom tools and select + Add.
- For Name, enter
research_report. For Resource type, select procedure. - For Custom tool identifier, select
SPECSTREAM.TOOLS.RESEARCH_REPORT. The parametersquestionanddepthappear by themselves. Give each the description from the agent spec above. - For Warehouse, select
SPECSTREAM_AGENT_WH. Snowflake does not choose one for you. - For Description, paste the tool's description from the agent spec above, with the three prices, then select Add.
- Add
read_research_reportthe same way with the resource type function, then select Save. - Under Orchestration, paste the planning instructions from the agent spec, and set the time limit in Budget configuration to 300 seconds.
What the agent gets back
A research report answers one question in plain words. SpecStream plans the question, searches the live web, reads the pages and writes the answer. Each cited sentence carries a [1] marker, and the Sources list under the text gives that page's title, its URL and the time it was read in this run.
The tools return the report as text, which is what a Cortex Agent shows best. In your own code, GET /v1/research/{id} returns more: report.citations holds each cited sentence with its passage, and report.sources lists every page read, cited or not. Send "output": {"type": "json", "schema": {...}} to get JSON in the shape of your schema in place of text, and include_domains or exclude_domains to choose the sites. The research docs list every field.
How spending stays under control
- One report has one fixed price for its depth. No report costs more than $1.00.
- The user approves the price. The agent's instructions make it name the price and wait for a yes before
research_report. - A repeated call buys nothing new. The procedure sends an
Idempotency-Keybuilt from the question, the depth and the hour, so the same question in the same hour returns the report it already started. - The charge comes at delivery. A report that fails or is cancelled costs nothing.
- The role gets
USAGEon the procedure and the function, not on the integration or the secret, so its users cannot read the key or reach another host. - To keep deep reports out, remove
"deep"from the depth check in the procedure and run theCREATE OR REPLACEagain.
If something doesn't work
| What you see | What to do |
|---|---|
The report is still in work | The report needs more than the 90 seconds one call waits. Ask the agent for it again in a minute, or run SELECT specstream.tools.read_research_report('rr_...');. |
SpecStream answered 401 | The key in the secret is unknown, expired or revoked. Create a new key and run ALTER SECRET specstream.tools.specstream_api_key SET SECRET_STRING = 'NEW_KEY';. |
SpecStream answered 402, or the balance cannot pay for it | The balance does not hold the report's price. Add balance in your SpecStream workspace. A report that was already written is delivered on the next read. |
SpecStream answered 422 | A field is wrong, and the reply names it. The question holds up to 15,000 characters. |
SpecStream answered 429 | The account used its calls for the minute. Wait and ask again. Nothing is charged. |
A Python error that names api.specstream.ai | The network rule does not allow the host. Check it with SHOW NETWORK RULES and DESCRIBE EXTERNAL ACCESS INTEGRATION specstream_api_access. |
| The agent stops before the report arrives | The agent's budget ended first. Set the time limit in Budget configuration to 300 seconds, or budget.seconds in the agent spec. |
| Snowflake refuses the tool for one user | Their role has no USAGE on the procedure or the function. Run the two GRANT USAGE statements for that role. |
Cost
A report costs $0.10 at quick, $0.30 at standard and $1.00 at deep, taken from your SpecStream balance once, when the report is delivered. Reading a report costs nothing. Snowflake bills the warehouse that runs the tools, as it bills any warehouse, and that includes the seconds the procedure waits for the report. The rates are on pricing.
Web search, page reading and tables too
For one fact or the text of a page, the Cortex Agents web search guide adds web_search and read_pages tools on the same integration. The Search API is $5 per 1,000 searches of up to 10 results and the Extract API $0.80 per 1,000 pages. For a table of every match with the same facts on each row, the Deep Search guide adds three more tools. The REST API reference lists every call on this page.
Remove
Run DROP AGENT specstream.tools.research_agent;, DROP PROCEDURE specstream.tools.research_report(STRING, STRING); and DROP FUNCTION specstream.tools.read_research_report(STRING);. If no other SpecStream tool uses them, drop the integration, the secret and the network rule too, then revoke the key in your SpecStream workspace. Reports already delivered stay in your account. Questions: [email protected].
More
SpecStream for Snowflake Cortex Agents Research covers what it does in Snowflake Cortex Agents Research 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].