snowflake-cortex-agent-sdk 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- snowflake_cortex_agent_sdk-0.0.1/.gitignore +14 -0
- snowflake_cortex_agent_sdk-0.0.1/LICENSE +1 -0
- snowflake_cortex_agent_sdk-0.0.1/PKG-INFO +194 -0
- snowflake_cortex_agent_sdk-0.0.1/README.md +165 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/__init__.py +180 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/_base_client.py +783 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/_constants.py +51 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/_generated/__init__.py +0 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/_generated/agent_runs.py +1061 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/_generated/data_agent.py +1309 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/_generated/events.py +2657 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/_generated/lite_agent.py +1050 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/_generated/threads.py +238 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/_request_options.py +158 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/_resource.py +103 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/_transport.py +111 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/_types.py +96 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/_version.py +12 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/api_response.py +51 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/auth.py +245 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/client.py +461 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/constants.py +137 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/conversation.py +428 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/__init__.py +436 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/_errors.py +66 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/_internal/__init__.py +0 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/_internal/message_parser.py +261 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/_internal/query.py +682 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/_internal/transport/__init__.py +62 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/_internal/transport/api.py +988 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/_internal/transport/api_support/__init__.py +1 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/_internal/transport/api_support/connection.py +232 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/_internal/transport/api_support/messages.py +72 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/_internal/transport/api_support/options.py +100 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/_internal/transport/api_support/settings.py +31 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/_internal/transport/api_support/tools.py +55 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/_internal/transport/api_support/trace.py +99 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/_internal/transport/api_support/types.py +86 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/_internal/transport/api_support/utils.py +34 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/_internal/transport/api_support/wire.py +530 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/_internal/transport/subprocess_cli.py +625 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/client.py +384 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/fork_session.py +103 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/py.typed +0 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/query.py +73 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/threads.py +190 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/cortexcode/types.py +1299 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/errors.py +146 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/models.py +466 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/origin.py +20 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/py.typed +0 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/resources/__init__.py +22 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/resources/agent.py +680 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/resources/coding_agent.py +343 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/resources/feedback.py +166 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/resources/runs.py +146 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/resources/threads.py +429 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/stream.py +12 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/streaming/__init__.py +15 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/streaming/parser.py +189 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/streaming/run_stream.py +524 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/threads_page.py +180 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/views/__init__.py +17 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/views/agent_response.py +236 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/views/async_run.py +317 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/views/content_view.py +144 -0
- snowflake_cortex_agent_sdk-0.0.1/cortex_agent_sdk/views/thread_message.py +122 -0
- snowflake_cortex_agent_sdk-0.0.1/pyproject.toml +85 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Use of the Cortex Agent SDK is governed by your customer agreement with Snowflake as Client Software.
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: snowflake-cortex-agent-sdk
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Python SDK for the Snowflake Cortex Agent REST API (agent:run streaming, threads, feedback)
|
|
5
|
+
Author-email: "Snowflake, Inc." <support@snowflake.com>
|
|
6
|
+
License: See LICENSE
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: cortex,cortex-agent,openapi,sdk,snowflake
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
11
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
12
|
+
Requires-Python: >=3.10
|
|
13
|
+
Requires-Dist: httpx-sse>=0.4
|
|
14
|
+
Requires-Dist: httpx>=0.27
|
|
15
|
+
Requires-Dist: pydantic>=2.0
|
|
16
|
+
Provides-Extra: code
|
|
17
|
+
Requires-Dist: anyio>=4.0; extra == 'code'
|
|
18
|
+
Requires-Dist: mcp<2,>=1.0; extra == 'code'
|
|
19
|
+
Requires-Dist: snowflake-connector-python<5,>=4.7.1; extra == 'code'
|
|
20
|
+
Requires-Dist: typing-extensions>=4.0; extra == 'code'
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: datamodel-code-generator>=0.28; extra == 'dev'
|
|
23
|
+
Requires-Dist: mypy>=1.0; extra == 'dev'
|
|
24
|
+
Requires-Dist: pytest-asyncio>=0.20.0; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest-timeout>=2.0.0; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# `snowflake-cortex-agent-sdk` — Python SDK for Snowflake Cortex Agents
|
|
31
|
+
|
|
32
|
+
**Version:** v0.0.1 (preview)
|
|
33
|
+
|
|
34
|
+
Python SDK for the Snowflake Cortex Agent REST API. Covers the full public
|
|
35
|
+
surface:
|
|
36
|
+
|
|
37
|
+
- Lite + data agent runs (streaming, non-streaming, background)
|
|
38
|
+
- Named + versioned data agents (CRUD lifecycle)
|
|
39
|
+
- Coding-agent runs — sandbox, bash, skills, workspace mounts
|
|
40
|
+
- Threads (create / list / describe / update / delete / search) with auto-pagination
|
|
41
|
+
- Feedback
|
|
42
|
+
- Background run reconnect, cancel, and wait (`client.runs.*`)
|
|
43
|
+
- High-level `Conversation` abstraction
|
|
44
|
+
- Typed response views (`AgentResponseView`, `ThreadMessageView`)
|
|
45
|
+
- **Sync and async clients** as first-class twins
|
|
46
|
+
- Programmatic Cortex Code sessions through either the local CLI or Agent API
|
|
47
|
+
|
|
48
|
+
Request and response models are generated from the Cortex Agent API schema. The
|
|
49
|
+
HTTP client, streaming runtime, resource classes, and higher-level helpers are
|
|
50
|
+
hand-written for Python.
|
|
51
|
+
|
|
52
|
+
## Install
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install snowflake-cortex-agent-sdk
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Requires Python 3.10+. Core dependencies include `httpx`, `httpx-sse`, and
|
|
59
|
+
`pydantic` v2.
|
|
60
|
+
|
|
61
|
+
For Cortex Code sessions, install the `code` extra (including the optional
|
|
62
|
+
Snowflake connector profile integration):
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install 'snowflake-cortex-agent-sdk[code]'
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Quickstart
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
import os
|
|
72
|
+
from cortex_agent_sdk import CortexAgentClient, EventType
|
|
73
|
+
|
|
74
|
+
client = CortexAgentClient(account="myaccount", auth=os.environ["SNOWFLAKE_PAT"])
|
|
75
|
+
|
|
76
|
+
for event in client.agent.run(
|
|
77
|
+
{
|
|
78
|
+
"models": {"orchestration": "claude-sonnet-4-5"},
|
|
79
|
+
"messages": [{"role": "user", "content": [{"type": "text", "text": "Hi."}]}],
|
|
80
|
+
}
|
|
81
|
+
):
|
|
82
|
+
if event["event"] == EventType.RESPONSE_TEXT_DELTA:
|
|
83
|
+
print(event.get("text", ""), end="", flush=True)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Async, same surface:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
import asyncio
|
|
90
|
+
from cortex_agent_sdk import AsyncCortexAgentClient
|
|
91
|
+
|
|
92
|
+
async def main() -> None:
|
|
93
|
+
async with AsyncCortexAgentClient(account="myaccount", auth=os.environ["SNOWFLAKE_PAT"]) as client:
|
|
94
|
+
stream = client.agent.stream({"messages": [{"role": "user", "content": [{"type": "text", "text": "Hi."}]}]})
|
|
95
|
+
async for text in stream.text_stream:
|
|
96
|
+
print(text, end="", flush=True)
|
|
97
|
+
|
|
98
|
+
asyncio.run(main())
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Or, for multi-turn without hand-managing ids:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from cortex_agent_sdk import Conversation
|
|
105
|
+
|
|
106
|
+
convo = Conversation.create(client, origin_application="my-app")
|
|
107
|
+
print(convo.ask("What is Snowflake Arctic?").text)
|
|
108
|
+
print(convo.ask("Name one advantage over Llama 3.").text)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Cortex Code sessions
|
|
112
|
+
|
|
113
|
+
The optional `cortex_agent_sdk.cortexcode` module provides one-shot queries and
|
|
114
|
+
stateful Cortex Code sessions through either an installed Cortex Code CLI or the
|
|
115
|
+
direct Agent API:
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
import asyncio
|
|
119
|
+
from cortex_agent_sdk.cortexcode import CortexCodeAgentOptions, ResultMessage, query
|
|
120
|
+
|
|
121
|
+
async def main() -> None:
|
|
122
|
+
async for message in query(
|
|
123
|
+
prompt="Review this repository for bugs",
|
|
124
|
+
options=CortexCodeAgentOptions(connection="my_connection", mode="cli"),
|
|
125
|
+
):
|
|
126
|
+
if isinstance(message, ResultMessage):
|
|
127
|
+
print(message.result)
|
|
128
|
+
|
|
129
|
+
asyncio.run(main())
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
CLI mode supports local tools, hooks, permissions, MCP servers, and session
|
|
133
|
+
resume or fork. API mode needs no local CLI and supports durable background
|
|
134
|
+
runs, remote sandbox tools, cancellation, and thread-backed sessions.
|
|
135
|
+
|
|
136
|
+
## Resources at a glance
|
|
137
|
+
|
|
138
|
+
| Resource | Purpose |
|
|
139
|
+
|---|---|
|
|
140
|
+
| `client.agent` | Run agents (lite, data, versioned) + data-agent CRUD |
|
|
141
|
+
| `client.coding_agent` | Coding-agent runs |
|
|
142
|
+
| `client.runs` | Reconnect to or cancel existing runs |
|
|
143
|
+
| `client.threads` | Thread CRUD + search + pagination |
|
|
144
|
+
| `client.feedback` | Send feedback for a data-agent turn |
|
|
145
|
+
|
|
146
|
+
Higher-level helpers:
|
|
147
|
+
|
|
148
|
+
- **`Conversation`** — hides `thread_id` + `parent_message_id`; `ask()` and
|
|
149
|
+
`ask_coding_agent()` return `AgentResponseView`.
|
|
150
|
+
- **`BackgroundRun`** — the handle a background run returns; `wait()` and
|
|
151
|
+
`cancel()`. Low-level live access stays on `client.runs.resume()`.
|
|
152
|
+
- **`AgentResponseView` / `ThreadMessageView`** — typed content accessors.
|
|
153
|
+
- **`ThreadsPage`** — auto-paginating `threads.list()`.
|
|
154
|
+
|
|
155
|
+
## Auth at a glance
|
|
156
|
+
|
|
157
|
+
| Class | For | Header shape |
|
|
158
|
+
|---|---|---|
|
|
159
|
+
| `PatAuth` (or a bare string) | Programmatic Access Token | `Authorization: Bearer <token>` + `X-Snowflake-Authorization-Token-Type: PROGRAMMATIC_ACCESS_TOKEN` |
|
|
160
|
+
| `OAuthAuth` | External OAuth / Snowflake OAuth access tokens | Bearer + `...-Token-Type: OAUTH` |
|
|
161
|
+
| `KeyPairJwtAuth` | Key-pair JWTs you sign yourself | Bearer + `...-Token-Type: KEYPAIR_JWT` |
|
|
162
|
+
| `SnowflakeSessionTokenAuth` | `snowflake-connector-python` session tokens | `Authorization: Snowflake Token="<token>"` |
|
|
163
|
+
| `CallableAuth` | Lazy token minting, any token type | Bearer + configurable token-type header |
|
|
164
|
+
| Any object with `get_auth_headers()` | Anything else | You return the header map |
|
|
165
|
+
|
|
166
|
+
Every authenticator takes a callable as well as a string and is re-invoked per
|
|
167
|
+
request attempt, so token rotation needs no extra plumbing.
|
|
168
|
+
|
|
169
|
+
## Models and runtime data
|
|
170
|
+
|
|
171
|
+
Generated Pydantic v2 models are available from `cortex_agent_sdk.models` for
|
|
172
|
+
construction-time validation and autocomplete. Request methods also accept
|
|
173
|
+
plain dictionaries as an escape hatch for fields newer than the bundled schema.
|
|
174
|
+
|
|
175
|
+
Events, response content, and thread messages are returned as plain dictionaries
|
|
176
|
+
so unknown server fields are preserved. Event validation is opt-in:
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
from cortex_agent_sdk.models import AgentRunRequest, parse_event
|
|
180
|
+
|
|
181
|
+
client.agent.run(AgentRunRequest(messages=[...], stream=False)) # validated
|
|
182
|
+
client.agent.run({"messages": [...], "stream": False}) # not validated
|
|
183
|
+
|
|
184
|
+
for event in client.agent.run({"messages": [...]}):
|
|
185
|
+
typed = parse_event(event) # model when known, dict when not
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Status
|
|
189
|
+
|
|
190
|
+
Preview. Expect breaking changes while the underlying API stabilizes.
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
See `LICENSE`. Use is governed by your Snowflake customer agreement.
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# `snowflake-cortex-agent-sdk` — Python SDK for Snowflake Cortex Agents
|
|
2
|
+
|
|
3
|
+
**Version:** v0.0.1 (preview)
|
|
4
|
+
|
|
5
|
+
Python SDK for the Snowflake Cortex Agent REST API. Covers the full public
|
|
6
|
+
surface:
|
|
7
|
+
|
|
8
|
+
- Lite + data agent runs (streaming, non-streaming, background)
|
|
9
|
+
- Named + versioned data agents (CRUD lifecycle)
|
|
10
|
+
- Coding-agent runs — sandbox, bash, skills, workspace mounts
|
|
11
|
+
- Threads (create / list / describe / update / delete / search) with auto-pagination
|
|
12
|
+
- Feedback
|
|
13
|
+
- Background run reconnect, cancel, and wait (`client.runs.*`)
|
|
14
|
+
- High-level `Conversation` abstraction
|
|
15
|
+
- Typed response views (`AgentResponseView`, `ThreadMessageView`)
|
|
16
|
+
- **Sync and async clients** as first-class twins
|
|
17
|
+
- Programmatic Cortex Code sessions through either the local CLI or Agent API
|
|
18
|
+
|
|
19
|
+
Request and response models are generated from the Cortex Agent API schema. The
|
|
20
|
+
HTTP client, streaming runtime, resource classes, and higher-level helpers are
|
|
21
|
+
hand-written for Python.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install snowflake-cortex-agent-sdk
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Requires Python 3.10+. Core dependencies include `httpx`, `httpx-sse`, and
|
|
30
|
+
`pydantic` v2.
|
|
31
|
+
|
|
32
|
+
For Cortex Code sessions, install the `code` extra (including the optional
|
|
33
|
+
Snowflake connector profile integration):
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install 'snowflake-cortex-agent-sdk[code]'
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Quickstart
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
import os
|
|
43
|
+
from cortex_agent_sdk import CortexAgentClient, EventType
|
|
44
|
+
|
|
45
|
+
client = CortexAgentClient(account="myaccount", auth=os.environ["SNOWFLAKE_PAT"])
|
|
46
|
+
|
|
47
|
+
for event in client.agent.run(
|
|
48
|
+
{
|
|
49
|
+
"models": {"orchestration": "claude-sonnet-4-5"},
|
|
50
|
+
"messages": [{"role": "user", "content": [{"type": "text", "text": "Hi."}]}],
|
|
51
|
+
}
|
|
52
|
+
):
|
|
53
|
+
if event["event"] == EventType.RESPONSE_TEXT_DELTA:
|
|
54
|
+
print(event.get("text", ""), end="", flush=True)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Async, same surface:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
import asyncio
|
|
61
|
+
from cortex_agent_sdk import AsyncCortexAgentClient
|
|
62
|
+
|
|
63
|
+
async def main() -> None:
|
|
64
|
+
async with AsyncCortexAgentClient(account="myaccount", auth=os.environ["SNOWFLAKE_PAT"]) as client:
|
|
65
|
+
stream = client.agent.stream({"messages": [{"role": "user", "content": [{"type": "text", "text": "Hi."}]}]})
|
|
66
|
+
async for text in stream.text_stream:
|
|
67
|
+
print(text, end="", flush=True)
|
|
68
|
+
|
|
69
|
+
asyncio.run(main())
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Or, for multi-turn without hand-managing ids:
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from cortex_agent_sdk import Conversation
|
|
76
|
+
|
|
77
|
+
convo = Conversation.create(client, origin_application="my-app")
|
|
78
|
+
print(convo.ask("What is Snowflake Arctic?").text)
|
|
79
|
+
print(convo.ask("Name one advantage over Llama 3.").text)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Cortex Code sessions
|
|
83
|
+
|
|
84
|
+
The optional `cortex_agent_sdk.cortexcode` module provides one-shot queries and
|
|
85
|
+
stateful Cortex Code sessions through either an installed Cortex Code CLI or the
|
|
86
|
+
direct Agent API:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
import asyncio
|
|
90
|
+
from cortex_agent_sdk.cortexcode import CortexCodeAgentOptions, ResultMessage, query
|
|
91
|
+
|
|
92
|
+
async def main() -> None:
|
|
93
|
+
async for message in query(
|
|
94
|
+
prompt="Review this repository for bugs",
|
|
95
|
+
options=CortexCodeAgentOptions(connection="my_connection", mode="cli"),
|
|
96
|
+
):
|
|
97
|
+
if isinstance(message, ResultMessage):
|
|
98
|
+
print(message.result)
|
|
99
|
+
|
|
100
|
+
asyncio.run(main())
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
CLI mode supports local tools, hooks, permissions, MCP servers, and session
|
|
104
|
+
resume or fork. API mode needs no local CLI and supports durable background
|
|
105
|
+
runs, remote sandbox tools, cancellation, and thread-backed sessions.
|
|
106
|
+
|
|
107
|
+
## Resources at a glance
|
|
108
|
+
|
|
109
|
+
| Resource | Purpose |
|
|
110
|
+
|---|---|
|
|
111
|
+
| `client.agent` | Run agents (lite, data, versioned) + data-agent CRUD |
|
|
112
|
+
| `client.coding_agent` | Coding-agent runs |
|
|
113
|
+
| `client.runs` | Reconnect to or cancel existing runs |
|
|
114
|
+
| `client.threads` | Thread CRUD + search + pagination |
|
|
115
|
+
| `client.feedback` | Send feedback for a data-agent turn |
|
|
116
|
+
|
|
117
|
+
Higher-level helpers:
|
|
118
|
+
|
|
119
|
+
- **`Conversation`** — hides `thread_id` + `parent_message_id`; `ask()` and
|
|
120
|
+
`ask_coding_agent()` return `AgentResponseView`.
|
|
121
|
+
- **`BackgroundRun`** — the handle a background run returns; `wait()` and
|
|
122
|
+
`cancel()`. Low-level live access stays on `client.runs.resume()`.
|
|
123
|
+
- **`AgentResponseView` / `ThreadMessageView`** — typed content accessors.
|
|
124
|
+
- **`ThreadsPage`** — auto-paginating `threads.list()`.
|
|
125
|
+
|
|
126
|
+
## Auth at a glance
|
|
127
|
+
|
|
128
|
+
| Class | For | Header shape |
|
|
129
|
+
|---|---|---|
|
|
130
|
+
| `PatAuth` (or a bare string) | Programmatic Access Token | `Authorization: Bearer <token>` + `X-Snowflake-Authorization-Token-Type: PROGRAMMATIC_ACCESS_TOKEN` |
|
|
131
|
+
| `OAuthAuth` | External OAuth / Snowflake OAuth access tokens | Bearer + `...-Token-Type: OAUTH` |
|
|
132
|
+
| `KeyPairJwtAuth` | Key-pair JWTs you sign yourself | Bearer + `...-Token-Type: KEYPAIR_JWT` |
|
|
133
|
+
| `SnowflakeSessionTokenAuth` | `snowflake-connector-python` session tokens | `Authorization: Snowflake Token="<token>"` |
|
|
134
|
+
| `CallableAuth` | Lazy token minting, any token type | Bearer + configurable token-type header |
|
|
135
|
+
| Any object with `get_auth_headers()` | Anything else | You return the header map |
|
|
136
|
+
|
|
137
|
+
Every authenticator takes a callable as well as a string and is re-invoked per
|
|
138
|
+
request attempt, so token rotation needs no extra plumbing.
|
|
139
|
+
|
|
140
|
+
## Models and runtime data
|
|
141
|
+
|
|
142
|
+
Generated Pydantic v2 models are available from `cortex_agent_sdk.models` for
|
|
143
|
+
construction-time validation and autocomplete. Request methods also accept
|
|
144
|
+
plain dictionaries as an escape hatch for fields newer than the bundled schema.
|
|
145
|
+
|
|
146
|
+
Events, response content, and thread messages are returned as plain dictionaries
|
|
147
|
+
so unknown server fields are preserved. Event validation is opt-in:
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from cortex_agent_sdk.models import AgentRunRequest, parse_event
|
|
151
|
+
|
|
152
|
+
client.agent.run(AgentRunRequest(messages=[...], stream=False)) # validated
|
|
153
|
+
client.agent.run({"messages": [...], "stream": False}) # not validated
|
|
154
|
+
|
|
155
|
+
for event in client.agent.run({"messages": [...]}):
|
|
156
|
+
typed = parse_event(event) # model when known, dict when not
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Status
|
|
160
|
+
|
|
161
|
+
Preview. Expect breaking changes while the underlying API stabilizes.
|
|
162
|
+
|
|
163
|
+
## License
|
|
164
|
+
|
|
165
|
+
See `LICENSE`. Use is governed by your Snowflake customer agreement.
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"""Snowflake Cortex Agent SDK (Python).
|
|
2
|
+
|
|
3
|
+
Sync::
|
|
4
|
+
|
|
5
|
+
from cortex_agent_sdk import Conversation, CortexAgentClient
|
|
6
|
+
|
|
7
|
+
client = CortexAgentClient(account="myacct", auth="<pat>")
|
|
8
|
+
convo = Conversation.create(client)
|
|
9
|
+
print(convo.ask("What is Snowflake Arctic?").text)
|
|
10
|
+
|
|
11
|
+
Async::
|
|
12
|
+
|
|
13
|
+
import asyncio
|
|
14
|
+
from cortex_agent_sdk import AsyncConversation, AsyncCortexAgentClient
|
|
15
|
+
|
|
16
|
+
async def main():
|
|
17
|
+
async with AsyncCortexAgentClient(account="myacct", auth="<pat>") as client:
|
|
18
|
+
convo = await AsyncConversation.create(client)
|
|
19
|
+
print((await convo.ask("What is Snowflake Arctic?")).text)
|
|
20
|
+
|
|
21
|
+
asyncio.run(main())
|
|
22
|
+
|
|
23
|
+
Start with ``docs/01-getting-started.md``.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
from __future__ import annotations
|
|
27
|
+
|
|
28
|
+
from . import models
|
|
29
|
+
from ._constants import DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT
|
|
30
|
+
from ._request_options import RequestOptions
|
|
31
|
+
from ._transport import AuthRefreshContext, RetryPolicy
|
|
32
|
+
from ._types import NOT_GIVEN, NotGiven, Omit, not_given, omit
|
|
33
|
+
from ._version import __title__, __version__
|
|
34
|
+
from .api_response import APIResponse, ResponseCarrier
|
|
35
|
+
from .auth import (
|
|
36
|
+
Authenticator,
|
|
37
|
+
CallableAuth,
|
|
38
|
+
KeyPairJwtAuth,
|
|
39
|
+
OAuthAuth,
|
|
40
|
+
PatAuth,
|
|
41
|
+
SnowflakeSessionTokenAuth,
|
|
42
|
+
SnowflakeTokenAuth,
|
|
43
|
+
SnowflakeTokenType,
|
|
44
|
+
)
|
|
45
|
+
from .client import AsyncCortexAgentClient, CortexAgentClient
|
|
46
|
+
from .constants import ContentType, ContentTypeName, EventType, EventTypeName
|
|
47
|
+
from .conversation import AsyncConversation, Conversation
|
|
48
|
+
from .errors import (
|
|
49
|
+
APIConnectionAbortedError,
|
|
50
|
+
APIConnectionError,
|
|
51
|
+
APIStatusError,
|
|
52
|
+
APITimeoutError,
|
|
53
|
+
AuthenticationError,
|
|
54
|
+
BadRequestError,
|
|
55
|
+
ConflictError,
|
|
56
|
+
CortexAgentAPIError,
|
|
57
|
+
CortexAgentError,
|
|
58
|
+
InternalServerError,
|
|
59
|
+
NotFoundError,
|
|
60
|
+
PermissionDeniedError,
|
|
61
|
+
RateLimitError,
|
|
62
|
+
UnprocessableEntityError,
|
|
63
|
+
create_api_error,
|
|
64
|
+
)
|
|
65
|
+
from .resources.agent import (
|
|
66
|
+
AgentResource,
|
|
67
|
+
AgentSchemaTarget,
|
|
68
|
+
AsyncAgentResource,
|
|
69
|
+
CreateMode,
|
|
70
|
+
DataAgentTarget,
|
|
71
|
+
DataAgentVersionTarget,
|
|
72
|
+
)
|
|
73
|
+
from .resources.coding_agent import (
|
|
74
|
+
AsyncCodingAgentResource,
|
|
75
|
+
CodingAgentPermissionPolicy,
|
|
76
|
+
CodingAgentResource,
|
|
77
|
+
expand_coding_agent_request,
|
|
78
|
+
)
|
|
79
|
+
from .resources.feedback import AsyncFeedbackResource, FeedbackResource
|
|
80
|
+
from .resources.runs import AsyncRunsResource, RunsResource
|
|
81
|
+
from .resources.threads import AsyncThreadsResource, ThreadsResource
|
|
82
|
+
from .streaming.parser import AgentEvent, aiter_sse, iter_sse
|
|
83
|
+
from .streaming.run_stream import AgentRunStream, AsyncAgentRunStream, StreamEvent
|
|
84
|
+
from .threads_page import AsyncThreadsPage, ThreadsPage
|
|
85
|
+
from .views.agent_response import AgentResponseView
|
|
86
|
+
from .views.async_run import AsyncBackgroundRun, AsyncRun, BackgroundRun
|
|
87
|
+
from .views.content_view import MessageContentView
|
|
88
|
+
from .views.thread_message import ThreadMessage, ThreadMessageView
|
|
89
|
+
|
|
90
|
+
__all__ = [
|
|
91
|
+
# Core clients + config
|
|
92
|
+
"APIResponse",
|
|
93
|
+
"AuthRefreshContext",
|
|
94
|
+
"AsyncCortexAgentClient",
|
|
95
|
+
"CortexAgentClient",
|
|
96
|
+
"DEFAULT_MAX_RETRIES",
|
|
97
|
+
"DEFAULT_TIMEOUT",
|
|
98
|
+
"RequestOptions",
|
|
99
|
+
"ResponseCarrier",
|
|
100
|
+
"RetryPolicy",
|
|
101
|
+
# Sentinels
|
|
102
|
+
"NOT_GIVEN",
|
|
103
|
+
"NotGiven",
|
|
104
|
+
"Omit",
|
|
105
|
+
"not_given",
|
|
106
|
+
"omit",
|
|
107
|
+
# Auth
|
|
108
|
+
"Authenticator",
|
|
109
|
+
"CallableAuth",
|
|
110
|
+
"KeyPairJwtAuth",
|
|
111
|
+
"OAuthAuth",
|
|
112
|
+
"PatAuth",
|
|
113
|
+
"SnowflakeSessionTokenAuth",
|
|
114
|
+
"SnowflakeTokenAuth",
|
|
115
|
+
"SnowflakeTokenType",
|
|
116
|
+
# Errors
|
|
117
|
+
"APIConnectionAbortedError",
|
|
118
|
+
"APIConnectionError",
|
|
119
|
+
"APIStatusError",
|
|
120
|
+
"APITimeoutError",
|
|
121
|
+
"AuthenticationError",
|
|
122
|
+
"BadRequestError",
|
|
123
|
+
"ConflictError",
|
|
124
|
+
"CortexAgentAPIError",
|
|
125
|
+
"CortexAgentError",
|
|
126
|
+
"InternalServerError",
|
|
127
|
+
"NotFoundError",
|
|
128
|
+
"PermissionDeniedError",
|
|
129
|
+
"RateLimitError",
|
|
130
|
+
"UnprocessableEntityError",
|
|
131
|
+
"create_api_error",
|
|
132
|
+
# Discriminator constants
|
|
133
|
+
"ContentType",
|
|
134
|
+
"ContentTypeName",
|
|
135
|
+
"EventType",
|
|
136
|
+
"EventTypeName",
|
|
137
|
+
# Streaming
|
|
138
|
+
"AgentEvent",
|
|
139
|
+
"AgentRunStream",
|
|
140
|
+
"AsyncAgentRunStream",
|
|
141
|
+
"StreamEvent",
|
|
142
|
+
"aiter_sse",
|
|
143
|
+
"iter_sse",
|
|
144
|
+
# Pagination
|
|
145
|
+
"AsyncThreadsPage",
|
|
146
|
+
"ThreadsPage",
|
|
147
|
+
# Resources
|
|
148
|
+
"AgentResource",
|
|
149
|
+
"AgentSchemaTarget",
|
|
150
|
+
"AsyncAgentResource",
|
|
151
|
+
"AsyncCodingAgentResource",
|
|
152
|
+
"AsyncFeedbackResource",
|
|
153
|
+
"AsyncRunsResource",
|
|
154
|
+
"AsyncThreadsResource",
|
|
155
|
+
"CodingAgentPermissionPolicy",
|
|
156
|
+
"CodingAgentResource",
|
|
157
|
+
"CreateMode",
|
|
158
|
+
"DataAgentTarget",
|
|
159
|
+
"DataAgentVersionTarget",
|
|
160
|
+
"FeedbackResource",
|
|
161
|
+
"RunsResource",
|
|
162
|
+
"ThreadsResource",
|
|
163
|
+
"expand_coding_agent_request",
|
|
164
|
+
# Response / message views
|
|
165
|
+
"AgentResponseView",
|
|
166
|
+
"AsyncBackgroundRun",
|
|
167
|
+
"AsyncRun",
|
|
168
|
+
"BackgroundRun",
|
|
169
|
+
"MessageContentView",
|
|
170
|
+
"ThreadMessage",
|
|
171
|
+
"ThreadMessageView",
|
|
172
|
+
# Conversation
|
|
173
|
+
"AsyncConversation",
|
|
174
|
+
"Conversation",
|
|
175
|
+
# Generated models
|
|
176
|
+
"models",
|
|
177
|
+
# Metadata
|
|
178
|
+
"__title__",
|
|
179
|
+
"__version__",
|
|
180
|
+
]
|