@kindgi/agents 0.0.0-bootstrap.0 → 0.1.1

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.
Files changed (240) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +131 -2
  3. package/dist/agent-turn-flow.d.ts +57 -0
  4. package/dist/agent-turn-flow.d.ts.map +1 -0
  5. package/dist/agent-turn-flow.js +172 -0
  6. package/dist/agent-turn-flow.js.map +1 -0
  7. package/dist/conversation-binding.d.ts +111 -0
  8. package/dist/conversation-binding.d.ts.map +1 -0
  9. package/dist/conversation-binding.js +4 -0
  10. package/dist/conversation-binding.js.map +1 -0
  11. package/dist/define.d.ts +180 -0
  12. package/dist/define.d.ts.map +1 -0
  13. package/dist/define.js +361 -0
  14. package/dist/define.js.map +1 -0
  15. package/dist/errors.d.ts +62 -0
  16. package/dist/errors.d.ts.map +1 -0
  17. package/dist/errors.js +4 -0
  18. package/dist/errors.js.map +1 -0
  19. package/dist/guardrails-gate.d.ts +169 -0
  20. package/dist/guardrails-gate.d.ts.map +1 -0
  21. package/dist/guardrails-gate.js +202 -0
  22. package/dist/guardrails-gate.js.map +1 -0
  23. package/dist/handlers/budget-check.d.ts +22 -0
  24. package/dist/handlers/budget-check.d.ts.map +1 -0
  25. package/dist/handlers/budget-check.js +109 -0
  26. package/dist/handlers/budget-check.js.map +1 -0
  27. package/dist/handlers/build-initial-messages.d.ts +17 -0
  28. package/dist/handlers/build-initial-messages.d.ts.map +1 -0
  29. package/dist/handlers/build-initial-messages.js +86 -0
  30. package/dist/handlers/build-initial-messages.js.map +1 -0
  31. package/dist/handlers/compose-result.d.ts +10 -0
  32. package/dist/handlers/compose-result.d.ts.map +1 -0
  33. package/dist/handlers/compose-result.js +79 -0
  34. package/dist/handlers/compose-result.js.map +1 -0
  35. package/dist/handlers/constants.d.ts +8 -0
  36. package/dist/handlers/constants.d.ts.map +1 -0
  37. package/dist/handlers/constants.js +10 -0
  38. package/dist/handlers/constants.js.map +1 -0
  39. package/dist/handlers/context.d.ts +210 -0
  40. package/dist/handlers/context.d.ts.map +1 -0
  41. package/dist/handlers/context.js +4 -0
  42. package/dist/handlers/context.js.map +1 -0
  43. package/dist/handlers/dispatch-tools.d.ts +15 -0
  44. package/dist/handlers/dispatch-tools.d.ts.map +1 -0
  45. package/dist/handlers/dispatch-tools.js +511 -0
  46. package/dist/handlers/dispatch-tools.js.map +1 -0
  47. package/dist/handlers/errors.d.ts +133 -0
  48. package/dist/handlers/errors.d.ts.map +1 -0
  49. package/dist/handlers/errors.js +134 -0
  50. package/dist/handlers/errors.js.map +1 -0
  51. package/dist/handlers/evaluate-guardrails.d.ts +14 -0
  52. package/dist/handlers/evaluate-guardrails.d.ts.map +1 -0
  53. package/dist/handlers/evaluate-guardrails.js +128 -0
  54. package/dist/handlers/evaluate-guardrails.js.map +1 -0
  55. package/dist/handlers/final-iteration.d.ts +7 -0
  56. package/dist/handlers/final-iteration.d.ts.map +1 -0
  57. package/dist/handlers/final-iteration.js +26 -0
  58. package/dist/handlers/final-iteration.js.map +1 -0
  59. package/dist/handlers/index.d.ts +5 -0
  60. package/dist/handlers/index.d.ts.map +1 -0
  61. package/dist/handlers/index.js +41 -0
  62. package/dist/handlers/index.js.map +1 -0
  63. package/dist/handlers/model-call.d.ts +13 -0
  64. package/dist/handlers/model-call.d.ts.map +1 -0
  65. package/dist/handlers/model-call.js +136 -0
  66. package/dist/handlers/model-call.js.map +1 -0
  67. package/dist/handlers/persist-final-message.d.ts +14 -0
  68. package/dist/handlers/persist-final-message.d.ts.map +1 -0
  69. package/dist/handlers/persist-final-message.js +54 -0
  70. package/dist/handlers/persist-final-message.js.map +1 -0
  71. package/dist/handlers/persist-provenance.d.ts +12 -0
  72. package/dist/handlers/persist-provenance.d.ts.map +1 -0
  73. package/dist/handlers/persist-provenance.js +34 -0
  74. package/dist/handlers/persist-provenance.js.map +1 -0
  75. package/dist/handlers/persist-user-message.d.ts +15 -0
  76. package/dist/handlers/persist-user-message.d.ts.map +1 -0
  77. package/dist/handlers/persist-user-message.js +59 -0
  78. package/dist/handlers/persist-user-message.js.map +1 -0
  79. package/dist/handlers/public-types.d.ts +201 -0
  80. package/dist/handlers/public-types.d.ts.map +1 -0
  81. package/dist/handlers/public-types.js +4 -0
  82. package/dist/handlers/public-types.js.map +1 -0
  83. package/dist/handlers/rehydrate.d.ts +8 -0
  84. package/dist/handlers/rehydrate.d.ts.map +1 -0
  85. package/dist/handlers/rehydrate.js +94 -0
  86. package/dist/handlers/rehydrate.js.map +1 -0
  87. package/dist/handlers/render-prompt.d.ts +12 -0
  88. package/dist/handlers/render-prompt.d.ts.map +1 -0
  89. package/dist/handlers/render-prompt.js +41 -0
  90. package/dist/handlers/render-prompt.js.map +1 -0
  91. package/dist/handlers/resolve-tools.d.ts +10 -0
  92. package/dist/handlers/resolve-tools.d.ts.map +1 -0
  93. package/dist/handlers/resolve-tools.js +55 -0
  94. package/dist/handlers/resolve-tools.js.map +1 -0
  95. package/dist/handlers/result-shape.d.ts +94 -0
  96. package/dist/handlers/result-shape.d.ts.map +1 -0
  97. package/dist/handlers/result-shape.js +19 -0
  98. package/dist/handlers/result-shape.js.map +1 -0
  99. package/dist/handlers/run-retrievals.d.ts +10 -0
  100. package/dist/handlers/run-retrievals.d.ts.map +1 -0
  101. package/dist/handlers/run-retrievals.js +64 -0
  102. package/dist/handlers/run-retrievals.js.map +1 -0
  103. package/dist/handlers/run-snapshot.d.ts +4 -0
  104. package/dist/handlers/run-snapshot.d.ts.map +1 -0
  105. package/dist/handlers/run-snapshot.js +26 -0
  106. package/dist/handlers/run-snapshot.js.map +1 -0
  107. package/dist/handlers/setup.d.ts +25 -0
  108. package/dist/handlers/setup.d.ts.map +1 -0
  109. package/dist/handlers/setup.js +231 -0
  110. package/dist/handlers/setup.js.map +1 -0
  111. package/dist/handlers/structured-output.d.ts +38 -0
  112. package/dist/handlers/structured-output.d.ts.map +1 -0
  113. package/dist/handlers/structured-output.js +89 -0
  114. package/dist/handlers/structured-output.js.map +1 -0
  115. package/dist/handlers/tool-errors.d.ts +56 -0
  116. package/dist/handlers/tool-errors.d.ts.map +1 -0
  117. package/dist/handlers/tool-errors.js +73 -0
  118. package/dist/handlers/tool-errors.js.map +1 -0
  119. package/dist/handlers/tool-hitl.d.ts +45 -0
  120. package/dist/handlers/tool-hitl.d.ts.map +1 -0
  121. package/dist/handlers/tool-hitl.js +81 -0
  122. package/dist/handlers/tool-hitl.js.map +1 -0
  123. package/dist/handlers/turn-environment.d.ts +26 -0
  124. package/dist/handlers/turn-environment.d.ts.map +1 -0
  125. package/dist/handlers/turn-environment.js +154 -0
  126. package/dist/handlers/turn-environment.js.map +1 -0
  127. package/dist/hitl-policy.d.ts +45 -0
  128. package/dist/hitl-policy.d.ts.map +1 -0
  129. package/dist/hitl-policy.js +74 -0
  130. package/dist/hitl-policy.js.map +1 -0
  131. package/dist/index.d.ts +31 -0
  132. package/dist/index.d.ts.map +1 -0
  133. package/dist/index.js +19 -0
  134. package/dist/index.js.map +1 -0
  135. package/dist/invoke.d.ts +36 -0
  136. package/dist/invoke.d.ts.map +1 -0
  137. package/dist/invoke.js +228 -0
  138. package/dist/invoke.js.map +1 -0
  139. package/dist/migrations-dir.d.ts +11 -0
  140. package/dist/migrations-dir.d.ts.map +1 -0
  141. package/dist/migrations-dir.js +14 -0
  142. package/dist/migrations-dir.js.map +1 -0
  143. package/dist/project-run-result.d.ts +23 -0
  144. package/dist/project-run-result.d.ts.map +1 -0
  145. package/dist/project-run-result.js +116 -0
  146. package/dist/project-run-result.js.map +1 -0
  147. package/dist/prompt.d.ts +83 -0
  148. package/dist/prompt.d.ts.map +1 -0
  149. package/dist/prompt.js +119 -0
  150. package/dist/prompt.js.map +1 -0
  151. package/dist/provenance-emit.d.ts +44 -0
  152. package/dist/provenance-emit.d.ts.map +1 -0
  153. package/dist/provenance-emit.js +51 -0
  154. package/dist/provenance-emit.js.map +1 -0
  155. package/dist/registry.d.ts +38 -0
  156. package/dist/registry.d.ts.map +1 -0
  157. package/dist/registry.js +125 -0
  158. package/dist/registry.js.map +1 -0
  159. package/dist/retrieval.d.ts +47 -0
  160. package/dist/retrieval.d.ts.map +1 -0
  161. package/dist/retrieval.js +155 -0
  162. package/dist/retrieval.js.map +1 -0
  163. package/dist/run-snapshot-binding.d.ts +77 -0
  164. package/dist/run-snapshot-binding.d.ts.map +1 -0
  165. package/dist/run-snapshot-binding.js +4 -0
  166. package/dist/run-snapshot-binding.js.map +1 -0
  167. package/dist/schema.d.ts +497 -0
  168. package/dist/schema.d.ts.map +1 -0
  169. package/dist/schema.js +133 -0
  170. package/dist/schema.js.map +1 -0
  171. package/dist/streaming.d.ts +118 -0
  172. package/dist/streaming.d.ts.map +1 -0
  173. package/dist/streaming.js +17 -0
  174. package/dist/streaming.js.map +1 -0
  175. package/dist/tenant-policy.d.ts +16 -0
  176. package/dist/tenant-policy.d.ts.map +1 -0
  177. package/dist/tenant-policy.js +77 -0
  178. package/dist/tenant-policy.js.map +1 -0
  179. package/dist/types.d.ts +435 -0
  180. package/dist/types.d.ts.map +1 -0
  181. package/dist/types.js +4 -0
  182. package/dist/types.js.map +1 -0
  183. package/dist/versioning.d.ts +29 -0
  184. package/dist/versioning.d.ts.map +1 -0
  185. package/dist/versioning.js +58 -0
  186. package/dist/versioning.js.map +1 -0
  187. package/migrations/0000_sparkling_talkback.sql +18 -0
  188. package/migrations/0001_tired_warhawk.sql +16 -0
  189. package/migrations/0002_violet_ezekiel.sql +2 -0
  190. package/migrations/meta/0000_snapshot.json +172 -0
  191. package/migrations/meta/0001_snapshot.json +275 -0
  192. package/migrations/meta/0002_snapshot.json +287 -0
  193. package/migrations/meta/_journal.json +27 -0
  194. package/package.json +76 -4
  195. package/src/agent-turn-flow.ts +183 -0
  196. package/src/conversation-binding.ts +147 -0
  197. package/src/define.ts +572 -0
  198. package/src/errors.ts +80 -0
  199. package/src/guardrails-gate.ts +342 -0
  200. package/src/handlers/budget-check.ts +143 -0
  201. package/src/handlers/build-initial-messages.ts +103 -0
  202. package/src/handlers/compose-result.ts +90 -0
  203. package/src/handlers/constants.ts +10 -0
  204. package/src/handlers/context.ts +226 -0
  205. package/src/handlers/dispatch-tools.ts +633 -0
  206. package/src/handlers/errors.ts +282 -0
  207. package/src/handlers/evaluate-guardrails.ts +153 -0
  208. package/src/handlers/final-iteration.ts +30 -0
  209. package/src/handlers/index.ts +63 -0
  210. package/src/handlers/model-call.ts +151 -0
  211. package/src/handlers/persist-final-message.ts +67 -0
  212. package/src/handlers/persist-provenance.ts +39 -0
  213. package/src/handlers/persist-user-message.ts +70 -0
  214. package/src/handlers/public-types.ts +209 -0
  215. package/src/handlers/rehydrate.ts +161 -0
  216. package/src/handlers/render-prompt.ts +46 -0
  217. package/src/handlers/resolve-tools.ts +68 -0
  218. package/src/handlers/result-shape.ts +113 -0
  219. package/src/handlers/run-retrievals.ts +77 -0
  220. package/src/handlers/run-snapshot.ts +44 -0
  221. package/src/handlers/setup.ts +269 -0
  222. package/src/handlers/structured-output.ts +117 -0
  223. package/src/handlers/tool-errors.ts +122 -0
  224. package/src/handlers/tool-hitl.ts +126 -0
  225. package/src/handlers/turn-environment.ts +191 -0
  226. package/src/hitl-policy.ts +128 -0
  227. package/src/index.ts +154 -0
  228. package/src/invoke.ts +299 -0
  229. package/src/migrations-dir.ts +17 -0
  230. package/src/project-run-result.ts +131 -0
  231. package/src/prompt.ts +185 -0
  232. package/src/provenance-emit.ts +100 -0
  233. package/src/registry.ts +164 -0
  234. package/src/retrieval.ts +219 -0
  235. package/src/run-snapshot-binding.ts +87 -0
  236. package/src/schema.ts +154 -0
  237. package/src/streaming.ts +153 -0
  238. package/src/tenant-policy.ts +78 -0
  239. package/src/types.ts +453 -0
  240. package/src/versioning.ts +77 -0
