snowflake-cortex-agent-sdk — Python SDK for Snowflake Cortex Agents
Version: v0.0.1 (preview)
Python SDK for the Snowflake Cortex Agent REST API. Covers the full public surface:
- Lite + data agent runs (streaming, non-streaming, background)
- Named + versioned data agents (CRUD lifecycle)
- Coding-agent runs — sandbox, bash, skills, workspace mounts
- Threads (create / list / describe / update / delete / search) with auto-pagination
- Feedback
- Background run reconnect, cancel, and wait (
client.runs.*) - High-level
Conversationabstraction - Typed response views (
AgentResponseView,ThreadMessageView) - Sync and async clients as first-class twins
- Programmatic Cortex Code sessions through either the local CLI or Agent API
Request and response models are generated from the Cortex Agent API schema. The HTTP client, streaming runtime, resource classes, and higher-level helpers are hand-written for Python.
Install
pip install snowflake-cortex-agent-sdk
Requires Python 3.10+. Core dependencies include httpx, httpx-sse, and
pydantic v2.
For Cortex Code sessions, install the code extra (including the optional
Snowflake connector profile integration):
pip install 'snowflake-cortex-agent-sdk[code]'
Quickstart
import os
from cortex_agent_sdk import CortexAgentClient, EventType
client = CortexAgentClient(account="myaccount", auth=os.environ["SNOWFLAKE_PAT"])
for event in client.agent.run(
{
"models": {"orchestration": "claude-sonnet-4-5"},
"messages": [{"role": "user", "content": [{"type": "text", "text": "Hi."}]}],
}
):
if event["event"] == EventType.RESPONSE_TEXT_DELTA:
print(event.get("text", ""), end="", flush=True)
Async, same surface:
import asyncio
from cortex_agent_sdk import AsyncCortexAgentClient
async def main() -> None:
async with AsyncCortexAgentClient(account="myaccount", auth=os.environ["SNOWFLAKE_PAT"]) as client:
stream = client.agent.stream({"messages": [{"role": "user", "content": [{"type": "text", "text": "Hi."}]}]})
async for text in stream.text_stream:
print(text, end="", flush=True)
asyncio.run(main())
Or, for multi-turn without hand-managing ids:
from cortex_agent_sdk import Conversation
convo = Conversation.create(client, origin_application="my-app")
print(convo.ask("What is Snowflake Arctic?").text)
print(convo.ask("Name one advantage over Llama 3.").text)
Cortex Code sessions
The optional cortex_agent_sdk.cortexcode module provides one-shot queries and
stateful Cortex Code sessions through either an installed Cortex Code CLI or the
direct Agent API:
import asyncio
from cortex_agent_sdk.cortexcode import CortexCodeAgentOptions, ResultMessage, query
async def main() -> None:
async for message in query(
prompt="Review this repository for bugs",
options=CortexCodeAgentOptions(connection="my_connection", mode="cli"),
):
if isinstance(message, ResultMessage):
print(message.result)
asyncio.run(main())
CLI mode supports local tools, hooks, permissions, MCP servers, and session resume or fork. API mode needs no local CLI and supports durable background runs, remote sandbox tools, cancellation, and thread-backed sessions.
Resources at a glance
| Resource | Purpose |
|---|---|
client.agent |
Run agents (lite, data, versioned) + data-agent CRUD |
client.coding_agent |
Coding-agent runs |
client.runs |
Reconnect to or cancel existing runs |
client.threads |
Thread CRUD + search + pagination |
client.feedback |
Send feedback for a data-agent turn |
Higher-level helpers:
Conversation— hidesthread_id+parent_message_id;ask()andask_coding_agent()returnAgentResponseView.BackgroundRun— the handle a background run returns;wait()andcancel(). Low-level live access stays onclient.runs.resume().AgentResponseView/ThreadMessageView— typed content accessors.ThreadsPage— auto-paginatingthreads.list().
Auth at a glance
| Class | For | Header shape |
|---|---|---|
PatAuth (or a bare string) |
Programmatic Access Token | Authorization: Bearer <token> + X-Snowflake-Authorization-Token-Type: PROGRAMMATIC_ACCESS_TOKEN |
OAuthAuth |
External OAuth / Snowflake OAuth access tokens | Bearer + ...-Token-Type: OAUTH |
KeyPairJwtAuth |
Key-pair JWTs you sign yourself | Bearer + ...-Token-Type: KEYPAIR_JWT |
SnowflakeSessionTokenAuth |
snowflake-connector-python session tokens |
Authorization: Snowflake Token="<token>" |
CallableAuth |
Lazy token minting, any token type | Bearer + configurable token-type header |
Any object with get_auth_headers() |
Anything else | You return the header map |
Every authenticator takes a callable as well as a string and is re-invoked per request attempt, so token rotation needs no extra plumbing.
Models and runtime data
Generated Pydantic v2 models are available from cortex_agent_sdk.models for
construction-time validation and autocomplete. Request methods also accept
plain dictionaries as an escape hatch for fields newer than the bundled schema.
Events, response content, and thread messages are returned as plain dictionaries so unknown server fields are preserved. Event validation is opt-in:
from cortex_agent_sdk.models import AgentRunRequest, parse_event
client.agent.run(AgentRunRequest(messages=[...], stream=False)) # validated
client.agent.run({"messages": [...], "stream": False}) # not validated
for event in client.agent.run({"messages": [...]}):
typed = parse_event(event) # model when known, dict when not
Status
Preview. Expect breaking changes while the underlying API stabilizes.
License
See LICENSE. Use is governed by your Snowflake customer agreement.
Release files for snowflake-cortex-agent-sdk 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| snowflake_cortex_agent_sdk-0.0.1.tar.gz | 137.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| snowflake_cortex_agent_sdk-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 314.6 kB
Release files / snowflake_cortex_agent_sdk-0.0.1.tar.gz
| Download URL | snowflake_cortex_agent_sdk-0.0.1.tar.gz |
|---|---|
| Size | 137.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f538c797af5d2718a5c06a29bb3627f19f0a3147e6196888ae8fea345d0c1fe0
|
|
BLAKE2b-256 checksum How to use checksums |
96a88b8e17387f043018e79c255643180c38adb30e241c1e54425d95b8f4cb0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.8
|
Release files / snowflake_cortex_agent_sdk-0.0.1-py3-none-any.whl
| Download URL | snowflake_cortex_agent_sdk-0.0.1-py3-none-any.whl |
|---|---|
| Size | 177.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
26faf38bb61a553cb037bbb5c1f1b0e69a1a68c549f48e4864c1df77a5f3ba1e
|
|
BLAKE2b-256 checksum How to use checksums |
f02b89eb6ed0753940c5d9e383d91bbdcac79aa86a2082eac39d39ba7cc0b3fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.8
|