kindgi 0.1.3__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.
- kindgi-0.1.3/.gitignore +79 -0
- kindgi-0.1.3/CHANGELOG.md +1 -0
- kindgi-0.1.3/LICENSE +201 -0
- kindgi-0.1.3/PKG-INFO +401 -0
- kindgi-0.1.3/README.md +377 -0
- kindgi-0.1.3/pyproject.toml +94 -0
- kindgi-0.1.3/src/kindgi/__init__.py +51 -0
- kindgi-0.1.3/src/kindgi/_json.py +115 -0
- kindgi-0.1.3/src/kindgi/_schema.py +502 -0
- kindgi-0.1.3/src/kindgi/_specs/__init__.py +4 -0
- kindgi-0.1.3/src/kindgi/_specs/flow.schema.json +517 -0
- kindgi-0.1.3/src/kindgi/_specs/pack-index.schema.json +277 -0
- kindgi-0.1.3/src/kindgi/_specs/pack-protocol.schema.json +236 -0
- kindgi-0.1.3/src/kindgi/_specs/tool.schema.json +297 -0
- kindgi-0.1.3/src/kindgi/_version.py +9 -0
- kindgi-0.1.3/src/kindgi/client/__init__.py +59 -0
- kindgi-0.1.3/src/kindgi/client/_base.py +378 -0
- kindgi-0.1.3/src/kindgi/client/_client.py +134 -0
- kindgi-0.1.3/src/kindgi/client/_errors.py +228 -0
- kindgi-0.1.3/src/kindgi/client/_models.py +6399 -0
- kindgi-0.1.3/src/kindgi/client/_resources.py +10442 -0
- kindgi-0.1.3/src/kindgi/client/_runtime_config.py +159 -0
- kindgi-0.1.3/src/kindgi/client/_sse.py +61 -0
- kindgi-0.1.3/src/kindgi/pack/__init__.py +4 -0
- kindgi-0.1.3/src/kindgi/pack/__main__.py +79 -0
- kindgi-0.1.3/src/kindgi/pack/config.py +220 -0
- kindgi-0.1.3/src/kindgi/pack/context.py +143 -0
- kindgi-0.1.3/src/kindgi/pack/define.py +588 -0
- kindgi-0.1.3/src/kindgi/pack/discovery.py +87 -0
- kindgi-0.1.3/src/kindgi/pack/index.py +460 -0
- kindgi-0.1.3/src/kindgi/pack/loader.py +88 -0
- kindgi-0.1.3/src/kindgi/pack/protocol.py +155 -0
- kindgi-0.1.3/src/kindgi/pack/serve.py +248 -0
- kindgi-0.1.3/src/kindgi/pack/service.py +674 -0
- kindgi-0.1.3/src/kindgi/pack/trace.py +80 -0
- kindgi-0.1.3/src/kindgi/py.typed +0 -0
- kindgi-0.1.3/src/kindgi/webhooks.py +256 -0
kindgi-0.1.3/.gitignore
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Dependencies
|
|
2
|
+
node_modules/
|
|
3
|
+
.pnpm-store/
|
|
4
|
+
.pnpm-debug.log*
|
|
5
|
+
|
|
6
|
+
# Build output
|
|
7
|
+
dist/
|
|
8
|
+
.astro/
|
|
9
|
+
build/
|
|
10
|
+
out/
|
|
11
|
+
*.tsbuildinfo
|
|
12
|
+
.turbo/
|
|
13
|
+
|
|
14
|
+
# Test + coverage
|
|
15
|
+
coverage/
|
|
16
|
+
.vitest/
|
|
17
|
+
*.log
|
|
18
|
+
|
|
19
|
+
# Environment
|
|
20
|
+
.env
|
|
21
|
+
.env.local
|
|
22
|
+
.env.*.local
|
|
23
|
+
!.env.example
|
|
24
|
+
|
|
25
|
+
# Editor
|
|
26
|
+
.vscode/*
|
|
27
|
+
!.vscode/settings.example.json
|
|
28
|
+
!.vscode/extensions.json
|
|
29
|
+
.idea/
|
|
30
|
+
*.swp
|
|
31
|
+
*.swo
|
|
32
|
+
.DS_Store
|
|
33
|
+
Thumbs.db
|
|
34
|
+
|
|
35
|
+
# OS
|
|
36
|
+
.DS_Store
|
|
37
|
+
._*
|
|
38
|
+
|
|
39
|
+
# Docker
|
|
40
|
+
.docker-data/
|
|
41
|
+
|
|
42
|
+
# Local data volumes (docker-compose)
|
|
43
|
+
data/postgres/
|
|
44
|
+
data/minio/
|
|
45
|
+
|
|
46
|
+
# Temporary
|
|
47
|
+
tmp/
|
|
48
|
+
temp/
|
|
49
|
+
*.tmp
|
|
50
|
+
|
|
51
|
+
# Local chat transcripts from coding assistants
|
|
52
|
+
chats/
|
|
53
|
+
|
|
54
|
+
# Local pack test tarballs (from `pnpm pack`)
|
|
55
|
+
*.tgz
|
|
56
|
+
|
|
57
|
+
# Local scratch notes (never committed)
|
|
58
|
+
.scratch/
|
|
59
|
+
|
|
60
|
+
# Python (sdks/python)
|
|
61
|
+
.venv/
|
|
62
|
+
__pycache__/
|
|
63
|
+
*.py[cod]
|
|
64
|
+
.pytest_cache/
|
|
65
|
+
.ruff_cache/
|
|
66
|
+
*.egg-info/
|
|
67
|
+
|
|
68
|
+
# The docs site's generated reference pages (site/scripts/generate-reference.mjs)
|
|
69
|
+
site/src/content/docs/reference/cli/
|
|
70
|
+
site/src/content/docs/reference/env-vars.md
|
|
71
|
+
site/src/content/docs/reference/schemas/
|
|
72
|
+
site/src/content/docs/reference/packages/
|
|
73
|
+
site/src/content/docs/reference/typescript/
|
|
74
|
+
site/src/content/docs/reference/python/
|
|
75
|
+
site/src/content/docs/contributing/*
|
|
76
|
+
!site/src/content/docs/contributing/index.md
|
|
77
|
+
site/generated/
|
|
78
|
+
site/dist-versions/
|
|
79
|
+
site/dist-preview/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#
|
kindgi-0.1.3/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Kindgi Inc.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
kindgi-0.1.3/PKG-INFO
ADDED
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: kindgi
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: Python SDK for Kindgi™ — write a pack's tools and guardrail checks in Python, run them in a Kindgi pack service, and call the Kindgi API.
|
|
5
|
+
Project-URL: Homepage, https://github.com/kindgi/kindgi-sdk/tree/main/sdks/python#readme
|
|
6
|
+
Project-URL: Repository, https://github.com/kindgi/kindgi-sdk
|
|
7
|
+
Project-URL: Issues, https://github.com/kindgi/kindgi-sdk/issues
|
|
8
|
+
Author: Kindgi Inc.
|
|
9
|
+
License: Apache-2.0
|
|
10
|
+
Keywords: agents,ai,kindgi,tools,workflows
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Requires-Dist: httpx<1,>=0.27
|
|
20
|
+
Requires-Dist: jsonschema<5,>=4.18
|
|
21
|
+
Requires-Dist: pydantic<3,>=2.10
|
|
22
|
+
Requires-Dist: uvicorn<1,>=0.27
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# `kindgi` — Kindgi™ for Python
|
|
26
|
+
|
|
27
|
+
Write a Kindgi pack's **tools** and **guardrail checks** in Python — agents
|
|
28
|
+
and flows are data, declared next to them — and call the Kindgi API from
|
|
29
|
+
Python. The Kindgi runtime calls your code over
|
|
30
|
+
[pack protocol v2](../../packages/specs/schemas/pack-protocol.schema.json) —
|
|
31
|
+
the contract its Node pack service speaks, checked by the same
|
|
32
|
+
[conformance suite](../../packages/pack-conformance/).
|
|
33
|
+
|
|
34
|
+
```sh
|
|
35
|
+
uv add kindgi # or: pip install kindgi
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Requires Python 3.11+. Dependencies: pydantic ≥ 2.10, uvicorn ≥ 0.27, httpx ≥
|
|
39
|
+
0.27, jsonschema ≥ 4.18 — CI runs the tests and the pack conformance suite at
|
|
40
|
+
those minimums as well as at the lock.
|
|
41
|
+
|
|
42
|
+
## A pack
|
|
43
|
+
|
|
44
|
+
```
|
|
45
|
+
ledger/
|
|
46
|
+
├── pyproject.toml # [tool.kindgi] — the pack's id and version
|
|
47
|
+
├── tools/ledger.py # @tool
|
|
48
|
+
├── tools/_db.py # a helper (a leading `_`: not a primitive)
|
|
49
|
+
├── guardrails/response.py # @guardrail
|
|
50
|
+
├── agents/bookkeeper.py # Agent(...)
|
|
51
|
+
└── flows/record.py # Flow(...)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```toml
|
|
55
|
+
# pyproject.toml
|
|
56
|
+
[tool.kindgi.pack]
|
|
57
|
+
id = "acme.ledger"
|
|
58
|
+
version = "1.0.0"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The `[tool.kindgi]` table takes the keys `kindgi.config.ts` takes (`pack`,
|
|
62
|
+
`discovery`, `dev`, `env`, `environments`, …), spelled the same.
|
|
63
|
+
|
|
64
|
+
A pack declares the process env its code and libraries read from
|
|
65
|
+
`os.environ`, names only; the index carries them:
|
|
66
|
+
|
|
67
|
+
```toml
|
|
68
|
+
[tool.kindgi.env]
|
|
69
|
+
required = ["DATABASE_URL"] # unset or "" → the pack service isn't ready
|
|
70
|
+
optional = ["SENTRY_DSN"] # read when set
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`KINDGI_*` names configure Kindgi itself and can't be declared.
|
|
74
|
+
|
|
75
|
+
### Tools
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
# tools/ledger.py
|
|
79
|
+
import os
|
|
80
|
+
|
|
81
|
+
from pydantic import BaseModel, Field
|
|
82
|
+
|
|
83
|
+
from kindgi import ToolContext, tool
|
|
84
|
+
|
|
85
|
+
from ._db import insert_expense
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
class Expense(BaseModel):
|
|
89
|
+
vendor: str = Field(min_length=1)
|
|
90
|
+
amount_cents: int = Field(alias="amountCents", ge=0)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
class Recorded(BaseModel):
|
|
94
|
+
expense_id: str = Field(alias="expenseId")
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
@tool(id="acme.ledger.record-expense", effects=[{"kind": "writes", "resource": "db:ledger"}])
|
|
98
|
+
def record_expense(expense: Expense, ctx: ToolContext) -> Recorded:
|
|
99
|
+
"""Records an expense in the ledger."""
|
|
100
|
+
expense_id = insert_expense(os.environ["LEDGER_DATABASE_URL"], ctx.tenant_id, expense)
|
|
101
|
+
return Recorded(expenseId=expense_id)
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
- The input and output schemas come from the handler's annotations — a
|
|
105
|
+
pydantic model, a `TypedDict`, a dataclass, anything pydantic understands —
|
|
106
|
+
or from `input=` / `output=` (a type, or a JSON Schema dict). Field aliases
|
|
107
|
+
are the names on the wire. The input is an object: a model calls a tool with
|
|
108
|
+
an object of arguments.
|
|
109
|
+
- The description is the docstring (or `description=`); the version is the
|
|
110
|
+
pack's (or `version=`, an exact semver).
|
|
111
|
+
- `mutating=False` declares a tool read-only: it runs in a dry run, and an
|
|
112
|
+
agent with tool approval gates on (and no override or `default` for it)
|
|
113
|
+
doesn't ask before it. Without it a tool may change something (as with
|
|
114
|
+
`mutating=True`).
|
|
115
|
+
- The handler is `(input)` or `(input, ctx)`, `def` or `async def`. A `def`
|
|
116
|
+
handler runs in a worker thread, so blocking I/O is fine.
|
|
117
|
+
- Before calling you, the pack service validates the input against the schema
|
|
118
|
+
and runs your model's own validators; it validates what you return, too.
|
|
119
|
+
- `ctx` carries `tenant_id`, `run_id`, `request_id` and `cancellation`, and in
|
|
120
|
+
a run `project_id` (the run's project) and `org_id` (its org, or `None`),
|
|
121
|
+
which the runtime sets from the run, never from the input.
|
|
122
|
+
`ctx.secrets` holds the secrets the tool declares
|
|
123
|
+
(`needs_spec={"secrets": {"CITATOR_KEY": {"type": "string"}}}`): the
|
|
124
|
+
runtime resolves them on every call, for the call's tenant, in its env
|
|
125
|
+
(`KINDGI_ENV`; in `kindgi dev`, `local` — the pack's `.env` and
|
|
126
|
+
`.env.local`), and fails the call, naming the secret, when one is missing.
|
|
127
|
+
`ctx.env` and `ctx.config` are reserved and still empty: read other
|
|
128
|
+
configuration from the process environment — the pack service's, which in
|
|
129
|
+
`kindgi dev` is the pack's `.env` and `.env.local`.
|
|
130
|
+
|
|
131
|
+
**Cancellation.** When a call passes its deadline or the caller disconnects,
|
|
132
|
+
the runtime gets `deadline-exceeded` / `cancelled` at once and
|
|
133
|
+
`ctx.cancellation` fires. An `async def` handler is also cancelled at its next
|
|
134
|
+
`await` (`asyncio.CancelledError`). A `def` handler keeps running in its
|
|
135
|
+
thread — check `ctx.cancellation.cancelled`, or wait on it
|
|
136
|
+
(`ctx.cancellation.wait(timeout)`), between slow steps.
|
|
137
|
+
|
|
138
|
+
**Output.** `print()` and logging go to the pack service's own stdout and
|
|
139
|
+
stderr (`kindgi dev` shows them as `[pack] …`), never into a response.
|
|
140
|
+
|
|
141
|
+
**HTTP tools.** A tool that is one HTTP request needs no handler:
|
|
142
|
+
`http_tool(...)` declares it, and the Kindgi runtime makes the request (the
|
|
143
|
+
counterpart of TypeScript's `defineTool({ spec: { kind: 'http' } })`).
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
from kindgi import http_tool
|
|
147
|
+
|
|
148
|
+
lookup_vendor = http_tool(
|
|
149
|
+
id="acme.ledger.lookup-vendor",
|
|
150
|
+
description="Looks a vendor up in the vendor registry.",
|
|
151
|
+
input=VendorRef,
|
|
152
|
+
output=Vendor,
|
|
153
|
+
method="GET",
|
|
154
|
+
url_template="https://vendors.example.com/v1/{vendor_id}",
|
|
155
|
+
authorization={"kind": "bearer", "secretRef": {"envName": "local", "name": "VENDORS_TOKEN"}},
|
|
156
|
+
)
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
`{name}` placeholders come from the input's fields (each must be one). The
|
|
160
|
+
runtime resolves the secret per call, and the spec (`headers`,
|
|
161
|
+
`request_body`, `timeout_ms`, `success_status`, …) is checked where it's
|
|
162
|
+
declared, against the same schema as TypeScript's. Calling it in Python
|
|
163
|
+
raises: it runs in Kindgi.
|
|
164
|
+
|
|
165
|
+
### Guardrail checks
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
# guardrails/response.py
|
|
169
|
+
from pydantic import BaseModel, Field
|
|
170
|
+
|
|
171
|
+
from kindgi import CheckResult, RunTrace, guardrail
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
class Config(BaseModel):
|
|
175
|
+
min_length: int = Field(1, alias="minLength", ge=0)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
@guardrail(id="acme.ledger.response-not-empty", on_violation="halt", severity="error")
|
|
179
|
+
def response_not_empty(config: Config, trace: RunTrace) -> CheckResult:
|
|
180
|
+
text = (trace.output or "").strip()
|
|
181
|
+
if len(text) < config.min_length:
|
|
182
|
+
return CheckResult(passed=False, reason=f"Response too short ({len(text)} chars)")
|
|
183
|
+
return CheckResult(passed=True)
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
A check is `(config, trace)` and returns a `CheckResult`, a dict with a
|
|
187
|
+
boolean `passed`, or a bool. Its config type is the first parameter's
|
|
188
|
+
annotation (or `config_type=`); `config=` on the decorator is what it runs
|
|
189
|
+
with, keyed as on the wire (`config={"minLength": 20}`), checked against the
|
|
190
|
+
type here — without it the check gets `{}`, its defaults. `RunTrace` holds the run's `output`,
|
|
191
|
+
`tool_calls`, `tool_results`, `model_calls`, … (snake_case here, camelCase on
|
|
192
|
+
the wire). `on_violation` names the action (`halt`, `retry`, `escalate`,
|
|
193
|
+
`log-only`, `compensate`); `action=` takes the whole object
|
|
194
|
+
(`{"on-violation": "retry", "retry": {"maxAttempts": 2}}`).
|
|
195
|
+
|
|
196
|
+
### Agents and flows
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
# agents/bookkeeper.py
|
|
200
|
+
from kindgi import Agent
|
|
201
|
+
|
|
202
|
+
from ..guardrails.response import response_not_empty
|
|
203
|
+
from ..tools.ledger import record_expense
|
|
204
|
+
|
|
205
|
+
bookkeeper = Agent(
|
|
206
|
+
id="acme.ledger.bookkeeper",
|
|
207
|
+
version="1.0.0",
|
|
208
|
+
name="Bookkeeper",
|
|
209
|
+
instructions="Record each expense the user describes with acme.ledger.record-expense.",
|
|
210
|
+
capabilities=[{"needs": [{"feature": "tool-use"}]}],
|
|
211
|
+
tools=[record_expense], # Tool objects, or {"id", "version"} refs
|
|
212
|
+
guardrails=[response_not_empty],
|
|
213
|
+
)
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
```python
|
|
217
|
+
# flows/record.py
|
|
218
|
+
from kindgi import Flow
|
|
219
|
+
|
|
220
|
+
from ..tools.ledger import record_expense
|
|
221
|
+
|
|
222
|
+
record = Flow(
|
|
223
|
+
id="acme.ledger.record-flow",
|
|
224
|
+
version="1.0.0",
|
|
225
|
+
nodes=[{"id": "record", "kind": "tool", "ref": record_expense}],
|
|
226
|
+
edges=[
|
|
227
|
+
{"id": "e-start", "from": "$start", "to": "record"},
|
|
228
|
+
{"id": "e-end", "from": "record", "to": "$end"},
|
|
229
|
+
],
|
|
230
|
+
)
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Flows follow [`flow.schema.json`](../../packages/specs/schemas/flow.schema.json);
|
|
234
|
+
the indexer checks them against it.
|
|
235
|
+
|
|
236
|
+
## Imports inside a pack
|
|
237
|
+
|
|
238
|
+
Each file is imported as part of one package rooted at the pack, so relative
|
|
239
|
+
imports work (`from ._db import …`, `from ..tools.ledger import …`), and a
|
|
240
|
+
folder named `tools/` or `agents/` never collides with an installed
|
|
241
|
+
distribution. The pack root is also on `sys.path`, so an application's own
|
|
242
|
+
packages import by name — a pack can live inside an existing app:
|
|
243
|
+
|
|
244
|
+
```toml
|
|
245
|
+
[tool.kindgi.discovery]
|
|
246
|
+
tools = "kindgi/tools/**/*.py"
|
|
247
|
+
guardrails = "kindgi/guardrails/**/*.py"
|
|
248
|
+
agents = "kindgi/agents/**/*.py"
|
|
249
|
+
flows = "kindgi/flows/**/*.py"
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Every module under a discovery folder defines at least one primitive at
|
|
253
|
+
module level; helper modules start with `_`. Tests (`test_*.py`, `*_test.py`,
|
|
254
|
+
`conftest.py`) are skipped.
|
|
255
|
+
|
|
256
|
+
## Running it
|
|
257
|
+
|
|
258
|
+
`kindgi dev` indexes the pack, runs it in a local pack service with the pack's
|
|
259
|
+
own interpreter and environment, and swaps the code on every save. Underneath
|
|
260
|
+
are two commands you can run yourself:
|
|
261
|
+
|
|
262
|
+
```sh
|
|
263
|
+
python -m kindgi.pack index --pack-dir . # → index.json
|
|
264
|
+
KINDGI_PACK_SERVICE_TOKEN=… python -m kindgi.pack serve --index index.json
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
`serve` has the Node pack service's process contract: `--index`,
|
|
268
|
+
`--module-root` and `--host`; `KINDGI_PACK_SERVICE_TOKEN`, `PORT`,
|
|
269
|
+
`KINDGI_PACK_SERVICE_MAX_CONCURRENCY` and `KINDGI_PACK_ENV_CHECK`; JSON log
|
|
270
|
+
lines on stderr; SIGTERM drains in-flight calls for up to 8 s.
|
|
271
|
+
|
|
272
|
+
At startup it checks the index's `env.required`. Under
|
|
273
|
+
`KINDGI_PACK_ENV_CHECK=strict` (the default), a name that is unset or `""`
|
|
274
|
+
holds `/readyz` and every call at 503 `{"error": "missing env",
|
|
275
|
+
"missingEnv": [...]}`; under `warn` it serves. Either way the names are
|
|
276
|
+
logged once (`{"kind": "missing-env", …}`) and `/v1/info` lists them in
|
|
277
|
+
`missingEnv`.
|
|
278
|
+
|
|
279
|
+
## Calling the Kindgi API
|
|
280
|
+
|
|
281
|
+
`kindgi.client` covers every operation of the API — generated from
|
|
282
|
+
[`openapi.json`](../../packages/api/openapi.json), so it can't fall behind it.
|
|
283
|
+
An operation id `approvals.reviewers.list` is `client.approvals.reviewers.list()`.
|
|
284
|
+
|
|
285
|
+
```python
|
|
286
|
+
from kindgi.client import GuardrailViolationError, Kindgi, paginate
|
|
287
|
+
|
|
288
|
+
client = Kindgi() # KINDGI_API_URL, KINDGI_API_TOKEN — or Kindgi(url, token=…)
|
|
289
|
+
|
|
290
|
+
run = client.runs.start(flow="acme.ledger.record-flow", input={"vendor": "Acme", "amountCents": 1299})
|
|
291
|
+
print(run.status, run.output)
|
|
292
|
+
|
|
293
|
+
try:
|
|
294
|
+
turn = client.runs.start(agent="acme.ledger.bookkeeper", input={"userMessage": "Lunch, $12.99"})
|
|
295
|
+
except GuardrailViolationError as blocked:
|
|
296
|
+
print(blocked.violations)
|
|
297
|
+
|
|
298
|
+
for event in client.runs.stream(str(turn.id)): # SSE, resumes after a drop
|
|
299
|
+
print(event.kind)
|
|
300
|
+
|
|
301
|
+
for agent in paginate(client.agents.list, limit=50): # every page
|
|
302
|
+
print(agent.id)
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
Without arguments, the client takes `KINDGI_API_URL` and `KINDGI_API_TOKEN`
|
|
306
|
+
from the environment. In development, when they're unset, it uses the running
|
|
307
|
+
`kindgi dev` (the nearest `.kindgirc.json` at or above the working directory)
|
|
308
|
+
and warns once (`KindgiConfigWarning`) to put them in your env file (`.env` /
|
|
309
|
+
`.env.local`). Production (`KINDGI_ENV` or `NODE_ENV` set to `production`)
|
|
310
|
+
never reads `.kindgirc.json`. It's the same lookup as the TypeScript SDK's
|
|
311
|
+
`createClient()`.
|
|
312
|
+
|
|
313
|
+
- A request body is a model from `kindgi.client.models`, a mapping, or its
|
|
314
|
+
fields as keywords (snake_case or the wire's camelCase); answers are models.
|
|
315
|
+
- Path parameters are positional; query and header parameters keyword-only.
|
|
316
|
+
- An operation that takes an `Idempotency-Key` gets one when you pass none, so
|
|
317
|
+
a retry never runs it twice. Calls that are safe to repeat are retried on a
|
|
318
|
+
connection error, 429, 502, 503 or 504 (`max_retries=2`, honouring
|
|
319
|
+
`Retry-After`).
|
|
320
|
+
- Errors are typed: `NotFoundError`, `ConflictError`, `InvalidRequestError`,
|
|
321
|
+
`GuardrailViolationError`, `AuthError`, `RateLimitedError`, `ServerError`,
|
|
322
|
+
`NetworkError` — all `KindgiApiError`, with `.status`, `.server_code`,
|
|
323
|
+
`.details` and `.request_id`.
|
|
324
|
+
- `AsyncKindgi` is the same with asyncio (`apaginate` for its pages).
|
|
325
|
+
|
|
326
|
+
A pack's tools can use it to call back into Kindgi (memory, events, other runs).
|
|
327
|
+
|
|
328
|
+
## Receiving webhooks
|
|
329
|
+
|
|
330
|
+
Kindgi signs the webhooks it sends (`run.finished`, `webhook.test`; see
|
|
331
|
+
[webhooks](https://docs.kindgi.com/v0.1/guides/webhooks/verify-a-webhook/)) in the
|
|
332
|
+
[Standard Webhooks](https://www.standardwebhooks.com) format. Verify the
|
|
333
|
+
**raw** body, before parsing it, with the secret the endpoint's `secretRef`
|
|
334
|
+
names:
|
|
335
|
+
|
|
336
|
+
```python
|
|
337
|
+
import os
|
|
338
|
+
|
|
339
|
+
from fastapi import FastAPI, Request, Response
|
|
340
|
+
from kindgi import webhooks
|
|
341
|
+
|
|
342
|
+
app = FastAPI()
|
|
343
|
+
|
|
344
|
+
@app.post("/hooks/kindgi")
|
|
345
|
+
async def kindgi_hook(request: Request) -> Response:
|
|
346
|
+
body = await request.body() # the bytes as sent, never re-serialized JSON
|
|
347
|
+
try:
|
|
348
|
+
delivery = webhooks.verify(os.environ["KINDGI_WEBHOOK_SECRET"], request.headers, body)
|
|
349
|
+
except webhooks.WebhookVerificationError:
|
|
350
|
+
return Response(status_code=401)
|
|
351
|
+
if already_handled(delivery.id): # delivery is at least once
|
|
352
|
+
return Response(status_code=204)
|
|
353
|
+
event = webhooks.parse_event(body) # RunFinishedEvent | WebhookTestEvent
|
|
354
|
+
if event.type == "run.finished":
|
|
355
|
+
print(event.data.run.flow_id, event.data.run.status)
|
|
356
|
+
return Response(status_code=204)
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
- `verify` takes the headers as any mapping (Starlette, Django, aiohttp, a
|
|
360
|
+
`dict`), Werkzeug's `Headers` or `http.server`'s, names in any case. It rejects a timestamp
|
|
361
|
+
more than 5 minutes from your clock (`tolerance_seconds=`) and compares in
|
|
362
|
+
constant time; `WebhookVerificationError.reason` says which check failed.
|
|
363
|
+
- During a secret rotation requests carry a signature per secret, so the old
|
|
364
|
+
and the new secret both verify.
|
|
365
|
+
- `sign` / `signed_headers` make signed requests, for testing a receiver;
|
|
366
|
+
`generate_secret` makes a strong secret.
|
|
367
|
+
|
|
368
|
+
## Testing your code
|
|
369
|
+
|
|
370
|
+
A `Tool` and a `Guardrail` stay callable:
|
|
371
|
+
|
|
372
|
+
```python
|
|
373
|
+
from kindgi import ToolContext
|
|
374
|
+
|
|
375
|
+
def test_record_expense():
|
|
376
|
+
out = record_expense(Expense(vendor="Acme", amountCents=100), ToolContext.for_test())
|
|
377
|
+
assert out.expense_id
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
## Developing this package
|
|
381
|
+
|
|
382
|
+
With uv 0.12 (`[tool.uv] required-version` in `pyproject.toml`; uv refuses
|
|
383
|
+
to run here otherwise, and CI installs its version from that line):
|
|
384
|
+
|
|
385
|
+
```sh
|
|
386
|
+
uv sync # .venv with the dev tools
|
|
387
|
+
uv run pytest
|
|
388
|
+
uv run ruff check src tests && uv run ruff format --check src tests
|
|
389
|
+
uv run pyright # strict
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
The vendored schemas in `src/kindgi/_specs` are copies of `@kindgi/specs`;
|
|
393
|
+
`tests/test_specs_drift.py` fails when they drift. The client's
|
|
394
|
+
`_models.py` and `_resources.py` are generated —
|
|
395
|
+
`uv run python scripts/gen_client.py` after `openapi.json` changes;
|
|
396
|
+
`tests/test_client.py` fails while they are out of step. `@kindgi/pack-conformance`
|
|
397
|
+
runs its suite against this package's `.venv`.
|
|
398
|
+
|
|
399
|
+
## License
|
|
400
|
+
|
|
401
|
+
Apache-2.0 — see [LICENSE](./LICENSE).
|