@@ -0,0 +1,287 @@
1
+ {
2
+ "id": "2769ef0e-69b4-4a4d-ab47-044e2f11945e",
3
+ "prevId": "02977280-a54a-47a9-90e9-db22e06166f2",
4
+ "version": "7",
5
+ "dialect": "postgresql",
6
+ "tables": {
7
+ "public.agent_conversations": {
8
+ "name": "agent_conversations",
9
+ "schema": "",
10
+ "columns": {
11
+ "id": {
12
+ "name": "id",
13
+ "type": "uuid",
14
+ "primaryKey": true,
15
+ "notNull": true,
16
+ "default": "gen_random_uuid()"
17
+ },
18
+ "tenant_id": {
19
+ "name": "tenant_id",
20
+ "type": "uuid",
21
+ "primaryKey": false,
22
+ "notNull": true
23
+ },
24
+ "agent_id": {
25
+ "name": "agent_id",
26
+ "type": "text",
27
+ "primaryKey": false,
28
+ "notNull": true
29
+ },
30
+ "agent_version": {
31
+ "name": "agent_version",
32
+ "type": "text",
33
+ "primaryKey": false,
34
+ "notNull": true
35
+ },
36
+ "title": {
37
+ "name": "title",
38
+ "type": "text",
39
+ "primaryKey": false,
40
+ "notNull": true
41
+ },
42
+ "participant_id": {
43
+ "name": "participant_id",
44
+ "type": "text",
45
+ "primaryKey": false,
46
+ "notNull": false
47
+ },
48
+ "scope": {
49
+ "name": "scope",
50
+ "type": "jsonb",
51
+ "primaryKey": false,
52
+ "notNull": true
53
+ },
54
+ "opened_at": {
55
+ "name": "opened_at",
56
+ "type": "timestamp with time zone",
57
+ "primaryKey": false,
58
+ "notNull": true,
59
+ "default": "now()"
60
+ },
61
+ "closed_at": {
62
+ "name": "closed_at",
63
+ "type": "timestamp with time zone",
64
+ "primaryKey": false,
65
+ "notNull": false
66
+ },
67
+ "turn_count": {
68
+ "name": "turn_count",
69
+ "type": "integer",
70
+ "primaryKey": false,
71
+ "notNull": true,
72
+ "default": 0
73
+ },
74
+ "last_message_at": {
75
+ "name": "last_message_at",
76
+ "type": "timestamp with time zone",
77
+ "primaryKey": false,
78
+ "notNull": false
79
+ },
80
+ "metadata": {
81
+ "name": "metadata",
82
+ "type": "jsonb",
83
+ "primaryKey": false,
84
+ "notNull": false
85
+ }
86
+ },
87
+ "indexes": {
88
+ "agent_conversations_tenant_agent_idx": {
89
+ "name": "agent_conversations_tenant_agent_idx",
90
+ "columns": [
91
+ {
92
+ "expression": "tenant_id",
93
+ "isExpression": false,
94
+ "asc": true,
95
+ "nulls": "last"
96
+ },
97
+ {
98
+ "expression": "agent_id",
99
+ "isExpression": false,
100
+ "asc": true,
101
+ "nulls": "last"
102
+ }
103
+ ],
104
+ "isUnique": false,
105
+ "concurrently": false,
106
+ "method": "btree",
107
+ "with": {}
108
+ },
109
+ "agent_conversations_tenant_participant_idx": {
110
+ "name": "agent_conversations_tenant_participant_idx",
111
+ "columns": [
112
+ {
113
+ "expression": "tenant_id",
114
+ "isExpression": false,
115
+ "asc": true,
116
+ "nulls": "last"
117
+ },
118
+ {
119
+ "expression": "participant_id",
120
+ "isExpression": false,
121
+ "asc": true,
122
+ "nulls": "last"
123
+ }
124
+ ],
125
+ "isUnique": false,
126
+ "concurrently": false,
127
+ "method": "btree",
128
+ "with": {}
129
+ },
130
+ "agent_conversations_open_recent_idx": {
131
+ "name": "agent_conversations_open_recent_idx",
132
+ "columns": [
133
+ {
134
+ "expression": "tenant_id",
135
+ "isExpression": false,
136
+ "asc": true,
137
+ "nulls": "last"
138
+ },
139
+ {
140
+ "expression": "last_message_at",
141
+ "isExpression": false,
142
+ "asc": false,
143
+ "nulls": "last"
144
+ }
145
+ ],
146
+ "isUnique": false,
147
+ "where": "\"agent_conversations\".\"closed_at\" IS NULL",
148
+ "concurrently": false,
149
+ "method": "btree",
150
+ "with": {}
151
+ }
152
+ },
153
+ "foreignKeys": {},
154
+ "compositePrimaryKeys": {},
155
+ "uniqueConstraints": {},
156
+ "policies": {},
157
+ "checkConstraints": {},
158
+ "isRLSEnabled": false
159
+ },
160
+ "public.agent_run_snapshots": {
161
+ "name": "agent_run_snapshots",
162
+ "schema": "",
163
+ "columns": {
164
+ "id": {
165
+ "name": "id",
166
+ "type": "uuid",
167
+ "primaryKey": true,
168
+ "notNull": true
169
+ },
170
+ "tenant_id": {
171
+ "name": "tenant_id",
172
+ "type": "uuid",
173
+ "primaryKey": false,
174
+ "notNull": true
175
+ },
176
+ "project_id": {
177
+ "name": "project_id",
178
+ "type": "uuid",
179
+ "primaryKey": false,
180
+ "notNull": true
181
+ },
182
+ "agent_id": {
183
+ "name": "agent_id",
184
+ "type": "text",
185
+ "primaryKey": false,
186
+ "notNull": true
187
+ },
188
+ "agent_version": {
189
+ "name": "agent_version",
190
+ "type": "text",
191
+ "primaryKey": false,
192
+ "notNull": true
193
+ },
194
+ "conversation_id": {
195
+ "name": "conversation_id",
196
+ "type": "uuid",
197
+ "primaryKey": false,
198
+ "notNull": true
199
+ },
200
+ "user_message": {
201
+ "name": "user_message",
202
+ "type": "text",
203
+ "primaryKey": false,
204
+ "notNull": true
205
+ },
206
+ "parameters": {
207
+ "name": "parameters",
208
+ "type": "jsonb",
209
+ "primaryKey": false,
210
+ "notNull": false
211
+ },
212
+ "input": {
213
+ "name": "input",
214
+ "type": "jsonb",
215
+ "primaryKey": false,
216
+ "notNull": false
217
+ },
218
+ "participant_id": {
219
+ "name": "participant_id",
220
+ "type": "text",
221
+ "primaryKey": false,
222
+ "notNull": false
223
+ },
224
+ "dry_run": {
225
+ "name": "dry_run",
226
+ "type": "integer",
227
+ "primaryKey": false,
228
+ "notNull": true,
229
+ "default": 0
230
+ },
231
+ "principal": {
232
+ "name": "principal",
233
+ "type": "jsonb",
234
+ "primaryKey": false,
235
+ "notNull": false
236
+ },
237
+ "authz": {
238
+ "name": "authz",
239
+ "type": "jsonb",
240
+ "primaryKey": false,
241
+ "notNull": false
242
+ },
243
+ "created_at": {
244
+ "name": "created_at",
245
+ "type": "timestamp with time zone",
246
+ "primaryKey": false,
247
+ "notNull": true,
248
+ "default": "now()"
249
+ }
250
+ },
251
+ "indexes": {
252
+ "agent_run_snapshots_tenant_idx": {
253
+ "name": "agent_run_snapshots_tenant_idx",
254
+ "columns": [
255
+ {
256
+ "expression": "tenant_id",
257
+ "isExpression": false,
258
+ "asc": true,
259
+ "nulls": "last"
260
+ }
261
+ ],
262
+ "isUnique": false,
263
+ "concurrently": false,
264
+ "method": "btree",
265
+ "with": {}
266
+ }
267
+ },
268
+ "foreignKeys": {},
269
+ "compositePrimaryKeys": {},
270
+ "uniqueConstraints": {},
271
+ "policies": {},
272
+ "checkConstraints": {},
273
+ "isRLSEnabled": false
274
+ }
275
+ },
276
+ "enums": {},
277
+ "schemas": {},
278
+ "sequences": {},
279
+ "roles": {},
280
+ "policies": {},
281
+ "views": {},
282
+ "_meta": {
283
+ "columns": {},
284
+ "schemas": {},
285
+ "tables": {}
286
+ }
287
+ }
@@ -0,0 +1,27 @@
1
+ {
2
+ "version": "7",
3
+ "dialect": "postgresql",
4
+ "entries": [
5
+ {
6
+ "idx": 0,
7
+ "version": "7",
8
+ "when": 1789708941765,
9
+ "tag": "0000_sparkling_talkback",
10
+ "breakpoints": true
11
+ },
12
+ {
13
+ "idx": 1,
14
+ "version": "7",
15
+ "when": 1790270079710,
16
+ "tag": "0001_tired_warhawk",
17
+ "breakpoints": true
18
+ },
19
+ {
20
+ "idx": 2,
21
+ "version": "7",
22
+ "when": 1790813765675,
23
+ "tag": "0002_violet_ezekiel",
24
+ "breakpoints": true
25
+ }
26
+ ]
27
+ }
package/package.json CHANGED
@@ -1,7 +1,79 @@
1
1
  {
2
2
  "name": "@kindgi/agents",
3
- "version": "0.0.0-bootstrap.0",
4
- "description": "Placeholder so a trusted publisher can be attached. Releases are published from https://github.com/kindgi/kindgi-sdk with provenance; use 0.1.0 or later.",
3
+ "version": "0.1.1",
4
+ "description": "Agent primitive for Kindgi. Composes capabilities (model routing), tools (execution), memory (facts + retrieval), guardrails (declarative guardrails), and provenance into a single declarative unit. Agents are data-as-code — a defineAgent() call produces a durable definition that runs on the kernel, with first-class multi-turn conversations, streaming output, and a provenance record per turn.",
5
5
  "license": "Apache-2.0",
6
- "repository": { "type": "git", "url": "git+https://github.com/kindgi/kindgi-sdk.git" }
7
- }
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/kindgi/kindgi-sdk.git",
9
+ "directory": "packages/agents"
10
+ },
11
+ "homepage": "https://github.com/kindgi/kindgi-sdk/tree/main/packages/agents#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/kindgi/kindgi-sdk/issues"
14
+ },
15
+ "type": "module",
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "dist",
26
+ "src",
27
+ "migrations",
28
+ "README.md",
29
+ "SPEC.md",
30
+ "type-manifest.json"
31
+ ],
32
+ "dependencies": {
33
+ "@kindgi/authz": "0.1.1",
34
+ "@kindgi/capabilities": "0.1.1",
35
+ "@kindgi/compliance": "0.1.1",
36
+ "@kindgi/embedding": "0.1.1",
37
+ "@kindgi/flow": "0.1.1",
38
+ "@kindgi/handler": "0.1.1",
39
+ "@kindgi/guardrails": "0.1.1",
40
+ "@kindgi/memory": "0.1.1",
41
+ "@kindgi/policy-contract": "0.1.1",
42
+ "@kindgi/provenance": "0.1.1",
43
+ "@kindgi/runtime": "0.1.1",
44
+ "@kindgi/schema": "0.1.1",
45
+ "@kindgi/tools": "0.1.1",
46
+ "@kindgi/types": "0.1.1",
47
+ "drizzle-orm": "^0.36.4",
48
+ "liquidjs": "^10.29.0"
49
+ },
50
+ "peerDependencies": {
51
+ "zod": "^4.0.0"
52
+ },
53
+ "peerDependenciesMeta": {
54
+ "zod": {
55
+ "optional": true
56
+ }
57
+ },
58
+ "devDependencies": {
59
+ "@types/node": "^22.10.5",
60
+ "drizzle-kit": "^0.30.1",
61
+ "typescript": "^5.7.3",
62
+ "vitest": "^2.1.8",
63
+ "zod": "^4.6.5"
64
+ },
65
+ "engines": {
66
+ "node": ">=22.0.0"
67
+ },
68
+ "publishConfig": {
69
+ "access": "public",
70
+ "provenance": true
71
+ },
72
+ "scripts": {
73
+ "build": "tsc -p tsconfig.build.json",
74
+ "typecheck": "tsc --noEmit",
75
+ "test": "vitest run",
76
+ "clean": "rm -rf dist *.tsbuildinfo",
77
+ "db:generate": "drizzle-kit generate"
78
+ }
79
+ }
@@ -0,0 +1,183 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright (C) 2026 Kindgi Inc.
3
+
4
+ import type { Flow } from '@kindgi/flow';
5
+ import { loadFlow } from '@kindgi/flow';
6
+
7
+ /**
8
+ * The versioned agent-turn flow. Every agent turn — regardless of which
9
+ * concrete `Agent` is being invoked — executes as a run of this flow
10
+ * against handlers that close over the specific agent + bindings + input.
11
+ *
12
+ * Shape (uses the kernel loop primitive for the model↔tool cycle):
13
+ *
14
+ * ```
15
+ * $start → setup → render-prompt → persist-user-message → run-retrievals
16
+ * → build-initial-messages → agent-loop (kernel loop node)
17
+ * → evaluate-guardrails → persist-final-message → persist-provenance
18
+ * → compose-result → $end
19
+ * ```
20
+ *
21
+ * Guardrails run on the final response before it is stored: a response
22
+ * a blocking guardrail rejects never reaches the conversation.
23
+ *
24
+ * `agent-loop` is a `while+after` (do-while) loop; its body is
25
+ * `$loop-start → model-call → dispatch-tools → budget-check → $loop-end`.
26
+ * Exit condition: `iterationOutput.finishedTurn === true`.
27
+ * `collectAllIterations: true` so post-loop nodes can aggregate every
28
+ * iteration's per-iteration usage + appended messages.
29
+ *
30
+ * Version-locked so historical runs pin to this shape; any
31
+ * change to the node set or body sub-flow bumps the version and
32
+ * `resumeRun` refuses to resume old runs against a new flow.
33
+ */
34
+ export const AGENT_TURN_FLOW_ID = 'agent.turn';
35
+ export const AGENT_TURN_FLOW_VERSION = '1.1.0';
36
+
37
+ /**
38
+ * Safety cap for iterations. Per-agent `maxSteps` is enforced by the
39
+ * `budget-check` body node — this constant only bounds catastrophic
40
+ * runaway (model always requests a tool call, no budget-check, no
41
+ * agent config). Set high enough that no real agent will hit it.
42
+ */
43
+ export const AGENT_TURN_LOOP_MAX_ITERATIONS = 32;
44
+
45
+ // Outer node ids.
46
+ export const SETUP_NODE = 'setup';
47
+ export const RENDER_PROMPT_NODE = 'render-prompt';
48
+ export const PERSIST_USER_MESSAGE_NODE = 'persist-user-message';
49
+ export const RUN_RETRIEVALS_NODE = 'run-retrievals';
50
+ export const BUILD_INITIAL_MESSAGES_NODE = 'build-initial-messages';
51
+ export const AGENT_LOOP_NODE = 'agent-loop';
52
+ export const PERSIST_FINAL_MESSAGE_NODE = 'persist-final-message';
53
+ export const EVALUATE_GUARDRAILS_NODE = 'evaluate-guardrails';
54
+ export const PERSIST_PROVENANCE_NODE = 'persist-provenance';
55
+ export const COMPOSE_RESULT_NODE = 'compose-result';
56
+
57
+ // Loop body node ids.
58
+ export const MODEL_CALL_NODE = 'model-call';
59
+ export const DISPATCH_TOOLS_NODE = 'dispatch-tools';
60
+ export const BUDGET_CHECK_NODE = 'budget-check';
61
+
62
+ /**
63
+ * JSON Schema (draft 2020-12) for each iteration's `$loop-end` output.
64
+ * See `AgentTurnIterationOutput` in the handlers module for the TS
65
+ * mirror.
66
+ */
67
+ const iterationOutputSchema = {
68
+ type: 'object',
69
+ additionalProperties: false,
70
+ required: [
71
+ 'finishReason',
72
+ 'message',
73
+ 'iterationAppended',
74
+ 'iterationUsage',
75
+ 'provider',
76
+ 'finishedTurn',
77
+ 'nextMessages',
78
+ ],
79
+ properties: {
80
+ finishReason: {
81
+ type: 'string',
82
+ enum: ['stop', 'length', 'tool-use', 'content-filter', 'error'],
83
+ },
84
+ message: { type: 'object' },
85
+ iterationAppended: { type: 'array' },
86
+ iterationUsage: {
87
+ type: 'object',
88
+ additionalProperties: false,
89
+ required: ['promptTokens', 'completionTokens', 'costUsd'],
90
+ properties: {
91
+ promptTokens: { type: 'integer', minimum: 0 },
92
+ completionTokens: { type: 'integer', minimum: 0 },
93
+ costUsd: { type: 'number', minimum: 0 },
94
+ },
95
+ },
96
+ provider: {
97
+ type: 'object',
98
+ additionalProperties: false,
99
+ required: ['id', 'model'],
100
+ properties: {
101
+ id: { type: 'string' },
102
+ model: { type: 'string' },
103
+ },
104
+ },
105
+ finishedTurn: { type: 'boolean' },
106
+ nextMessages: { type: 'array' },
107
+ /** Populated when finishReason='error' from budget-check or dispatch failure. */
108
+ errorPayload: { type: 'object' },
109
+ },
110
+ } as const;
111
+
112
+ const rawGraph = {
113
+ id: AGENT_TURN_FLOW_ID,
114
+ version: AGENT_TURN_FLOW_VERSION,
115
+ name: 'Agent turn',
116
+ description:
117
+ 'Framework-grade agent turn execution. One run per turn. Model↔tool cycle uses the kernel loop primitive.',
118
+ nodes: [
119
+ { id: SETUP_NODE, kind: 'tool', ref: 'inline' },
120
+ { id: RENDER_PROMPT_NODE, kind: 'tool', ref: 'inline' },
121
+ { id: PERSIST_USER_MESSAGE_NODE, kind: 'tool', ref: 'inline' },
122
+ { id: RUN_RETRIEVALS_NODE, kind: 'tool', ref: 'inline' },
123
+ { id: BUILD_INITIAL_MESSAGES_NODE, kind: 'tool', ref: 'inline' },
124
+ {
125
+ id: AGENT_LOOP_NODE,
126
+ kind: 'loop',
127
+ loopKind: 'while',
128
+ evaluationTiming: 'after',
129
+ maxIterations: AGENT_TURN_LOOP_MAX_ITERATIONS,
130
+ exitCondition: {
131
+ op: 'truthy',
132
+ value: { path: 'iterationOutput.finishedTurn' },
133
+ },
134
+ outputSchema: iterationOutputSchema,
135
+ collectAllIterations: true,
136
+ body: {
137
+ nodes: [
138
+ { id: MODEL_CALL_NODE, kind: 'tool', ref: 'inline' },
139
+ { id: DISPATCH_TOOLS_NODE, kind: 'tool', ref: 'inline' },
140
+ { id: BUDGET_CHECK_NODE, kind: 'tool', ref: 'inline' },
141
+ ],
142
+ edges: [
143
+ { id: 'body-e1', from: '$loop-start', to: MODEL_CALL_NODE },
144
+ { id: 'body-e2', from: MODEL_CALL_NODE, to: DISPATCH_TOOLS_NODE },
145
+ { id: 'body-e3', from: DISPATCH_TOOLS_NODE, to: BUDGET_CHECK_NODE },
146
+ { id: 'body-e4', from: BUDGET_CHECK_NODE, to: '$loop-end' },
147
+ ],
148
+ },
149
+ },
150
+ { id: EVALUATE_GUARDRAILS_NODE, kind: 'tool', ref: 'inline' },
151
+ { id: PERSIST_FINAL_MESSAGE_NODE, kind: 'tool', ref: 'inline' },
152
+ { id: PERSIST_PROVENANCE_NODE, kind: 'tool', ref: 'inline' },
153
+ { id: COMPOSE_RESULT_NODE, kind: 'tool', ref: 'inline' },
154
+ ],
155
+ edges: [
156
+ { id: 'e0', from: '$start', to: SETUP_NODE },
157
+ { id: 'e1', from: SETUP_NODE, to: RENDER_PROMPT_NODE },
158
+ { id: 'e2', from: RENDER_PROMPT_NODE, to: PERSIST_USER_MESSAGE_NODE },
159
+ { id: 'e3', from: PERSIST_USER_MESSAGE_NODE, to: RUN_RETRIEVALS_NODE },
160
+ { id: 'e4', from: RUN_RETRIEVALS_NODE, to: BUILD_INITIAL_MESSAGES_NODE },
161
+ { id: 'e5', from: BUILD_INITIAL_MESSAGES_NODE, to: AGENT_LOOP_NODE },
162
+ { id: 'e6', from: AGENT_LOOP_NODE, to: EVALUATE_GUARDRAILS_NODE },
163
+ { id: 'e7', from: EVALUATE_GUARDRAILS_NODE, to: PERSIST_FINAL_MESSAGE_NODE },
164
+ { id: 'e8', from: PERSIST_FINAL_MESSAGE_NODE, to: PERSIST_PROVENANCE_NODE },
165
+ { id: 'e9', from: PERSIST_PROVENANCE_NODE, to: COMPOSE_RESULT_NODE },
166
+ { id: 'e10', from: COMPOSE_RESULT_NODE, to: '$end' },
167
+ ],
168
+ } as const;
169
+
170
+ /**
171
+ * The compiled + validated flow. Cached — the loader is called once
172
+ * at module load. Throws on module load if the constant is malformed
173
+ * (should be caught by tests immediately).
174
+ */
175
+ export const AGENT_TURN_FLOW: Flow = (() => {
176
+ const r = loadFlow(rawGraph);
177
+ if (r.kind === 'err') {
178
+ throw new Error(
179
+ `AGENT_TURN_FLOW failed to load — this is a bug in agent-turn-flow.ts: ${JSON.stringify(r.error)}`,
180
+ );
181
+ }
182
+ return r.value;
183
+ })();