stigmer-sdk 0.1.0.dev0__tar.gz → 0.1.2__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.
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/.gitignore +6 -3
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/Makefile +18 -2
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/PKG-INFO +89 -26
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/README.md +82 -22
- stigmer_sdk-0.1.2/examples/quickstart.py +34 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/pyproject.toml +11 -4
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/__init__.py +25 -12
- stigmer_sdk-0.1.2/src/stigmer/_client.py +222 -0
- stigmer_sdk-0.1.2/src/stigmer/_file.py +245 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/__init__.py +17 -10
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_agent.py +8 -3
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_channel.py +2 -2
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_channelapp.py +2 -2
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_client.py +6 -2
- stigmer_sdk-0.1.2/src/stigmer/_gen/_environment.py +190 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_eval.py +3 -3
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_federationissuer.py +2 -2
- stigmer_sdk-0.1.2/src/stigmer/_gen/_file.py +134 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_identityaccount.py +6 -5
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_oauthapp.py +2 -2
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_organization.py +7 -1
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_plugin.py +2 -2
- stigmer_sdk-0.1.0.dev0/src/stigmer/_gen/_schedule.py → stigmer_sdk-0.1.2/src/stigmer/_gen/_routine.py +124 -47
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_run.py +22 -108
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_session.py +22 -18
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_skill.py +4 -4
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_team.py +2 -2
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_vault.py +3 -12
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_runner_adapter.py +1 -1
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_transport.py +5 -1
- stigmer_sdk-0.1.2/src/stigmer/_turns.py +340 -0
- stigmer_sdk-0.1.2/tests/test_client.py +101 -0
- stigmer_sdk-0.1.2/tests/test_file_routing.py +337 -0
- stigmer_sdk-0.1.2/tests/test_generated_annotations.py +52 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/tests/test_optional_scalar_presence.py +12 -13
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/tests/test_pages.py +19 -19
- stigmer_sdk-0.1.2/tests/test_turns.py +277 -0
- stigmer_sdk-0.1.0.dev0/src/stigmer/_client.py +0 -124
- stigmer_sdk-0.1.0.dev0/tests/test_client.py +0 -35
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_billing.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_apikey.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_bidi.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_errors.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_evalrun.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_grant.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_invitation.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_license.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_memory.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_plan.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_providerkey.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_score.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_scoringrule.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_subscription.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_gen/_types.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_github.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_interceptors.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_search.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_skill.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/_tokens.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/src/stigmer/py.typed +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/tests/__init__.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/tests/test_agent_mcp_servers.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/tests/test_billing.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/tests/test_github.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/tests/test_orgless_kind_input.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/tests/test_runner_adapter.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/tests/test_skill_routing.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/tests/test_tokens.py +0 -0
- {stigmer_sdk-0.1.0.dev0 → stigmer_sdk-0.1.2}/tests/test_transport.py +0 -0
|
@@ -104,6 +104,9 @@ node_modules/
|
|
|
104
104
|
|
|
105
105
|
# Temporary files
|
|
106
106
|
*.log
|
|
107
|
+
# ...except the benchmark fixture's sync log, data the instrument reads
|
|
108
|
+
# (test/conformance/fixtures/working-agent/README.md).
|
|
109
|
+
!test/conformance/fixtures/working-agent/evals/_fixture/workspace/logs/*.log
|
|
107
110
|
*.tmp
|
|
108
111
|
tmp/
|
|
109
112
|
|
|
@@ -155,9 +158,6 @@ uv.lock
|
|
|
155
158
|
# every source URL, so tracking them creates churn on every SDK commit)
|
|
156
159
|
sdk/*/typedoc-output.json
|
|
157
160
|
|
|
158
|
-
# Dev TLS certs (generated by gen-dev-certs.sh)
|
|
159
|
-
client-apps/desktop/scripts/.certs/
|
|
160
|
-
|
|
161
161
|
# Cursor
|
|
162
162
|
_cursor/
|
|
163
163
|
_aacursor/
|
|
@@ -176,3 +176,6 @@ _roles/
|
|
|
176
176
|
/tools/proto2schema
|
|
177
177
|
/tools/codegen/generator/generator
|
|
178
178
|
/tools/codegen/proto2schema/proto2schema
|
|
179
|
+
|
|
180
|
+
# The docs snippet gate's Python venv and Java classpath (make docs-snippets-toolchains)
|
|
181
|
+
/.docs-snippets-toolchains/
|
|
@@ -39,8 +39,24 @@ codegen-verify: codegen ## Generate code and verify syntax
|
|
|
39
39
|
@echo ""
|
|
40
40
|
@echo "Code generation verified successfully!"
|
|
41
41
|
|
|
42
|
+
# The tests run in a virtual environment (the system Python on Homebrew and
|
|
43
|
+
# Ubuntu 24.04 refuses a global pip install, PEP 668) against the in-tree
|
|
44
|
+
# proto stubs, never PyPI's stigmer-apis, which lags the tree. VENV may sit
|
|
45
|
+
# outside the package, where a build here can never pack it.
|
|
46
|
+
VENV ?= .venv
|
|
47
|
+
PYTHON ?= python3
|
|
48
|
+
|
|
49
|
+
.PHONY: test
|
|
50
|
+
test: ## Run the SDK's tests against the in-tree proto stubs
|
|
51
|
+
@test -x $(VENV)/bin/python || $(PYTHON) -m venv $(VENV)
|
|
52
|
+
@# A .venv made by uv has no pip.
|
|
53
|
+
@$(VENV)/bin/python -m pip --version >/dev/null 2>&1 || $(VENV)/bin/python -m ensurepip --default-pip >/dev/null
|
|
54
|
+
@$(VENV)/bin/python -m pip install --quiet --disable-pip-version-check ../../apis/stubs/python/stigmer
|
|
55
|
+
@$(VENV)/bin/python -m pip install --quiet --disable-pip-version-check -e '.[test]'
|
|
56
|
+
@$(VENV)/bin/python -m pytest tests
|
|
57
|
+
|
|
42
58
|
.PHONY: clean
|
|
43
|
-
clean: ## Clean build artifacts
|
|
44
|
-
@rm -rf dist build *.egg-info src/*.egg-info
|
|
59
|
+
clean: ## Clean build artifacts and the test environment
|
|
60
|
+
@rm -rf dist build *.egg-info src/*.egg-info .venv .pytest_cache
|
|
45
61
|
|
|
46
62
|
.DEFAULT_GOAL := help
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: stigmer-sdk
|
|
3
|
-
Version: 0.1.
|
|
4
|
-
Summary:
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Python client for Stigmer, the open-source backend for the agents in your product
|
|
5
5
|
Project-URL: Homepage, https://stigmer.ai
|
|
6
6
|
Project-URL: Repository, https://github.com/stigmer/stigmer
|
|
7
|
-
Project-URL: Documentation, https://
|
|
7
|
+
Project-URL: Documentation, https://stigmer.ai/docs/sdk/python
|
|
8
8
|
Author-email: Stigmer <engineering@stigmer.ai>
|
|
9
9
|
License-Expression: Apache-2.0
|
|
10
10
|
Keywords: ai-agents,api-client,grpc,sdk,stigmer
|
|
@@ -19,12 +19,15 @@ Classifier: Typing :: Typed
|
|
|
19
19
|
Requires-Python: >=3.11
|
|
20
20
|
Requires-Dist: grpcio>=1.60.0
|
|
21
21
|
Requires-Dist: protobuf>=6.32.0
|
|
22
|
-
Requires-Dist: stigmer-apis==0.1.
|
|
22
|
+
Requires-Dist: stigmer-apis==0.1.2
|
|
23
|
+
Provides-Extra: test
|
|
24
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'test'
|
|
25
|
+
Requires-Dist: pytest>=8; extra == 'test'
|
|
23
26
|
Description-Content-Type: text/markdown
|
|
24
27
|
|
|
25
28
|
# stigmer
|
|
26
29
|
|
|
27
|
-
Python
|
|
30
|
+
Python client for [Stigmer](https://stigmer.ai), the open-source backend for the agents in your product. Provides typed API clients for every Stigmer resource with authentication, error handling, and cross-resource search.
|
|
28
31
|
|
|
29
32
|
## Installation
|
|
30
33
|
|
|
@@ -36,21 +39,54 @@ pip install stigmer-sdk
|
|
|
36
39
|
|
|
37
40
|
## Quick Start
|
|
38
41
|
|
|
42
|
+
Before you start, run Stigmer on your machine with `stigmer up` and give it a model key ([Start Stigmer and add your model key](https://stigmer.ai/docs/getting-started/quickstart#start-stigmer-and-add-your-model-key)). Without a key the server refuses the message, and the program prints why.
|
|
43
|
+
|
|
44
|
+
This program connects to that Stigmer, sets up a small agent, asks it one thing and prints its answer:
|
|
45
|
+
|
|
39
46
|
```python
|
|
40
|
-
|
|
47
|
+
"""The Stigmer quick start: connect to the Stigmer running on this machine,
|
|
48
|
+
set up a small agent, ask it one thing and print its answer.
|
|
49
|
+
|
|
50
|
+
Start Stigmer first with `stigmer up` (given a model key), then:
|
|
51
|
+
python quickstart.py
|
|
52
|
+
"""
|
|
53
|
+
|
|
54
|
+
import sys
|
|
55
|
+
|
|
56
|
+
from stigmer import AgentInput, ResourceRef, SessionSpecInput, StigmerClient, StigmerError
|
|
57
|
+
|
|
58
|
+
try:
|
|
59
|
+
# `stigmer up` serves on localhost:7234 and needs no key on your machine.
|
|
60
|
+
with StigmerClient(base_url="localhost:7234", insecure=True) as client:
|
|
61
|
+
# apply creates the agent, or updates it when you run this again.
|
|
62
|
+
agent = client.agents.apply(
|
|
63
|
+
AgentInput(
|
|
64
|
+
name="greeter",
|
|
65
|
+
org="stigmer",
|
|
66
|
+
instructions="You greet people in one short, friendly sentence.",
|
|
67
|
+
)
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
turn = client.send_and_wait(
|
|
71
|
+
org="stigmer",
|
|
72
|
+
session_spec=SessionSpecInput(agent_ref=ResourceRef(org="stigmer", slug=agent.metadata.slug)),
|
|
73
|
+
message="Say hello to a developer trying Stigmer for the first time.",
|
|
74
|
+
)
|
|
75
|
+
except StigmerError as err:
|
|
76
|
+
sys.exit(f"stigmer: {err}")
|
|
41
77
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
78
|
+
if turn.phase != "completed":
|
|
79
|
+
sys.exit(f"the turn did not complete ({turn.phase}): {turn.error}")
|
|
80
|
+
print(turn.answer)
|
|
45
81
|
```
|
|
46
82
|
|
|
47
|
-
|
|
83
|
+
It is `examples/quickstart.py`. Run `python quickstart.py`; it prints the agent's answer, for example "Hello, and welcome to Stigmer!".
|
|
48
84
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
85
|
+
`send_and_wait` sends the message and waits for the agent's answer, reconnecting if the stream drops. A turn that waits for a person's approval returns with `phase` `"waiting"` and its `asks`; answer them with `client.sessions.confirm_tool_use` and call `client.wait_for_turn` with the outcome's `last_seq`.
|
|
86
|
+
|
|
87
|
+
### On Stigmer Cloud
|
|
88
|
+
|
|
89
|
+
Make two changes: connect with an API key, `StigmerClient(os.environ["STIGMER_API_KEY"])` (keys read `stk_…`), and use your own organization, `os.environ["STIGMER_ORG"]`, where the program says `"stigmer"`.
|
|
54
90
|
|
|
55
91
|
## Resource Clients
|
|
56
92
|
|
|
@@ -75,16 +111,18 @@ Every resource type has a typed client accessible as a property on `StigmerClien
|
|
|
75
111
|
## Common Operations
|
|
76
112
|
|
|
77
113
|
```python
|
|
114
|
+
import os
|
|
115
|
+
|
|
78
116
|
from ai.stigmer.agentic.agent.v1 import io_pb2 as agent_io_pb2
|
|
79
117
|
from ai.stigmer.commons.apiresource import io_pb2 as apiresource_io_pb2
|
|
80
118
|
from stigmer import StigmerClient, AgentInput, ResourceRef
|
|
81
119
|
|
|
82
|
-
with StigmerClient("
|
|
120
|
+
with StigmerClient(os.environ["STIGMER_API_KEY"]) as client:
|
|
83
121
|
# Create
|
|
84
122
|
agent = client.agents.create(AgentInput(
|
|
85
123
|
name="my-agent",
|
|
86
124
|
org="my-org",
|
|
87
|
-
description="
|
|
125
|
+
description="Turns a customer's ledger into a variance report",
|
|
88
126
|
instructions="Be helpful and concise.",
|
|
89
127
|
))
|
|
90
128
|
|
|
@@ -104,7 +142,7 @@ with StigmerClient("sk_live_abc123") as client:
|
|
|
104
142
|
# Rename: change the slug people type. The id stays, so everything that
|
|
105
143
|
# points at the agent keeps working; the old slug reads for 30 days.
|
|
106
144
|
renamed = client.agents.rename(
|
|
107
|
-
apiresource_io_pb2.RenameInput(resource_id="agent-id", slug="
|
|
145
|
+
apiresource_io_pb2.RenameInput(resource_id="agent-id", slug="variance-reporter")
|
|
108
146
|
)
|
|
109
147
|
|
|
110
148
|
# Delete
|
|
@@ -119,21 +157,23 @@ with StigmerClient("sk_live_abc123") as client:
|
|
|
119
157
|
print(a.metadata.slug)
|
|
120
158
|
|
|
121
159
|
# Only the agents carrying every label given.
|
|
122
|
-
|
|
123
|
-
agent_io_pb2.ListAgentsRequest(org="my-org", labels={"team": "
|
|
160
|
+
finance = client.agents.list(
|
|
161
|
+
agent_io_pb2.ListAgentsRequest(org="my-org", labels={"team": "finance"})
|
|
124
162
|
)
|
|
125
163
|
```
|
|
126
164
|
|
|
127
165
|
## Cross-Resource Search
|
|
128
166
|
|
|
129
167
|
```python
|
|
168
|
+
import os
|
|
169
|
+
|
|
130
170
|
from stigmer import StigmerClient, ApiResourceKind, SearchParams
|
|
131
171
|
|
|
132
|
-
with StigmerClient("
|
|
172
|
+
with StigmerClient(os.environ["STIGMER_API_KEY"]) as client:
|
|
133
173
|
results = client.search.query(SearchParams(
|
|
134
174
|
kinds=[ApiResourceKind.agent, ApiResourceKind.skill],
|
|
135
175
|
org="my-org",
|
|
136
|
-
query="
|
|
176
|
+
query="variance report",
|
|
137
177
|
))
|
|
138
178
|
```
|
|
139
179
|
|
|
@@ -147,6 +187,8 @@ Pass `access_token` to the React SDK's `StigmerProvider` through
|
|
|
147
187
|
`getAccessToken`:
|
|
148
188
|
|
|
149
189
|
```python
|
|
190
|
+
import os
|
|
191
|
+
|
|
150
192
|
from stigmer import StigmerClient
|
|
151
193
|
|
|
152
194
|
with StigmerClient(os.environ["STIGMER_API_KEY"]) as client:
|
|
@@ -172,9 +214,11 @@ billing commands require `can_manage_billing`. The operator pricing methods
|
|
|
172
214
|
platform:
|
|
173
215
|
|
|
174
216
|
```python
|
|
217
|
+
import os
|
|
218
|
+
|
|
175
219
|
from stigmer import CreatePaymentMethodSetupSessionParams, StigmerClient
|
|
176
220
|
|
|
177
|
-
with StigmerClient("
|
|
221
|
+
with StigmerClient(os.environ["STIGMER_API_KEY"]) as client:
|
|
178
222
|
account = client.billing.get_billing_account(org)
|
|
179
223
|
|
|
180
224
|
setup = client.billing.create_payment_method_setup_session(
|
|
@@ -191,9 +235,11 @@ with StigmerClient("sk_live_abc123") as client:
|
|
|
191
235
|
All SDK operations raise `StigmerError` with structured error codes:
|
|
192
236
|
|
|
193
237
|
```python
|
|
238
|
+
import os
|
|
239
|
+
|
|
194
240
|
from stigmer import StigmerClient, StigmerError, is_not_found, is_retryable
|
|
195
241
|
|
|
196
|
-
with StigmerClient("
|
|
242
|
+
with StigmerClient(os.environ["STIGMER_API_KEY"]) as client:
|
|
197
243
|
try:
|
|
198
244
|
agent = client.agents.get("nonexistent")
|
|
199
245
|
except StigmerError as err:
|
|
@@ -211,13 +257,21 @@ Error codes: `not-found`, `permission-denied`, `unauthenticated`, `invalid-argum
|
|
|
211
257
|
|
|
212
258
|
```python
|
|
213
259
|
StigmerClient(
|
|
214
|
-
api_key: str,
|
|
260
|
+
api_key: str | None = None, # Stigmer API key, "stk_…" (required unless insecure)
|
|
215
261
|
*,
|
|
216
262
|
base_url: str = "api.stigmer.ai:443", # gRPC target address
|
|
217
263
|
insecure: bool = False, # Skip TLS (local development only)
|
|
218
264
|
)
|
|
219
265
|
```
|
|
220
266
|
|
|
267
|
+
On your machine, `stigmer up` serves on `localhost:7234` and needs no key; leave the key out on that plain-text connection, and the client sends no `authorization` header:
|
|
268
|
+
|
|
269
|
+
```python
|
|
270
|
+
client = StigmerClient(base_url="localhost:7234", insecure=True)
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
A client with no key on a TLS connection is refused at construction, as is an empty key.
|
|
274
|
+
|
|
221
275
|
For a CI job or a script, use a [service account's](https://stigmer.ai/docs/guides/authentication/service-accounts) API key, not a person's: it keeps working when that person leaves and works only in its own organization.
|
|
222
276
|
|
|
223
277
|
## Code Generation
|
|
@@ -229,4 +283,13 @@ cd sdk/python
|
|
|
229
283
|
make codegen
|
|
230
284
|
```
|
|
231
285
|
|
|
232
|
-
Handwritten code lives in `src/stigmer/` (outside `_gen/`): `_client.py`, `_transport.py`, `_interceptors.py`, `_search.py`, `_tokens.py`, and `__init__.py`.
|
|
286
|
+
Handwritten code lives in `src/stigmer/` (outside `_gen/`): `_client.py`, `_transport.py`, `_interceptors.py`, `_search.py`, `_tokens.py`, `_turns.py`, and `__init__.py`.
|
|
287
|
+
|
|
288
|
+
## Tests
|
|
289
|
+
|
|
290
|
+
```bash
|
|
291
|
+
cd sdk/python
|
|
292
|
+
make test
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
It makes a virtual environment in `.venv`, installs the SDK and the proto stubs from this repository into it (not PyPI's `stigmer-apis`, which can lag the tree), and runs `pytest`. `make clean` removes the environment.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# stigmer
|
|
2
2
|
|
|
3
|
-
Python
|
|
3
|
+
Python client for [Stigmer](https://stigmer.ai), the open-source backend for the agents in your product. Provides typed API clients for every Stigmer resource with authentication, error handling, and cross-resource search.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -12,21 +12,54 @@ pip install stigmer-sdk
|
|
|
12
12
|
|
|
13
13
|
## Quick Start
|
|
14
14
|
|
|
15
|
+
Before you start, run Stigmer on your machine with `stigmer up` and give it a model key ([Start Stigmer and add your model key](https://stigmer.ai/docs/getting-started/quickstart#start-stigmer-and-add-your-model-key)). Without a key the server refuses the message, and the program prints why.
|
|
16
|
+
|
|
17
|
+
This program connects to that Stigmer, sets up a small agent, asks it one thing and prints its answer:
|
|
18
|
+
|
|
15
19
|
```python
|
|
16
|
-
|
|
20
|
+
"""The Stigmer quick start: connect to the Stigmer running on this machine,
|
|
21
|
+
set up a small agent, ask it one thing and print its answer.
|
|
22
|
+
|
|
23
|
+
Start Stigmer first with `stigmer up` (given a model key), then:
|
|
24
|
+
python quickstart.py
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
import sys
|
|
28
|
+
|
|
29
|
+
from stigmer import AgentInput, ResourceRef, SessionSpecInput, StigmerClient, StigmerError
|
|
30
|
+
|
|
31
|
+
try:
|
|
32
|
+
# `stigmer up` serves on localhost:7234 and needs no key on your machine.
|
|
33
|
+
with StigmerClient(base_url="localhost:7234", insecure=True) as client:
|
|
34
|
+
# apply creates the agent, or updates it when you run this again.
|
|
35
|
+
agent = client.agents.apply(
|
|
36
|
+
AgentInput(
|
|
37
|
+
name="greeter",
|
|
38
|
+
org="stigmer",
|
|
39
|
+
instructions="You greet people in one short, friendly sentence.",
|
|
40
|
+
)
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
turn = client.send_and_wait(
|
|
44
|
+
org="stigmer",
|
|
45
|
+
session_spec=SessionSpecInput(agent_ref=ResourceRef(org="stigmer", slug=agent.metadata.slug)),
|
|
46
|
+
message="Say hello to a developer trying Stigmer for the first time.",
|
|
47
|
+
)
|
|
48
|
+
except StigmerError as err:
|
|
49
|
+
sys.exit(f"stigmer: {err}")
|
|
17
50
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
51
|
+
if turn.phase != "completed":
|
|
52
|
+
sys.exit(f"the turn did not complete ({turn.phase}): {turn.error}")
|
|
53
|
+
print(turn.answer)
|
|
21
54
|
```
|
|
22
55
|
|
|
23
|
-
|
|
56
|
+
It is `examples/quickstart.py`. Run `python quickstart.py`; it prints the agent's answer, for example "Hello, and welcome to Stigmer!".
|
|
24
57
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
58
|
+
`send_and_wait` sends the message and waits for the agent's answer, reconnecting if the stream drops. A turn that waits for a person's approval returns with `phase` `"waiting"` and its `asks`; answer them with `client.sessions.confirm_tool_use` and call `client.wait_for_turn` with the outcome's `last_seq`.
|
|
59
|
+
|
|
60
|
+
### On Stigmer Cloud
|
|
61
|
+
|
|
62
|
+
Make two changes: connect with an API key, `StigmerClient(os.environ["STIGMER_API_KEY"])` (keys read `stk_…`), and use your own organization, `os.environ["STIGMER_ORG"]`, where the program says `"stigmer"`.
|
|
30
63
|
|
|
31
64
|
## Resource Clients
|
|
32
65
|
|
|
@@ -51,16 +84,18 @@ Every resource type has a typed client accessible as a property on `StigmerClien
|
|
|
51
84
|
## Common Operations
|
|
52
85
|
|
|
53
86
|
```python
|
|
87
|
+
import os
|
|
88
|
+
|
|
54
89
|
from ai.stigmer.agentic.agent.v1 import io_pb2 as agent_io_pb2
|
|
55
90
|
from ai.stigmer.commons.apiresource import io_pb2 as apiresource_io_pb2
|
|
56
91
|
from stigmer import StigmerClient, AgentInput, ResourceRef
|
|
57
92
|
|
|
58
|
-
with StigmerClient("
|
|
93
|
+
with StigmerClient(os.environ["STIGMER_API_KEY"]) as client:
|
|
59
94
|
# Create
|
|
60
95
|
agent = client.agents.create(AgentInput(
|
|
61
96
|
name="my-agent",
|
|
62
97
|
org="my-org",
|
|
63
|
-
description="
|
|
98
|
+
description="Turns a customer's ledger into a variance report",
|
|
64
99
|
instructions="Be helpful and concise.",
|
|
65
100
|
))
|
|
66
101
|
|
|
@@ -80,7 +115,7 @@ with StigmerClient("sk_live_abc123") as client:
|
|
|
80
115
|
# Rename: change the slug people type. The id stays, so everything that
|
|
81
116
|
# points at the agent keeps working; the old slug reads for 30 days.
|
|
82
117
|
renamed = client.agents.rename(
|
|
83
|
-
apiresource_io_pb2.RenameInput(resource_id="agent-id", slug="
|
|
118
|
+
apiresource_io_pb2.RenameInput(resource_id="agent-id", slug="variance-reporter")
|
|
84
119
|
)
|
|
85
120
|
|
|
86
121
|
# Delete
|
|
@@ -95,21 +130,23 @@ with StigmerClient("sk_live_abc123") as client:
|
|
|
95
130
|
print(a.metadata.slug)
|
|
96
131
|
|
|
97
132
|
# Only the agents carrying every label given.
|
|
98
|
-
|
|
99
|
-
agent_io_pb2.ListAgentsRequest(org="my-org", labels={"team": "
|
|
133
|
+
finance = client.agents.list(
|
|
134
|
+
agent_io_pb2.ListAgentsRequest(org="my-org", labels={"team": "finance"})
|
|
100
135
|
)
|
|
101
136
|
```
|
|
102
137
|
|
|
103
138
|
## Cross-Resource Search
|
|
104
139
|
|
|
105
140
|
```python
|
|
141
|
+
import os
|
|
142
|
+
|
|
106
143
|
from stigmer import StigmerClient, ApiResourceKind, SearchParams
|
|
107
144
|
|
|
108
|
-
with StigmerClient("
|
|
145
|
+
with StigmerClient(os.environ["STIGMER_API_KEY"]) as client:
|
|
109
146
|
results = client.search.query(SearchParams(
|
|
110
147
|
kinds=[ApiResourceKind.agent, ApiResourceKind.skill],
|
|
111
148
|
org="my-org",
|
|
112
|
-
query="
|
|
149
|
+
query="variance report",
|
|
113
150
|
))
|
|
114
151
|
```
|
|
115
152
|
|
|
@@ -123,6 +160,8 @@ Pass `access_token` to the React SDK's `StigmerProvider` through
|
|
|
123
160
|
`getAccessToken`:
|
|
124
161
|
|
|
125
162
|
```python
|
|
163
|
+
import os
|
|
164
|
+
|
|
126
165
|
from stigmer import StigmerClient
|
|
127
166
|
|
|
128
167
|
with StigmerClient(os.environ["STIGMER_API_KEY"]) as client:
|
|
@@ -148,9 +187,11 @@ billing commands require `can_manage_billing`. The operator pricing methods
|
|
|
148
187
|
platform:
|
|
149
188
|
|
|
150
189
|
```python
|
|
190
|
+
import os
|
|
191
|
+
|
|
151
192
|
from stigmer import CreatePaymentMethodSetupSessionParams, StigmerClient
|
|
152
193
|
|
|
153
|
-
with StigmerClient("
|
|
194
|
+
with StigmerClient(os.environ["STIGMER_API_KEY"]) as client:
|
|
154
195
|
account = client.billing.get_billing_account(org)
|
|
155
196
|
|
|
156
197
|
setup = client.billing.create_payment_method_setup_session(
|
|
@@ -167,9 +208,11 @@ with StigmerClient("sk_live_abc123") as client:
|
|
|
167
208
|
All SDK operations raise `StigmerError` with structured error codes:
|
|
168
209
|
|
|
169
210
|
```python
|
|
211
|
+
import os
|
|
212
|
+
|
|
170
213
|
from stigmer import StigmerClient, StigmerError, is_not_found, is_retryable
|
|
171
214
|
|
|
172
|
-
with StigmerClient("
|
|
215
|
+
with StigmerClient(os.environ["STIGMER_API_KEY"]) as client:
|
|
173
216
|
try:
|
|
174
217
|
agent = client.agents.get("nonexistent")
|
|
175
218
|
except StigmerError as err:
|
|
@@ -187,13 +230,21 @@ Error codes: `not-found`, `permission-denied`, `unauthenticated`, `invalid-argum
|
|
|
187
230
|
|
|
188
231
|
```python
|
|
189
232
|
StigmerClient(
|
|
190
|
-
api_key: str,
|
|
233
|
+
api_key: str | None = None, # Stigmer API key, "stk_…" (required unless insecure)
|
|
191
234
|
*,
|
|
192
235
|
base_url: str = "api.stigmer.ai:443", # gRPC target address
|
|
193
236
|
insecure: bool = False, # Skip TLS (local development only)
|
|
194
237
|
)
|
|
195
238
|
```
|
|
196
239
|
|
|
240
|
+
On your machine, `stigmer up` serves on `localhost:7234` and needs no key; leave the key out on that plain-text connection, and the client sends no `authorization` header:
|
|
241
|
+
|
|
242
|
+
```python
|
|
243
|
+
client = StigmerClient(base_url="localhost:7234", insecure=True)
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
A client with no key on a TLS connection is refused at construction, as is an empty key.
|
|
247
|
+
|
|
197
248
|
For a CI job or a script, use a [service account's](https://stigmer.ai/docs/guides/authentication/service-accounts) API key, not a person's: it keeps working when that person leaves and works only in its own organization.
|
|
198
249
|
|
|
199
250
|
## Code Generation
|
|
@@ -205,4 +256,13 @@ cd sdk/python
|
|
|
205
256
|
make codegen
|
|
206
257
|
```
|
|
207
258
|
|
|
208
|
-
Handwritten code lives in `src/stigmer/` (outside `_gen/`): `_client.py`, `_transport.py`, `_interceptors.py`, `_search.py`, `_tokens.py`, and `__init__.py`.
|
|
259
|
+
Handwritten code lives in `src/stigmer/` (outside `_gen/`): `_client.py`, `_transport.py`, `_interceptors.py`, `_search.py`, `_tokens.py`, `_turns.py`, and `__init__.py`.
|
|
260
|
+
|
|
261
|
+
## Tests
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
cd sdk/python
|
|
265
|
+
make test
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
It makes a virtual environment in `.venv`, installs the SDK and the proto stubs from this repository into it (not PyPI's `stigmer-apis`, which can lag the tree), and runs `pytest`. `make clean` removes the environment.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""The Stigmer quick start: connect to the Stigmer running on this machine,
|
|
2
|
+
set up a small agent, ask it one thing and print its answer.
|
|
3
|
+
|
|
4
|
+
Start Stigmer first with `stigmer up` (given a model key), then:
|
|
5
|
+
python quickstart.py
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
from stigmer import AgentInput, ResourceRef, SessionSpecInput, StigmerClient, StigmerError
|
|
11
|
+
|
|
12
|
+
try:
|
|
13
|
+
# `stigmer up` serves on localhost:7234 and needs no key on your machine.
|
|
14
|
+
with StigmerClient(base_url="localhost:7234", insecure=True) as client:
|
|
15
|
+
# apply creates the agent, or updates it when you run this again.
|
|
16
|
+
agent = client.agents.apply(
|
|
17
|
+
AgentInput(
|
|
18
|
+
name="greeter",
|
|
19
|
+
org="stigmer",
|
|
20
|
+
instructions="You greet people in one short, friendly sentence.",
|
|
21
|
+
)
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
turn = client.send_and_wait(
|
|
25
|
+
org="stigmer",
|
|
26
|
+
session_spec=SessionSpecInput(agent_ref=ResourceRef(org="stigmer", slug=agent.metadata.slug)),
|
|
27
|
+
message="Say hello to a developer trying Stigmer for the first time.",
|
|
28
|
+
)
|
|
29
|
+
except StigmerError as err:
|
|
30
|
+
sys.exit(f"stigmer: {err}")
|
|
31
|
+
|
|
32
|
+
if turn.phase != "completed":
|
|
33
|
+
sys.exit(f"the turn did not complete ({turn.phase}): {turn.error}")
|
|
34
|
+
print(turn.answer)
|
|
@@ -4,8 +4,8 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "stigmer-sdk"
|
|
7
|
-
version = "0.1.
|
|
8
|
-
description = "
|
|
7
|
+
version = "0.1.2"
|
|
8
|
+
description = "Python client for Stigmer, the open-source backend for the agents in your product"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
11
11
|
license = "Apache-2.0"
|
|
@@ -24,13 +24,20 @@ classifiers = [
|
|
|
24
24
|
dependencies = [
|
|
25
25
|
"grpcio>=1.60.0",
|
|
26
26
|
"protobuf>=6.32.0",
|
|
27
|
-
"stigmer-apis==0.1.
|
|
27
|
+
"stigmer-apis==0.1.2",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
# Installed by `make test`, never by users of the published package.
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
test = [
|
|
33
|
+
"pytest>=8",
|
|
34
|
+
"pytest-asyncio>=0.23",
|
|
28
35
|
]
|
|
29
36
|
|
|
30
37
|
[project.urls]
|
|
31
38
|
Homepage = "https://stigmer.ai"
|
|
32
39
|
Repository = "https://github.com/stigmer/stigmer"
|
|
33
|
-
Documentation = "https://
|
|
40
|
+
Documentation = "https://stigmer.ai/docs/sdk/python"
|
|
34
41
|
|
|
35
42
|
[tool.hatch.build.targets.wheel]
|
|
36
43
|
packages = ["src/stigmer"]
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Python client for Stigmer, the open-source backend for the agents in your product.
|
|
2
2
|
|
|
3
3
|
Usage::
|
|
4
4
|
|
|
5
|
+
import os
|
|
6
|
+
|
|
5
7
|
from stigmer import StigmerClient, AgentInput
|
|
6
8
|
|
|
7
|
-
with StigmerClient("
|
|
9
|
+
with StigmerClient(os.environ["STIGMER_API_KEY"]) as client:
|
|
8
10
|
agent = client.agents.create(AgentInput(name="my-agent", org="my-org"))
|
|
9
11
|
print(agent.metadata.name)
|
|
10
12
|
"""
|
|
@@ -21,6 +23,7 @@ from ._runner_adapter import RunnerAdapter
|
|
|
21
23
|
from ._github import GitHubClient, GitHubRepoParams
|
|
22
24
|
from ._search import ApiResourceKind, SearchClient, SearchParams, SearchResponse
|
|
23
25
|
from ._tokens import MintUserTokenResult, TokenClient
|
|
26
|
+
from ._turns import TURN_PHASE_WAITING, TurnAsk, TurnOutcome
|
|
24
27
|
|
|
25
28
|
# --- Resource clients and input types (generated) --------------------------
|
|
26
29
|
|
|
@@ -32,23 +35,24 @@ from ._gen._agent import (
|
|
|
32
35
|
)
|
|
33
36
|
from ._gen._apikey import ApiKeyClient, ApiKeyInput
|
|
34
37
|
from ._gen._federationissuer import FederationIssuerClient, FederationIssuerInput
|
|
38
|
+
from ._gen._file import FileClient, FileInput
|
|
35
39
|
from ._gen._grant import ApiResourceRefInput, GrantClient, GrantInput
|
|
36
40
|
from ._gen._identityaccount import IdentityAccountClient, IdentityAccountInput
|
|
37
41
|
from ._gen._oauthapp import OAuthAppClient, OAuthAppInput
|
|
38
42
|
from ._gen._organization import OrganizationClient, OrganizationInput
|
|
39
43
|
from ._gen._plugin import PluginClient
|
|
40
44
|
from ._gen._run import (
|
|
41
|
-
AttachmentInput,
|
|
42
45
|
RunClient,
|
|
43
46
|
RunInput,
|
|
47
|
+
SessionSpecInput,
|
|
44
48
|
)
|
|
45
49
|
from ._gen._session import (
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
FileResourceInput,
|
|
51
|
+
GitRepositoryResourceInput,
|
|
52
|
+
LocalPathResourceInput,
|
|
48
53
|
SessionClient,
|
|
49
54
|
SessionInput,
|
|
50
|
-
|
|
51
|
-
WorkspaceSourceInput,
|
|
55
|
+
SessionResourceInput,
|
|
52
56
|
)
|
|
53
57
|
from ._gen._skill import SkillClient, SkillInput
|
|
54
58
|
from ._gen._vault import (
|
|
@@ -59,6 +63,7 @@ from ._gen._vault import (
|
|
|
59
63
|
VaultSecretInput,
|
|
60
64
|
)
|
|
61
65
|
from ._skill import MAX_INLINE_ARTIFACT_BYTES, RoutedSkillClient
|
|
66
|
+
from ._file import FileContent, RoutedFileClient
|
|
62
67
|
|
|
63
68
|
# --- Shared types (generated) ----------------------------------------------
|
|
64
69
|
|
|
@@ -101,10 +106,15 @@ __all__ = [
|
|
|
101
106
|
# User tokens
|
|
102
107
|
"MintUserTokenResult",
|
|
103
108
|
"TokenClient",
|
|
109
|
+
# Send a message and wait for the answer
|
|
110
|
+
"TURN_PHASE_WAITING",
|
|
111
|
+
"TurnAsk",
|
|
112
|
+
"TurnOutcome",
|
|
104
113
|
# Resource clients
|
|
105
114
|
"AgentClient",
|
|
106
115
|
"ApiKeyClient",
|
|
107
116
|
"FederationIssuerClient",
|
|
117
|
+
"FileClient",
|
|
108
118
|
"GrantClient",
|
|
109
119
|
"IdentityAccountClient",
|
|
110
120
|
"OAuthAppClient",
|
|
@@ -115,31 +125,34 @@ __all__ = [
|
|
|
115
125
|
"SkillClient",
|
|
116
126
|
"VaultClient",
|
|
117
127
|
"RoutedSkillClient",
|
|
128
|
+
"RoutedFileClient",
|
|
129
|
+
"FileContent",
|
|
118
130
|
"MAX_INLINE_ARTIFACT_BYTES",
|
|
119
131
|
# Input types
|
|
120
132
|
"AgentInput",
|
|
121
133
|
"AgentMcpServerInput",
|
|
122
134
|
"ApiKeyInput",
|
|
123
135
|
"ApiResourceRefInput",
|
|
124
|
-
"AttachmentInput",
|
|
125
136
|
"DeleteResourceInput",
|
|
126
137
|
"FederationIssuerInput",
|
|
127
|
-
"
|
|
138
|
+
"FileInput",
|
|
139
|
+
"FileResourceInput",
|
|
140
|
+
"GitRepositoryResourceInput",
|
|
128
141
|
"GrantInput",
|
|
129
142
|
"IdentityAccountInput",
|
|
130
|
-
"
|
|
143
|
+
"LocalPathResourceInput",
|
|
131
144
|
"OAuthAppInput",
|
|
132
145
|
"OrganizationInput",
|
|
133
146
|
"RunInput",
|
|
134
147
|
"RunConfigInput",
|
|
135
148
|
"SessionInput",
|
|
149
|
+
"SessionSpecInput",
|
|
150
|
+
"SessionResourceInput",
|
|
136
151
|
"SkillInput",
|
|
137
152
|
"VaultConnectionInput",
|
|
138
153
|
"VaultConnectionSignInInput",
|
|
139
154
|
"VaultInput",
|
|
140
155
|
"VaultSecretInput",
|
|
141
|
-
"WorkspaceEntryInput",
|
|
142
|
-
"WorkspaceSourceInput",
|
|
143
156
|
# Shared types
|
|
144
157
|
"ResourceRef",
|
|
145
158
|
# Errors
|