Cortex Agent SDK quickstart¶
In this quickstart, you build a small application that starts an agent turn, reads events and structured results, and continues the conversation on a persistent thread.
Prerequisites¶
- Node.js 22.22 or later
- A Snowflake account with Cortex Agents available
- A programmatic access token (PAT), or another supported credential type described in Authenticate Cortex Agent SDK requests
- Python 3.10 or later
- A Snowflake account and authentication token
- The Cortex Agent SDK for Python
Setup¶
Set "type": "module" in package.json so you can use import syntax:
The SDK expands SNOWFLAKE_ACCOUNT to the Snowflake API host. If the account identifier contains an underscore (_),
the SDK uses Snowflake’s canonical hyphenated host form.
The SDK expands SNOWFLAKE_ACCOUNT to the Snowflake API host. If the account identifier contains an underscore (_),
the SDK uses Snowflake’s canonical hyphenated host form.
Step 1: Send your first turn¶
Create agent.ts:
Run npx tsx agent.ts.
send() starts durable asynchronous work and returns after Snowflake accepts the turn. The SDK manages the thread ID, parent message ID, run ID, and background and stream flags. turn.id is the server-assigned run ID; result() waits for the final assistant response.
Step 2: Read events as they arrive¶
Events are replayable, so reading them does not replace result(). Call result(), events(), and cancel() on the Turn returned by send().
Step 3: Read structured results¶
AgentResponse also exposes toolUses, toolResults, tables, charts, and messageId when the agent response
contains those values.
Step 4: Send a follow-up¶
The same conversation retains history across turns. You can attach to conversation.id later to continue the same
thread from another process.
conversation.id is the thread ID. history() returns Promise<ConversationMessage[]>, newest first.
Step 5: Handle failures¶
Next steps¶
- Authenticate Cortex Agent SDK requests: Configure PAT, OAuth, key-pair JWT, Snowflake session token, and custom authentication.
- Conversations: Branch, search, and manage multi-turn state.
- Direct Agent API: Use low-level run, thread, and agent-object resources.
- SDK reference: Configure retries, errors, and request options.
Legal notices¶
Where your configuration of Cortex Code uses a model provided on the Model and Service Pass-Through Terms, your use of that model is further subject to the terms for that model on that page.
The data classification of inputs and outputs are as set forth in the following table.
| Input data classification | Output data classification | Designation |
|---|---|---|
| Usage Data | Customer Data | Covered AI Features [1] |
For additional information, refer to Snowflake AI and ML.