@jangts/agent-core 0.1.1 → 0.2.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 (558) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/LICENSE +55 -0
  3. package/NOTICE +6 -0
  4. package/README.md +8 -0
  5. package/development/docs/README.en.md +70 -0
  6. package/development/docs/README.md +1 -1
  7. package/development/docs/acceptance.en.md +34 -0
  8. package/development/docs/agent-development.en.md +42 -0
  9. package/development/docs/api/README.en.md +62 -0
  10. package/development/docs/api/advanced-agents.en.md +135 -0
  11. package/development/docs/api/context-processing.en.md +110 -0
  12. package/development/docs/api/core.en.md +274 -0
  13. package/development/docs/api/examples.en.md +118 -0
  14. package/development/docs/api/kits.en.md +183 -0
  15. package/development/docs/api/knowledge-answering.en.md +166 -0
  16. package/development/docs/api/mock.en.md +186 -0
  17. package/development/docs/api/observability.en.md +166 -0
  18. package/development/docs/api/reference.en.md +2235 -0
  19. package/development/docs/api/reference.md +1907 -1874
  20. package/development/docs/api/support.en.md +252 -0
  21. package/development/docs/api/support.md +27 -0
  22. package/development/docs/api/types.en.md +181 -0
  23. package/development/docs/api/workflow.en.md +188 -0
  24. package/development/docs/basic-usage.en.md +78 -0
  25. package/development/docs/create-app.en.md +76 -0
  26. package/development/docs/examples/offline-agent.en.md +273 -0
  27. package/development/docs/examples.en.md +36 -0
  28. package/development/docs/flows/knowledge-maintenance.en.md +38 -0
  29. package/development/docs/getting-started.en.md +71 -0
  30. package/development/docs/knowledge.en.md +89 -0
  31. package/development/docs/maintenance.en.md +62 -0
  32. package/development/docs/materials.en.md +38 -0
  33. package/development/docs/mechanisms.en.md +227 -0
  34. package/development/docs/memory-and-learning.en.md +42 -0
  35. package/development/docs/operations.en.md +51 -0
  36. package/development/docs/records.en.md +63 -0
  37. package/development/docs/registration.en.md +63 -0
  38. package/development/skills/agent-core-app/scripts/create-app.mjs +286 -70
  39. package/development/skills/agent-core-app/scripts/lib/knowledge.mjs +77 -16
  40. package/development/skills/agent-core-app/scripts/lib/source.mjs +30 -2
  41. package/development/skills/agent-core-app/scripts/plan.mjs +46 -12
  42. package/development/skills/agent-core-app/scripts/prepare-source.mjs +61 -10
  43. package/development/skills/agent-core-app/scripts/resources.mjs +62 -17
  44. package/development/skills/agent-core-app/scripts/validate-knowledge.mjs +18 -1
  45. package/development/skills/agent-core-app/templates/catalog.json +36 -22
  46. package/dist/cjs/capabilities/index.js +13 -0
  47. package/dist/cjs/capabilities/invocation.js +80 -10
  48. package/dist/cjs/capabilities/model.js +126 -13
  49. package/dist/cjs/capabilities/tool-runtime.js +64 -12
  50. package/dist/cjs/capabilities/tools.js +266 -31
  51. package/dist/cjs/context/assembly.js +46 -5
  52. package/dist/cjs/context/audit.js +31 -6
  53. package/dist/cjs/context/fragments.js +54 -11
  54. package/dist/cjs/context/index.js +12 -0
  55. package/dist/cjs/context/journal.js +84 -7
  56. package/dist/cjs/context/plan.js +30 -2
  57. package/dist/cjs/diagnostics/catalog.js +17 -3
  58. package/dist/cjs/diagnostics/index.js +149 -29
  59. package/dist/cjs/diagnostics/sub-flow.js +240 -40
  60. package/dist/cjs/errors.js +99 -17
  61. package/dist/cjs/execution/branch.js +20 -4
  62. package/dist/cjs/execution/engine.js +470 -56
  63. package/dist/cjs/execution/events.js +136 -18
  64. package/dist/cjs/execution/index.js +7 -0
  65. package/dist/cjs/execution/reporting.js +75 -6
  66. package/dist/cjs/execution/state.js +161 -22
  67. package/dist/cjs/execution/workflow.js +224 -32
  68. package/dist/cjs/index.js +18 -0
  69. package/dist/cjs/kits/aggregation.js +45 -3
  70. package/dist/cjs/kits/answering/batch.js +23 -4
  71. package/dist/cjs/kits/answering/check-result.js +31 -8
  72. package/dist/cjs/kits/answering/checks.js +24 -3
  73. package/dist/cjs/kits/answering/flow.js +192 -36
  74. package/dist/cjs/kits/answering/index.js +19 -1
  75. package/dist/cjs/kits/answering/tasks.js +88 -13
  76. package/dist/cjs/kits/artifacts.js +36 -4
  77. package/dist/cjs/kits/candidates.js +47 -5
  78. package/dist/cjs/kits/delivery.js +40 -5
  79. package/dist/cjs/kits/durable.js +155 -31
  80. package/dist/cjs/kits/evidence.js +66 -15
  81. package/dist/cjs/kits/family.js +152 -22
  82. package/dist/cjs/kits/index.js +12 -1
  83. package/dist/cjs/kits/inference.js +104 -16
  84. package/dist/cjs/kits/intents/catalog.js +67 -16
  85. package/dist/cjs/kits/intents/index.js +11 -0
  86. package/dist/cjs/kits/intents/registry.js +188 -43
  87. package/dist/cjs/kits/intents/scopes.js +215 -46
  88. package/dist/cjs/kits/interaction/command.js +140 -36
  89. package/dist/cjs/kits/interaction/commands.js +86 -11
  90. package/dist/cjs/kits/interaction/handlers.js +27 -10
  91. package/dist/cjs/kits/interaction/index.js +10 -0
  92. package/dist/cjs/kits/interaction/transfer.js +80 -14
  93. package/dist/cjs/kits/knowledge/catalog.js +62 -11
  94. package/dist/cjs/kits/knowledge/index.js +16 -1
  95. package/dist/cjs/kits/knowledge/publication.js +99 -23
  96. package/dist/cjs/kits/knowledge/sections.js +33 -4
  97. package/dist/cjs/kits/normalization.js +51 -7
  98. package/dist/cjs/kits/policies.js +79 -15
  99. package/dist/cjs/kits/presentation/events.js +54 -10
  100. package/dist/cjs/kits/presentation/index.js +24 -1
  101. package/dist/cjs/kits/presentation/outputs.js +176 -38
  102. package/dist/cjs/kits/presentation/templates.js +33 -5
  103. package/dist/cjs/kits/presentation/variants.js +31 -2
  104. package/dist/cjs/kits/projection.js +63 -8
  105. package/dist/cjs/kits/rank-fusion.js +27 -4
  106. package/dist/cjs/kits/reflection-log-source.js +89 -16
  107. package/dist/cjs/kits/reflection.js +234 -60
  108. package/dist/cjs/kits/retrieval.js +98 -18
  109. package/dist/cjs/kits/search.js +180 -27
  110. package/dist/cjs/kits/text-skills.js +104 -19
  111. package/dist/cjs/kits/tools.js +415 -74
  112. package/dist/cjs/kits/vector-search.js +50 -16
  113. package/dist/cjs/mock/node.js +7 -1
  114. package/dist/cjs/mock/web.js +7 -1
  115. package/dist/cjs/mock.js +7 -1
  116. package/dist/cjs/model/binding.js +68 -17
  117. package/dist/cjs/model/call-budget.js +45 -4
  118. package/dist/cjs/model/decision-retry.js +19 -1
  119. package/dist/cjs/model/defaults.js +27 -4
  120. package/dist/cjs/model/index.js +7 -0
  121. package/dist/cjs/model/interactions/arguments.js +36 -1
  122. package/dist/cjs/model/interactions/json-object.js +48 -12
  123. package/dist/cjs/model/interactions/native-functions.js +52 -10
  124. package/dist/cjs/model/message-diagnostics.js +17 -4
  125. package/dist/cjs/model/options.js +9 -1
  126. package/dist/cjs/model/preparation.js +86 -12
  127. package/dist/cjs/model/runner.js +413 -79
  128. package/dist/cjs/model/selection-transport.js +48 -8
  129. package/dist/cjs/model/settings.js +67 -13
  130. package/dist/cjs/model/token-budget.js +69 -11
  131. package/dist/cjs/model/transports.js +59 -6
  132. package/dist/cjs/structs/common.js +11 -0
  133. package/dist/cjs/structs/debug.js +34 -5
  134. package/dist/cjs/structs/errors.js +26 -1
  135. package/dist/cjs/structs/index.js +11 -1
  136. package/dist/cjs/structs/kits/durable.js +7 -0
  137. package/dist/cjs/structs/kits/family.js +1 -0
  138. package/dist/cjs/structs/kits/interaction.js +8 -1
  139. package/dist/cjs/structs/kits/knowledge-publication.js +1 -0
  140. package/dist/cjs/structs/kits/reflection.js +18 -3
  141. package/dist/cjs/structs/model/chat-provider.js +6 -0
  142. package/dist/cjs/structs/support/model/completion.js +2 -0
  143. package/dist/cjs/structs/support/model/messages.js +2 -0
  144. package/dist/cjs/support/capabilities.js +43 -6
  145. package/dist/cjs/support/context/assembly.js +88 -16
  146. package/dist/cjs/support/context/compression.js +48 -6
  147. package/dist/cjs/support/context/fragments.js +6 -0
  148. package/dist/cjs/support/context/history.js +36 -1
  149. package/dist/cjs/support/context/index.js +11 -0
  150. package/dist/cjs/support/context/nodes.js +164 -35
  151. package/dist/cjs/support/context/processing.js +319 -61
  152. package/dist/cjs/support/context/selection-policy.js +98 -21
  153. package/dist/cjs/support/context/selection.js +61 -10
  154. package/dist/cjs/support/context/snapshot.js +29 -7
  155. package/dist/cjs/support/context/strategies.js +120 -28
  156. package/dist/cjs/support/index.js +9 -1
  157. package/dist/cjs/support/model/capabilities.js +20 -1
  158. package/dist/cjs/support/model/chat-completions.js +92 -20
  159. package/dist/cjs/support/model/children.js +34 -6
  160. package/dist/cjs/support/model/compatible-provider.js +189 -59
  161. package/dist/cjs/support/model/completion/calls.js +61 -0
  162. package/dist/cjs/support/model/completion/default.js +33 -0
  163. package/dist/cjs/support/model/completion/index.js +28 -0
  164. package/dist/cjs/support/model/completion/session.js +107 -0
  165. package/dist/cjs/support/model/index.js +12 -0
  166. package/dist/cjs/support/model/interactions/index.js +12 -1
  167. package/dist/cjs/support/model/interactions/json-object.js +6 -0
  168. package/dist/cjs/support/model/interactions/native-functions.js +6 -0
  169. package/dist/cjs/support/model/observer.js +32 -6
  170. package/dist/cjs/support/model/preview-rules.js +66 -16
  171. package/dist/cjs/support/model/reply-preview.js +77 -17
  172. package/dist/cjs/support/model/stage-transport.js +33 -7
  173. package/dist/cjs/support/model/strategies.js +75 -14
  174. package/dist/cjs/support/model/transports.js +53 -11
  175. package/dist/cjs/support/registration.js +49 -7
  176. package/dist/cjs/support/schema.js +46 -4
  177. package/dist/cjs/support/stream-events.js +60 -8
  178. package/dist/cjs/support/tool-runtime.js +6 -0
  179. package/dist/cjs/support/tools.js +79 -10
  180. package/dist/cjs/support/transport/index.js +7 -0
  181. package/dist/cjs/support/transport/json.js +28 -4
  182. package/dist/cjs/support/transport/sse.js +25 -2
  183. package/dist/cjs/utils/break-observer.js +20 -2
  184. package/dist/cjs/utils/cancellation.js +77 -9
  185. package/dist/cjs/utils/catalog.js +19 -4
  186. package/dist/cjs/utils/debug.js +14 -2
  187. package/dist/cjs/utils/index.js +8 -0
  188. package/dist/cjs/utils/interaction-definition.js +26 -6
  189. package/dist/cjs/utils/invocation.js +42 -4
  190. package/dist/cjs/utils/model-protocol.js +20 -1
  191. package/dist/cjs/utils/object.js +16 -0
  192. package/dist/cjs/utils/observer.js +22 -2
  193. package/dist/cjs/utils/protocol-registry.js +47 -4
  194. package/dist/cjs/utils/query-key.js +21 -2
  195. package/dist/cjs/utils/registration.js +18 -2
  196. package/dist/cjs/utils/rules.js +39 -11
  197. package/dist/cjs/utils/schema-adapter.js +25 -2
  198. package/dist/cjs/utils/synchronous.js +64 -7
  199. package/dist/cjs/utils/text.js +15 -1
  200. package/dist/esm/capabilities/index.d.ts +13 -0
  201. package/dist/esm/capabilities/index.js +13 -0
  202. package/dist/esm/capabilities/invocation.d.ts +16 -2
  203. package/dist/esm/capabilities/invocation.js +80 -10
  204. package/dist/esm/capabilities/model.d.ts +68 -1
  205. package/dist/esm/capabilities/model.js +126 -13
  206. package/dist/esm/capabilities/tool-runtime.d.ts +11 -0
  207. package/dist/esm/capabilities/tool-runtime.js +64 -12
  208. package/dist/esm/capabilities/tools.d.ts +96 -3
  209. package/dist/esm/capabilities/tools.js +267 -32
  210. package/dist/esm/context/assembly.d.ts +13 -2
  211. package/dist/esm/context/assembly.js +46 -5
  212. package/dist/esm/context/audit.d.ts +23 -1
  213. package/dist/esm/context/audit.js +31 -6
  214. package/dist/esm/context/fragments.d.ts +37 -3
  215. package/dist/esm/context/fragments.js +54 -11
  216. package/dist/esm/context/index.d.ts +12 -0
  217. package/dist/esm/context/index.js +12 -0
  218. package/dist/esm/context/journal.d.ts +32 -1
  219. package/dist/esm/context/journal.js +84 -7
  220. package/dist/esm/context/plan.d.ts +11 -1
  221. package/dist/esm/context/plan.js +30 -2
  222. package/dist/esm/diagnostics/catalog.d.ts +6 -0
  223. package/dist/esm/diagnostics/catalog.js +17 -3
  224. package/dist/esm/diagnostics/index.d.ts +30 -2
  225. package/dist/esm/diagnostics/index.js +149 -29
  226. package/dist/esm/diagnostics/sub-flow.d.ts +41 -3
  227. package/dist/esm/diagnostics/sub-flow.js +240 -40
  228. package/dist/esm/errors.d.ts +22 -2
  229. package/dist/esm/errors.js +99 -17
  230. package/dist/esm/execution/branch.d.ts +19 -1
  231. package/dist/esm/execution/branch.js +20 -4
  232. package/dist/esm/execution/engine.d.ts +291 -5
  233. package/dist/esm/execution/engine.js +471 -57
  234. package/dist/esm/execution/events.d.ts +16 -2
  235. package/dist/esm/execution/events.js +136 -18
  236. package/dist/esm/execution/index.d.ts +7 -0
  237. package/dist/esm/execution/index.js +7 -0
  238. package/dist/esm/execution/reporting.d.ts +49 -1
  239. package/dist/esm/execution/reporting.js +75 -6
  240. package/dist/esm/execution/state.d.ts +126 -10
  241. package/dist/esm/execution/state.js +161 -22
  242. package/dist/esm/execution/workflow.d.ts +121 -3
  243. package/dist/esm/execution/workflow.js +224 -32
  244. package/dist/esm/index.d.ts +17 -1
  245. package/dist/esm/index.js +18 -0
  246. package/dist/esm/kits/aggregation.d.ts +34 -2
  247. package/dist/esm/kits/aggregation.js +45 -3
  248. package/dist/esm/kits/answering/batch.d.ts +17 -0
  249. package/dist/esm/kits/answering/batch.js +23 -4
  250. package/dist/esm/kits/answering/check-result.d.ts +18 -1
  251. package/dist/esm/kits/answering/check-result.js +31 -8
  252. package/dist/esm/kits/answering/checks.d.ts +11 -0
  253. package/dist/esm/kits/answering/checks.js +24 -3
  254. package/dist/esm/kits/answering/flow.d.ts +25 -2
  255. package/dist/esm/kits/answering/flow.js +192 -36
  256. package/dist/esm/kits/answering/index.d.ts +12 -0
  257. package/dist/esm/kits/answering/index.js +19 -1
  258. package/dist/esm/kits/answering/tasks.d.ts +32 -1
  259. package/dist/esm/kits/answering/tasks.js +88 -13
  260. package/dist/esm/kits/artifacts.d.ts +11 -0
  261. package/dist/esm/kits/artifacts.js +36 -4
  262. package/dist/esm/kits/candidates.d.ts +23 -1
  263. package/dist/esm/kits/candidates.js +47 -5
  264. package/dist/esm/kits/delivery.d.ts +34 -0
  265. package/dist/esm/kits/delivery.js +40 -5
  266. package/dist/esm/kits/durable.d.ts +19 -0
  267. package/dist/esm/kits/durable.js +155 -31
  268. package/dist/esm/kits/evidence.d.ts +28 -5
  269. package/dist/esm/kits/evidence.js +66 -15
  270. package/dist/esm/kits/family.d.ts +17 -1
  271. package/dist/esm/kits/family.js +152 -22
  272. package/dist/esm/kits/index.d.ts +12 -1
  273. package/dist/esm/kits/index.js +12 -1
  274. package/dist/esm/kits/inference.d.ts +64 -0
  275. package/dist/esm/kits/inference.js +104 -16
  276. package/dist/esm/kits/intents/catalog.d.ts +13 -1
  277. package/dist/esm/kits/intents/catalog.js +67 -16
  278. package/dist/esm/kits/intents/index.d.ts +11 -0
  279. package/dist/esm/kits/intents/index.js +11 -0
  280. package/dist/esm/kits/intents/registry.d.ts +61 -3
  281. package/dist/esm/kits/intents/registry.js +188 -43
  282. package/dist/esm/kits/intents/scopes.d.ts +73 -3
  283. package/dist/esm/kits/intents/scopes.js +215 -46
  284. package/dist/esm/kits/interaction/command.d.ts +38 -4
  285. package/dist/esm/kits/interaction/command.js +140 -36
  286. package/dist/esm/kits/interaction/commands.d.ts +66 -2
  287. package/dist/esm/kits/interaction/commands.js +86 -11
  288. package/dist/esm/kits/interaction/handlers.d.ts +19 -2
  289. package/dist/esm/kits/interaction/handlers.js +27 -10
  290. package/dist/esm/kits/interaction/index.d.ts +10 -0
  291. package/dist/esm/kits/interaction/index.js +10 -0
  292. package/dist/esm/kits/interaction/transfer.d.ts +39 -2
  293. package/dist/esm/kits/interaction/transfer.js +80 -14
  294. package/dist/esm/kits/knowledge/catalog.d.ts +13 -0
  295. package/dist/esm/kits/knowledge/catalog.js +62 -11
  296. package/dist/esm/kits/knowledge/index.d.ts +11 -0
  297. package/dist/esm/kits/knowledge/index.js +16 -1
  298. package/dist/esm/kits/knowledge/publication.d.ts +15 -1
  299. package/dist/esm/kits/knowledge/publication.js +99 -23
  300. package/dist/esm/kits/knowledge/sections.d.ts +31 -1
  301. package/dist/esm/kits/knowledge/sections.js +33 -4
  302. package/dist/esm/kits/normalization.d.ts +25 -2
  303. package/dist/esm/kits/normalization.js +51 -7
  304. package/dist/esm/kits/policies.d.ts +26 -3
  305. package/dist/esm/kits/policies.js +79 -15
  306. package/dist/esm/kits/presentation/events.d.ts +51 -4
  307. package/dist/esm/kits/presentation/events.js +54 -10
  308. package/dist/esm/kits/presentation/index.d.ts +12 -0
  309. package/dist/esm/kits/presentation/index.js +25 -2
  310. package/dist/esm/kits/presentation/outputs.d.ts +30 -1
  311. package/dist/esm/kits/presentation/outputs.js +176 -38
  312. package/dist/esm/kits/presentation/templates.d.ts +32 -3
  313. package/dist/esm/kits/presentation/templates.js +33 -5
  314. package/dist/esm/kits/presentation/variants.d.ts +29 -0
  315. package/dist/esm/kits/presentation/variants.js +31 -2
  316. package/dist/esm/kits/projection.d.ts +42 -5
  317. package/dist/esm/kits/projection.js +63 -8
  318. package/dist/esm/kits/rank-fusion.d.ts +21 -1
  319. package/dist/esm/kits/rank-fusion.js +28 -5
  320. package/dist/esm/kits/reflection-log-source.d.ts +28 -1
  321. package/dist/esm/kits/reflection-log-source.js +89 -16
  322. package/dist/esm/kits/reflection.d.ts +17 -1
  323. package/dist/esm/kits/reflection.js +235 -61
  324. package/dist/esm/kits/retrieval.d.ts +18 -2
  325. package/dist/esm/kits/retrieval.js +98 -18
  326. package/dist/esm/kits/search.d.ts +56 -3
  327. package/dist/esm/kits/search.js +180 -27
  328. package/dist/esm/kits/text-skills.d.ts +16 -2
  329. package/dist/esm/kits/text-skills.js +104 -19
  330. package/dist/esm/kits/tools.d.ts +122 -2
  331. package/dist/esm/kits/tools.js +416 -74
  332. package/dist/esm/kits/vector-search.d.ts +47 -1
  333. package/dist/esm/kits/vector-search.js +51 -17
  334. package/dist/esm/mock/node.d.ts +7 -0
  335. package/dist/esm/mock/node.js +7 -1
  336. package/dist/esm/mock/web.d.ts +7 -0
  337. package/dist/esm/mock/web.js +7 -1
  338. package/dist/esm/mock.d.ts +7 -0
  339. package/dist/esm/mock.js +7 -1
  340. package/dist/esm/model/binding.d.ts +32 -3
  341. package/dist/esm/model/binding.js +68 -17
  342. package/dist/esm/model/call-budget.d.ts +30 -2
  343. package/dist/esm/model/call-budget.js +45 -4
  344. package/dist/esm/model/decision-retry.d.ts +10 -1
  345. package/dist/esm/model/decision-retry.js +19 -1
  346. package/dist/esm/model/defaults.d.ts +13 -2
  347. package/dist/esm/model/defaults.js +27 -4
  348. package/dist/esm/model/index.d.ts +7 -0
  349. package/dist/esm/model/index.js +7 -0
  350. package/dist/esm/model/interactions/arguments.d.ts +27 -0
  351. package/dist/esm/model/interactions/arguments.js +36 -1
  352. package/dist/esm/model/interactions/json-object.d.ts +7 -1
  353. package/dist/esm/model/interactions/json-object.js +48 -12
  354. package/dist/esm/model/interactions/native-functions.d.ts +6 -0
  355. package/dist/esm/model/interactions/native-functions.js +52 -10
  356. package/dist/esm/model/message-diagnostics.d.ts +17 -1
  357. package/dist/esm/model/message-diagnostics.js +17 -4
  358. package/dist/esm/model/options.d.ts +18 -1
  359. package/dist/esm/model/options.js +9 -1
  360. package/dist/esm/model/preparation.d.ts +30 -2
  361. package/dist/esm/model/preparation.js +86 -12
  362. package/dist/esm/model/runner.d.ts +129 -5
  363. package/dist/esm/model/runner.js +414 -80
  364. package/dist/esm/model/selection-transport.d.ts +14 -1
  365. package/dist/esm/model/selection-transport.js +48 -8
  366. package/dist/esm/model/settings.d.ts +11 -0
  367. package/dist/esm/model/settings.js +67 -13
  368. package/dist/esm/model/token-budget.d.ts +59 -1
  369. package/dist/esm/model/token-budget.js +69 -11
  370. package/dist/esm/model/transports.d.ts +20 -2
  371. package/dist/esm/model/transports.js +59 -6
  372. package/dist/esm/structs/capabilities/invocation.d.ts +36 -0
  373. package/dist/esm/structs/capabilities/model.d.ts +27 -0
  374. package/dist/esm/structs/capabilities/tools.d.ts +38 -0
  375. package/dist/esm/structs/common.d.ts +62 -2
  376. package/dist/esm/structs/common.js +11 -0
  377. package/dist/esm/structs/context/fragments.d.ts +28 -0
  378. package/dist/esm/structs/context/journal.d.ts +28 -3
  379. package/dist/esm/structs/context/processing.d.ts +11 -0
  380. package/dist/esm/structs/debug.d.ts +58 -1
  381. package/dist/esm/structs/debug.js +34 -5
  382. package/dist/esm/structs/diagnostics.d.ts +119 -1
  383. package/dist/esm/structs/errors.d.ts +42 -1
  384. package/dist/esm/structs/errors.js +26 -1
  385. package/dist/esm/structs/execution/engine.d.ts +24 -1
  386. package/dist/esm/structs/execution/events.d.ts +12 -0
  387. package/dist/esm/structs/execution/workflow.d.ts +71 -0
  388. package/dist/esm/structs/index.d.ts +11 -1
  389. package/dist/esm/structs/index.js +11 -1
  390. package/dist/esm/structs/invocation.d.ts +30 -0
  391. package/dist/esm/structs/kits/aggregation.d.ts +12 -0
  392. package/dist/esm/structs/kits/answering/checks.d.ts +11 -0
  393. package/dist/esm/structs/kits/answering/flow.d.ts +35 -1
  394. package/dist/esm/structs/kits/answering/state.d.ts +21 -0
  395. package/dist/esm/structs/kits/answering/tasks.d.ts +21 -0
  396. package/dist/esm/structs/kits/artifacts.d.ts +14 -0
  397. package/dist/esm/structs/kits/candidates.d.ts +19 -0
  398. package/dist/esm/structs/kits/delivery.d.ts +22 -0
  399. package/dist/esm/structs/kits/durable.d.ts +56 -3
  400. package/dist/esm/structs/kits/durable.js +7 -0
  401. package/dist/esm/structs/kits/evidence.d.ts +23 -0
  402. package/dist/esm/structs/kits/family.d.ts +49 -1
  403. package/dist/esm/structs/kits/family.js +1 -0
  404. package/dist/esm/structs/kits/intents/catalog.d.ts +26 -0
  405. package/dist/esm/structs/kits/intents/registry.d.ts +34 -0
  406. package/dist/esm/structs/kits/intents/scopes.d.ts +36 -1
  407. package/dist/esm/structs/kits/interaction.d.ts +64 -0
  408. package/dist/esm/structs/kits/interaction.js +8 -1
  409. package/dist/esm/structs/kits/knowledge-publication.d.ts +43 -1
  410. package/dist/esm/structs/kits/knowledge-publication.js +1 -0
  411. package/dist/esm/structs/kits/knowledge.d.ts +39 -2
  412. package/dist/esm/structs/kits/normalization.d.ts +15 -0
  413. package/dist/esm/structs/kits/policies.d.ts +25 -1
  414. package/dist/esm/structs/kits/presentation/events.d.ts +28 -4
  415. package/dist/esm/structs/kits/presentation/outputs.d.ts +38 -1
  416. package/dist/esm/structs/kits/presentation/templates.d.ts +15 -0
  417. package/dist/esm/structs/kits/projection.d.ts +21 -0
  418. package/dist/esm/structs/kits/reflection.d.ts +61 -2
  419. package/dist/esm/structs/kits/reflection.js +18 -3
  420. package/dist/esm/structs/kits/retrieval.d.ts +39 -0
  421. package/dist/esm/structs/kits/search.d.ts +24 -0
  422. package/dist/esm/structs/kits/text-skills.d.ts +36 -0
  423. package/dist/esm/structs/kits/tools.d.ts +87 -0
  424. package/dist/esm/structs/model/chat-provider.d.ts +24 -1
  425. package/dist/esm/structs/model/chat-provider.js +6 -0
  426. package/dist/esm/structs/model/interactions.d.ts +38 -0
  427. package/dist/esm/structs/model/messages.d.ts +34 -0
  428. package/dist/esm/structs/model/runtime.d.ts +104 -6
  429. package/dist/esm/structs/support/capabilities.d.ts +19 -2
  430. package/dist/esm/structs/support/context-processing.d.ts +88 -9
  431. package/dist/esm/structs/support/context.d.ts +29 -1
  432. package/dist/esm/structs/support/model/completion.d.ts +50 -0
  433. package/dist/esm/structs/support/model/completion.js +1 -0
  434. package/dist/esm/structs/support/model/interactions.d.ts +13 -1
  435. package/dist/esm/structs/support/model/messages.d.ts +54 -0
  436. package/dist/esm/structs/support/model/messages.js +1 -0
  437. package/dist/esm/structs/support/model/provider-observer.d.ts +22 -1
  438. package/dist/esm/structs/support/model/provider.d.ts +71 -6
  439. package/dist/esm/structs/support/registration.d.ts +13 -0
  440. package/dist/esm/structs/support/schema.d.ts +14 -0
  441. package/dist/esm/structs/support/tools.d.ts +28 -0
  442. package/dist/esm/structs/support/transport/json.d.ts +16 -0
  443. package/dist/esm/structs/support/transport/sse.d.ts +15 -0
  444. package/dist/esm/structs/utils/rules.d.ts +19 -0
  445. package/dist/esm/support/capabilities.d.ts +25 -2
  446. package/dist/esm/support/capabilities.js +43 -6
  447. package/dist/esm/support/context/assembly.d.ts +35 -4
  448. package/dist/esm/support/context/assembly.js +88 -16
  449. package/dist/esm/support/context/compression.d.ts +17 -1
  450. package/dist/esm/support/context/compression.js +48 -6
  451. package/dist/esm/support/context/fragments.d.ts +6 -0
  452. package/dist/esm/support/context/fragments.js +6 -0
  453. package/dist/esm/support/context/history.d.ts +43 -0
  454. package/dist/esm/support/context/history.js +36 -1
  455. package/dist/esm/support/context/index.d.ts +13 -2
  456. package/dist/esm/support/context/index.js +12 -1
  457. package/dist/esm/support/context/nodes.d.ts +65 -3
  458. package/dist/esm/support/context/nodes.js +165 -36
  459. package/dist/esm/support/context/processing.d.ts +152 -1
  460. package/dist/esm/support/context/processing.js +320 -62
  461. package/dist/esm/support/context/selection-policy.d.ts +42 -2
  462. package/dist/esm/support/context/selection-policy.js +98 -21
  463. package/dist/esm/support/context/selection.d.ts +14 -1
  464. package/dist/esm/support/context/selection.js +61 -10
  465. package/dist/esm/support/context/snapshot.d.ts +23 -1
  466. package/dist/esm/support/context/snapshot.js +29 -7
  467. package/dist/esm/support/context/strategies.d.ts +35 -2
  468. package/dist/esm/support/context/strategies.js +120 -28
  469. package/dist/esm/support/index.d.ts +9 -1
  470. package/dist/esm/support/index.js +9 -1
  471. package/dist/esm/support/model/capabilities.d.ts +10 -0
  472. package/dist/esm/support/model/capabilities.js +20 -1
  473. package/dist/esm/support/model/chat-completions.d.ts +44 -15
  474. package/dist/esm/support/model/chat-completions.js +92 -20
  475. package/dist/esm/support/model/children.d.ts +34 -2
  476. package/dist/esm/support/model/children.js +34 -6
  477. package/dist/esm/support/model/compatible-provider.d.ts +29 -3
  478. package/dist/esm/support/model/compatible-provider.js +190 -60
  479. package/dist/esm/support/model/completion/calls.d.ts +40 -0
  480. package/dist/esm/support/model/completion/calls.js +58 -0
  481. package/dist/esm/support/model/completion/default.d.ts +11 -0
  482. package/dist/esm/support/model/completion/default.js +30 -0
  483. package/dist/esm/support/model/completion/index.d.ts +10 -0
  484. package/dist/esm/support/model/completion/index.js +22 -0
  485. package/dist/esm/support/model/completion/session.d.ts +16 -0
  486. package/dist/esm/support/model/completion/session.js +104 -0
  487. package/dist/esm/support/model/index.d.ts +14 -0
  488. package/dist/esm/support/model/index.js +12 -0
  489. package/dist/esm/support/model/interactions/index.d.ts +1 -1
  490. package/dist/esm/support/model/interactions/index.js +12 -1
  491. package/dist/esm/support/model/interactions/json-object.d.ts +6 -0
  492. package/dist/esm/support/model/interactions/json-object.js +6 -0
  493. package/dist/esm/support/model/interactions/native-functions.d.ts +6 -0
  494. package/dist/esm/support/model/interactions/native-functions.js +6 -0
  495. package/dist/esm/support/model/observer.d.ts +25 -2
  496. package/dist/esm/support/model/observer.js +32 -6
  497. package/dist/esm/support/model/preview-rules.d.ts +26 -2
  498. package/dist/esm/support/model/preview-rules.js +66 -16
  499. package/dist/esm/support/model/reply-preview.d.ts +22 -1
  500. package/dist/esm/support/model/reply-preview.js +77 -17
  501. package/dist/esm/support/model/stage-transport.d.ts +9 -1
  502. package/dist/esm/support/model/stage-transport.js +33 -7
  503. package/dist/esm/support/model/strategies.d.ts +28 -2
  504. package/dist/esm/support/model/strategies.js +75 -14
  505. package/dist/esm/support/model/transports.d.ts +17 -1
  506. package/dist/esm/support/model/transports.js +53 -11
  507. package/dist/esm/support/registration.d.ts +20 -1
  508. package/dist/esm/support/registration.js +49 -7
  509. package/dist/esm/support/schema.d.ts +31 -1
  510. package/dist/esm/support/schema.js +46 -4
  511. package/dist/esm/support/stream-events.d.ts +22 -1
  512. package/dist/esm/support/stream-events.js +60 -8
  513. package/dist/esm/support/tool-runtime.d.ts +6 -0
  514. package/dist/esm/support/tool-runtime.js +6 -0
  515. package/dist/esm/support/tools.d.ts +22 -0
  516. package/dist/esm/support/tools.js +79 -10
  517. package/dist/esm/support/transport/index.d.ts +7 -0
  518. package/dist/esm/support/transport/index.js +7 -0
  519. package/dist/esm/support/transport/json.d.ts +29 -2
  520. package/dist/esm/support/transport/json.js +28 -4
  521. package/dist/esm/support/transport/sse.d.ts +31 -1
  522. package/dist/esm/support/transport/sse.js +25 -2
  523. package/dist/esm/types.d.ts +9 -1
  524. package/dist/esm/utils/break-observer.d.ts +27 -2
  525. package/dist/esm/utils/break-observer.js +20 -2
  526. package/dist/esm/utils/cancellation.d.ts +56 -5
  527. package/dist/esm/utils/cancellation.js +77 -9
  528. package/dist/esm/utils/catalog.d.ts +20 -1
  529. package/dist/esm/utils/catalog.js +19 -4
  530. package/dist/esm/utils/debug.d.ts +20 -1
  531. package/dist/esm/utils/debug.js +14 -2
  532. package/dist/esm/utils/index.d.ts +8 -0
  533. package/dist/esm/utils/index.js +8 -0
  534. package/dist/esm/utils/interaction-definition.d.ts +18 -1
  535. package/dist/esm/utils/interaction-definition.js +26 -6
  536. package/dist/esm/utils/invocation.d.ts +36 -1
  537. package/dist/esm/utils/invocation.js +42 -4
  538. package/dist/esm/utils/model-protocol.d.ts +8 -0
  539. package/dist/esm/utils/model-protocol.js +20 -1
  540. package/dist/esm/utils/object.d.ts +16 -0
  541. package/dist/esm/utils/object.js +16 -0
  542. package/dist/esm/utils/observer.d.ts +19 -1
  543. package/dist/esm/utils/observer.js +22 -2
  544. package/dist/esm/utils/protocol-registry.d.ts +38 -1
  545. package/dist/esm/utils/protocol-registry.js +47 -4
  546. package/dist/esm/utils/query-key.d.ts +11 -1
  547. package/dist/esm/utils/query-key.js +21 -2
  548. package/dist/esm/utils/registration.d.ts +34 -2
  549. package/dist/esm/utils/registration.js +18 -2
  550. package/dist/esm/utils/rules.d.ts +81 -4
  551. package/dist/esm/utils/rules.js +39 -11
  552. package/dist/esm/utils/schema-adapter.d.ts +12 -1
  553. package/dist/esm/utils/schema-adapter.js +25 -2
  554. package/dist/esm/utils/synchronous.d.ts +60 -4
  555. package/dist/esm/utils/synchronous.js +64 -7
  556. package/dist/esm/utils/text.d.ts +15 -1
  557. package/dist/esm/utils/text.js +15 -1
  558. package/package.json +7 -3
@@ -0,0 +1,36 @@
1
+ # Integration references and maintenance tools
2
+
3
+ [Back to development handbook](README.md) · [Manual maintenance](maintenance.md) · [Shared flow](flows/knowledge-maintenance.md)
4
+
5
+ This kit provides [new project initialization](create-app.md), integration references for existing projects, copy-and-run offline code, and knowledge maintenance tools.
6
+
7
+ ## Integration code references
8
+
9
+ For the overall flow and call timing see [How the mechanism works](mechanisms.md); the knowledge answering diagram there is an illustration of an App composing local Kit contracts.
10
+
11
+ | Reference | What it offers an existing project |
12
+ | --- | --- |
13
+ | [Offline complete service answering](examples/offline-agent.md) | The same contract in TS/JS, from single node to tools, models, and process observation; no credentials needed |
14
+ | [Basic model and tool calls](basic-usage.md) | Named calls, static tool catalogs, real authorization and execution, Provider stream boundaries |
15
+ | [Core API](api/core.md) | Executor, model, tool, and cancellation/budget contracts |
16
+ | [Support Context](api/support.md#context) | Assembling existing knowledge and profiles into model input |
17
+ | [Knowledge API](api/knowledge-answering.md#knowledge) | Text parsing, section reading, and snapshots |
18
+ | [Knowledge answering contract](api/knowledge-answering.md) | Connecting reading, generation, checks, and output through local Kit interfaces |
19
+
20
+ The above are module call references; they do not create project directories, install dependencies, or start applications. Actual side effects are still carried by the existing project's ports.
21
+
22
+ ## Maintenance tools
23
+
24
+ The following paths are relative to the installed package's `development/`. Scripts require Node 22+ and a resolvable Core build.
25
+
26
+ | Entry | Input | Output and side effects |
27
+ | --- | --- | --- |
28
+ | `skills/agent-core-app/scripts/validate-knowledge.mjs PROJECT` | Existing project knowledge manifest, sources, and required read references | Check results; does not modify files |
29
+ | `skills/agent-core-app/scripts/prepare-source.mjs PROJECT --source UTF8_FILE --id DOCUMENT_ID` | Existing project, explicitly provided source, and stable document id | Source awaiting review and a proposal; does not overwrite effective knowledge or configuration |
30
+ | `skills/agent-core-app/scripts/plan.mjs PROJECT [--source UTF8_FILE]` | Existing project, optional source path | Agent development plan; see the Skill for specific behavior |
31
+ | `skills/agent-core-app/scripts/create-app.mjs TARGET [--write]` | Empty target directory, name and purpose, optional real source | Read-only plan by default; explicitly creates a TypeScript/Node project and unpublished source candidates |
32
+ | `skills/agent-core-app/scripts/create-app.mjs TARGET --check` | Generation receipt, current managed files, and the selected template | Read-only diff report; does not overwrite user modifications |
33
+
34
+ Knowledge maintenance tools work from configuration explicitly provided by the project and do not scan or execute project code. For initialization and diff checks see [Create an App](create-app.md). For knowledge format, flow, and publication responsibility see the [Maintenance guide](maintenance.md). Failures exit with a non-zero code and an error report; invalid UTF-8, budget, or section errors cannot be bypassed by relaxing validation.
35
+
36
+ The tools do not replace document review, resource authorization, database write-back, or publication, and they do not by default take on PDF/OCR, web crawling, or arbitrary material ingestion.
@@ -0,0 +1,38 @@
1
+ # Knowledge Preparation, Maintenance, and Publication Flow
2
+
3
+ This flow is referenced by the development-time knowledge preparation tools, the manual maintenance process, and the App's runtime knowledge growth implementation. It is not a prompt or state machine that Core executes automatically, and it grants no read or write permission. In an existing project, development-time verification and runtime loading reuse the same knowledge.config.json and compileApplicationKnowledge. When there is only an idea and no source, keep an empty file and an empty document list, and do not generate initial facts.
4
+
5
+ ## Shared Process
6
+
7
+ | Stage | What must be obtained | Execution responsibility |
8
+ | --- | --- | --- |
9
+ | Obtain sources | Originals or references, source entity, time, usage/access scope | Organized by developers, or received by the App under authorization |
10
+ | Form candidates | Locatable body text/fields; unknowns and conflicts retained | Human or App extractor; model output is only a candidate |
11
+ | Assign identity | Stable document/section IDs, explicit revision and locale | The App's maintenance policy; not the model inventing new program handlers at will |
12
+ | Check structure and references | Documents, sections, task reads, and budgets all usable | The same application compile entry and local validators such as Knowledge/Task |
13
+ | Approve for publication | Human/business verification decided from sources and risk; authorization scope not widened | The App's own publication policy; the library does not build in generic approval |
14
+ | Publish the version | Persistent records and the concurrent version commit succeed, then the new catalog becomes available | Controlled publication during development, or a transactional/CAS implementation at runtime |
15
+ | Use and trace | Requests bind the catalog and source snapshot; corrections can find the old version | App handler and storage; Core maintains execution budget and cancellation |
16
+
17
+ ## Shared Rules
18
+
19
+ 1. Document IDs are unique within the catalog; section IDs are globally unique within a document. A title or file path does not replace identity.
20
+ 2. Changing body text or metadata that affects interpretation requires changing the revision. A snapshot does not replace source material, approval records, or a content hash.
21
+ 3. Validate references to tasks, readers, sections, outputs, and checks. A knowledge file passing syntax parsing does not mean the whole Agent integration is correct.
22
+ 4. Source material, user preferences, experience candidates, published knowledge, and tool receipts are handled separately; a user statement does not automatically become a public fact.
23
+ 5. Use the smallest complete read scope; when the budget is insufficient, report an error explicitly or read in batches, and do not silently truncate rules or necessary evidence.
24
+ 6. A failed check or publication does not overwrite the old version. Existing requests keep using their own old snapshot, and knowledge is not swapped out behind the scenes between generation and review.
25
+ 7. A data update does not automatically add execution permission. Dynamic knowledge references and program capability registration are two different flows.
26
+
27
+ ## Where the Shared Rules Are Enforced
28
+
29
+ The example knowledge.config.json is an **App-owned configuration template**, not a new protocol in the library. It declares source files, read budgets, and read references that must be valid. compileApplicationKnowledge in development/skills/agent-core-app/scripts/lib/knowledge.mjs is used by both the validation tool and runtime loading; when the App copies or rewrites the template, it keeps the same entry:
30
+
31
+ ```text
32
+ 开发者/开发期脚本 → 源稿和配置 → 共享编译校验 → 发布应用资料
33
+ 运行期增长适配器 → 经审定的新版本 → 共享编译校验 → 持久提交/切换可用版本
34
+ ```
35
+
36
+ The example implements only reading local source files, version computation, reference checks, and in-memory catalog construction. Runtime candidate extraction, review, persistence transactions, CAS, deletion, and permission filtering remain the App's responsibility; writing a flow in this file does not mean those capabilities are integrated.
37
+
38
+ When integrating other formats, databases, or retrieval services, keep this flow and the same structure/reference checks, and replace only the input and commit adapters. There is no need to hard-code storage paths or one product's data tables into Core.
@@ -0,0 +1,71 @@
1
+ # Installation and integration
2
+
3
+ [Back to development handbook](README.md) · [API handbook](api/README.md)
4
+
5
+ Install Agent Core as a dependency in your application, then integrate models, tools, and workflows as needed.
6
+
7
+ When starting from an empty directory, you can first generate a TypeScript/Node project following [Create an App](create-app.md), then complete dependency and model integration along this page.
8
+
9
+ ## Installation
10
+
11
+ Install from npm:
12
+
13
+ ```sh
14
+ npm install @jangts/agent-core
15
+ ```
16
+
17
+ Dependencies are installed by the package manager according to `package.json`. When using a local package provided by the maintainer, specify the tarball path:
18
+
19
+ ```sh
20
+ npm install /artifacts/jangts-agent-core-0.1.0.tgz
21
+ ```
22
+
23
+ Replace the path and version according to the actual delivery. Offline installation requires the maintainer to provide a complete local dependency source, and the package manager resolves all dependencies.
24
+
25
+ The package provides ESM, CommonJS, and TypeScript declarations. Use Node.js 22.12.0 or later; the runtime must provide the APIs in use such as `fetch`, `AbortSignal`, and `ReadableStream`. Model credentials are managed by the application's server-side configuration.
26
+
27
+ ## Wire up the first call
28
+
29
+ First provide a ChatProvider that the App has already configured, then pass the raw question; all other run settings have defaults:
30
+
31
+ ```ts
32
+ import { Support, ModelRunner } from '@jangts/agent-core';
33
+
34
+ const provider = new Support.CompatibleModelProvider({ config: {
35
+ baseUrl: process.env.AI_BASE_URL!,
36
+ apiKey: process.env.AI_API_KEY!,
37
+ model: process.env.AI_MODEL!,
38
+ } });
39
+ const model = new ModelRunner({ provider });
40
+ const text = (await model.invoke('你好')).value;
41
+ ```
42
+
43
+ The above uses the application's existing environment configuration, and the service must be compatible with Chat Completions; baseUrl does not include /chat/completions. The Provider handles HTTP/SSE itself, so you do not need to implement stream separately. Run the [Offline complete example](examples/offline-agent.md) first without model credentials; it does not call a real model. Plain text calls need no Knowledge, tools, or workflows. Kits are imported from `@jangts/agent-core/kits/<name>` as needed; see the corresponding task documentation for specific compositions.
44
+
45
+ | Provided by the App | Executed by existing interfaces |
46
+ | --- | --- |
47
+ | The Provider's real connection configuration and user input; signal/budget overrides as needed | ModelRunner checks budget, handles cancellation/timeout, and calls the model |
48
+ | Centralized tool declarations, server-side identity, and business implementation | Core ToolRegistry executes registrations; optional Support reduces repeated wiring, and authorization constraints come from the actual declarations |
49
+ | Continue/end conditions and business error exits | AgentCoreEngine executes according to registered flows |
50
+ | Knowledge reading, visibility scope, sources and versions | Kits such as Knowledge process provided data under local contracts |
51
+
52
+ Next, follow [Model and tool integration](basic-usage.md) to complete text calls, tool proposals, and real execution in order. ModelRunner.invoke is one complete model call; multi-step execution is explicitly orchestrated by the App with existing Core APIs. For parameters and errors see [Core](api/core.md), [Support](api/support.md), and [Kit](api/kits.md).
53
+
54
+ ## Knowledge and output integration
55
+
56
+ - [Knowledge documents](knowledge.md): sections, versions, selection, and snapshots; parse/define process only in-memory data and create no storage.
57
+ - [Knowledge answering contract](api/knowledge-answering.md): the local interfaces of Knowledge, Answering, and Presentation, connected by the App through reader, authorization, model, review, and output.
58
+ - [Manual maintenance](maintenance.md) and [Agent-assisted development](agent-development.md): shared rules and scripts for maintaining existing code and knowledge.
59
+ - [Operations](operations.md): Core output, Support observer, App logs, cancellation, and budget.
60
+
61
+ Prepare knowledge faithfully when raw material exists; when there is only an idea, keep knowledge empty with open items, and do not write speculation or demo text as facts. Knowledge growth is carried by the existing App's authorization, storage, and update flows.
62
+
63
+ ## Lifecycle wiring
64
+
65
+ Static declarations can be validated during the existing project's assembly stage; user materials, read evidence, consumed budget, and session state should have explicit request/session ownership. Do not store mutable current-request state in objects shared across users.
66
+
67
+ Before integration, verify small-scope behavior that has no real side effects, then verify real models and business execution as needed. The call code in the documentation is not a standalone application template, and it does not automatically grant publication or operation permissions.
68
+
69
+ ## Debug with a mock model
70
+
71
+ When there are no model credentials, use the [MockGPT Kit](api/mock.md) to configure fixed replies, input-dependent generators, tool proposals, and failures. Direct calls are imported from `@jangts/agent-core/mock`; when a standalone HTTP model service is needed, use createMockServer from `@jangts/agent-core/mock/node`. Point the model client at its local address, and the application's workflow, tool authorization, and budget contracts stay the same.
@@ -0,0 +1,89 @@
1
+ # Knowledge documents, sections, and versions
2
+
3
+ [Back to development handbook](README.md) · [Knowledge API](api/knowledge-answering.md#knowledge) · [Complete answering chain](api/knowledge-answering.md)
4
+
5
+ ## How the library learns your knowledge structure
6
+
7
+ Core does not scan knowledge directories, infer a knowledge base from file names, or automatically generate sections from Markdown headings. The App explicitly executes the following chain:
8
+
9
+ ```text
10
+ App reads controlled sources
11
+ → provides id, revision, locale, and body/structure
12
+ → Knowledge.parseKnowledgeDocument (only when text anchors are used)
13
+ → Knowledge.defineKnowledgeCatalog
14
+ → App checks the task's document/section references
15
+ → catalog.read with the reads allowed for this round
16
+ → passes the KnowledgeSnapshot as evidence to subsequent handlers
17
+ ```
18
+
19
+ This structure is a local specification after adopting the Knowledge Kit, not a document format every Agent must store. The App can generate `KnowledgeDocument.parts` directly without Markdown parsing.
20
+
21
+ ## Development-time preparation tools and runtime assembly functions
22
+
23
+ | Entry/asset | Purpose | What it does not do |
24
+ | --- | --- | --- |
25
+ | [Maintenance guide](maintenance.md) | Prepare knowledge in the project; organize faithfully when sources exist, keep empty when none | Knowledge must have real sources; ideas are not facts |
26
+ | `Knowledge.parseKnowledgeDocument({id, revision, text, locale?})` | Parse paired section anchors into a document tree | Does not read files, compute revision, or complete all catalog validation |
27
+ | `Knowledge.defineKnowledgeCatalog(documents, options?)` | Compile/freeze an in-memory document catalog, providing ids, sectionIds, assertSelection, read | Does not create databases, watch files, import uploads, or automatically learn or write back |
28
+ | [Section marker notes](#text-section-anchors) | Local code fragment explaining paired anchors and nesting rules | Not initial knowledge and not loaded automatically |
29
+ | [knowledge.mjs](../skills/agent-core-app/scripts/lib/knowledge.mjs) | App-side template shipped with the Skill for explicitly reading files, computing versions, and compiling catalogs | Not a built-in persistent initializer of the library |
30
+
31
+ Minimal document JSON structure:
32
+
33
+ ```json
34
+ {
35
+ "id": "service-guide",
36
+ "revision": "content-version-1",
37
+ "locale": "zh-CN",
38
+ "parts": [
39
+ "全局引言。",
40
+ { "id": "delivery", "parts": [
41
+ "本章节自身正文。",
42
+ { "id": "delivery.timing", "parts": ["时机说明。"] }
43
+ ] }
44
+ ]
45
+ }
46
+ ```
47
+
48
+ `parts` may mix raw text strings and subsections. Structured section IDs must be non-empty strings and **globally unique within the same document**, not merely unique among adjacent siblings. Document IDs are unique within the catalog; catalog compilation rejects duplicate sections and cycles. Do not run only the text parser and skip catalog compilation.
49
+
50
+ ## Text section anchors
51
+
52
+ Sources use paired markers on their own lines, with no indentation:
53
+
54
+ ```md
55
+ <!-- agent-section:delivery -->
56
+ 本章节自身正文。
57
+ <!-- agent-section:delivery.timing -->
58
+ 子章节正文。
59
+ <!-- /agent-section:delivery.timing -->
60
+ <!-- /agent-section:delivery -->
61
+ ```
62
+
63
+ The characters accepted in IDs by the text adapter are English letters, digits, `_`, `.`, `:`, and `-`. Markers must keep spaces as in the example and occupy their own line; opening and closing IDs must match and nest correctly. Markdown `#` headings are merely body text. The parser recognizes anchors from raw text and is not a full Markdown interpreter; do not put example anchors on their own lines inside code fences in sources, or they will also be recognized as real sections.
64
+
65
+ Stable IDs represent content identity. Changing a title does not require changing the ID; when splitting/deleting sections, migrate task mappings and historical reference policies at the same time. Characters such as `.` are only part of the ID; parent-child relationships are determined by the actual nesting in `parts` and cannot be guessed from names.
66
+
67
+ ## Three ways to read
68
+
69
+ | Request | Returned scope |
70
+ | --- | --- |
71
+ | `{documentId:'service-guide', selection:{mode:'document'}}` | The whole body text and all descendants, in source order |
72
+ | `{documentId:'service-guide', selection:{mode:'self', sectionIds:['delivery']}}` | The selected section's own string body, excluding subsections |
73
+ | `{documentId:'service-guide', selection:{mode:'subtree', sectionIds:['delivery']}}` | The selected section and all its descendants |
74
+
75
+ Sections explicitly selected are joined by two newlines in the order of the request array; duplicate IDs are rejected. If a parent section and its child are both selected into a subtree as two different IDs, the child text may still be included twice; the library does not automatically eliminate this ancestor overlap. The App should choose the appropriate minimal complete scope.
76
+
77
+ `maxChars` limits the selected, trimmed body text of this call; exceeding it throws rather than silently cutting off the latter half. Document size, storage capacity, and model context budget are different limits. Unknown fields, identity, and file paths coming from the client are not trustworthy just because catalog.assertSelection passes; cross-boundary input is still parsed and authorized by the App according to its own schema.
78
+
79
+ ## Versions and snapshots
80
+
81
+ The App provides `revision`. It can be a hash of available content and related metadata, a database version number, or a release version; the library does not compute it for you. Secretly modifying the body text under the same id/revision invalidates version semantics.
82
+
83
+ `KnowledgeSnapshot` contains documentId, selection, revision, locale, content, and id. The id comes from the serialization of the above identity and selection and is **not a body-text hash, signature, persistence ID, or authorization credential**. Different section selections of the same document have different references, and selection order also affects identity. Generation and review should pass the same snapshot and must not re-read "the latest current body" to replace old evidence.
84
+
85
+ ## Updates and knowledge growth
86
+
87
+ The current catalog has no register, upsert, delete, save, watch, or automatic retrieval interfaces over all storage. When change is needed, the App creates a new catalog and switches its own reference; see [Continuous accumulation](memory-and-learning.md) for the pattern. Before publication, re-validate task → document → sections, reader, checks, and output references.
88
+
89
+ Both static sources and approved growth knowledge can be converted to KnowledgeDocument. User-uploaded originals, unverified self-descriptions, and experience candidates should not be mixed directly into a public authoritative catalog; permissions, sources, and review status are controlled by the App's storage/loading adapters.
@@ -0,0 +1,62 @@
1
+ # Manual initialization and knowledge maintenance
2
+
3
+ [Back to development handbook](README.md) · [Tool notes](examples.md) · [Shared flow](flows/knowledge-maintenance.md)
4
+
5
+ ## Establish sources first, not a full directory
6
+
7
+ Developers are responsible for confirming which text is an actual knowledge source and which is only a product idea, pending content, or an operation instruction. When there is only an idea, keep files empty and do not generate introductions, policies, or user profiles that look real. When actual material exists, organize it faithfully; when originals are complex, conflicting, or mixed with instructions, preserve the originals and form candidates first, and never treat commands inside them as development authorization.
8
+
9
+ Integrate existing projects following the [integration guide](getting-started.md), and initialize new projects following [Create an App](create-app.md). Pure conversation does not require a knowledge base; maintain knowledge configuration explicitly only when knowledge answering is needed. Compare existing directories first, preserve business files, and limit test knowledge to test scopes.
10
+
11
+ A knowledge App prepares a `knowledge.config.json` in the same directory, for example the empty state below, and creates an empty `initial.knowledge.md`. Files are not read until they are registered.
12
+
13
+ ```json
14
+ {
15
+ "schemaVersion": 1,
16
+ "maxDocumentBytes": 32000,
17
+ "maxReadChars": 8000,
18
+ "documents": [],
19
+ "requiredReads": []
20
+ }
21
+ ```
22
+
23
+ After installing the maintainer-delivered Core and full dependencies following the [installation guide](getting-started.md), you can run the shared validation entry. The directory argument below is the knowledge directory containing `knowledge.config.json` and does not have to be the project root; the tool path is located from the package installed in the current project:
24
+
25
+ ```sh
26
+ node node_modules/@jangts/agent-core/development/skills/agent-core-app/scripts/validate-knowledge.mjs ./existing-project/knowledge
27
+ ```
28
+
29
+ When there is no knowledge it outputs the empty-catalog state; this is a correct preparation state and should not be made to look successful by fabricating knowledge. Actual sources can first be turned into candidates with the tools below, and after confirmation written into source files and registered in the manifest.
30
+
31
+ ## How the configuration is maintained
32
+
33
+ `knowledge.config.json` is the template's App configuration; the library does not require every App to use this file. The current shared loader understands:
34
+
35
+ | Field | Constraint and meaning |
36
+ | --- | --- |
37
+ | `schemaVersion` | Currently 1, checked by the shared compiler |
38
+ | `maxDocumentBytes` | Positive integer, byte limit per source file; not a model token limit |
39
+ | `maxReadChars` | Positive integer, per-read character limit for Knowledge |
40
+ | `documents` | May be empty; entries are `{id,file,locale?}`; currently only lowercase `*.knowledge.md` file names in the same directory are allowed, and model-supplied paths are not accepted |
41
+ | `requiredReads` | `{documentId,selection}` actually depended on by tasks; all references are checked at compile time |
42
+
43
+ Document IDs must be unique; see [Knowledge documents](knowledge.md) for section rules. Newly added files must be registered explicitly; being on disk does not automatically grant publication or read eligibility. Source and subsequent version traceability are carried by the maintainer's own change records; candidate tools do not replace complete publication records.
44
+
45
+ ## Adding and updating reuse the same validation
46
+
47
+ ```sh
48
+ node node_modules/@jangts/agent-core/development/skills/agent-core-app/scripts/prepare-source.mjs ./existing-project/knowledge --source ./revision.md --id initial-doc
49
+ node node_modules/@jangts/agent-core/development/skills/agent-core-app/scripts/validate-knowledge.mjs ./existing-project/knowledge
50
+ ```
51
+
52
+ The first command only generates a candidate; the second checks the **currently effective configuration** and does not publish the candidate. The candidate contains the original file, document ID, suggested addition/replacement, source hash, revision, as well as the configuration hash at preparation time and existing document versions. Candidate validation also checks existing required section references; deleting a referenced section fails, and the task and configuration must be explicitly adjusted and the candidate prepared again—errors cannot be skipped automatically.
53
+
54
+ The configuration hash comes from the raw bytes actually parsed this time, sharing a single configuration read with the candidate's budget and required-read validation, so it is not re-read after validation and marked against a different baseline. Each source file version comes from content read this time; this does not constitute an atomic multi-file filesystem snapshot.
55
+
56
+ Publication is done by the maintainer: verify sources, body diffs, task references, and permissions → save the candidate to a controlled source file → add the new document to the manifest or update an existing file → use the same check entry → publish one complete version. Before publishing, compare the effective configuration and the revisions of replaced documents against the candidate baseline; if stale, redo the comparison. A single-file write is not a multi-file transaction; production systems should use their own versioned publication, transactions, or atomic switching.
57
+
58
+ Direct editing follows the same flow. A failed validation keeps the published version; generation and review use the same snapshot; a failed update does not delete the original file. Manual and runtime growth can share `compileApplicationKnowledge`, replacing only the input and commit adapters.
59
+
60
+ ## What maintenance does not happen automatically
61
+
62
+ The tools have no automatic approval, publication, file watching, indexing, scheduled learning, or database writes. User profiles and business experience are different application data; define their sources, updates, and deletions according to [Continuous accumulation](memory-and-learning.md), then decide whether to convert them into readable Knowledge documents.
@@ -0,0 +1,38 @@
1
+ # User materials and data boundaries
2
+
3
+ [Back to development handbook](README.md) · [Continuous accumulation](memory-and-learning.md)
4
+
5
+ Receiving material, extracting body text, using it within a round, storing it in a personal profile, and publishing it as shared knowledge are different operations. Core does not automatically convert uploads into long-term memory, nor does it trust instructions in material just because the material contains section anchors.
6
+
7
+ ## Minimal processing chain
8
+
9
+ ```text
10
+ Server confirms identity and material ownership
11
+ → App checks format/size, saves necessary source information
12
+ → Controlled parser extracts body text, records extraction failures or gaps
13
+ → Selects content according to this round's authorization
14
+ → Support context fragment marks it as user data and sets a budget
15
+ → Handler uses the material and binds output to actual evidence
16
+ ```
17
+
18
+ Parsing and saving are provided by App adapters. The plain text example does not mean PDF, image OCR, audio transcription, web crawling, or archives are supported. When these formats are needed, register parsing capabilities and acceptable results explicitly; parsing failure must not be treated as empty content and then followed by a complete conclusion.
19
+
20
+ | Field to be made explicit | Purpose |
21
+ | --- | --- |
22
+ | Material ID, owning user/tenant, access scope | The server establishes permissions and does not trust client-claimed owners |
23
+ | Original reference, type, source time, content hash | Retrieve the original and determine versions; do not treat file names as stable identity |
24
+ | Extraction version, body text, gaps, and parsing status | Distinguish originals from model/parser output |
25
+ | Lifecycle, retention, and deletion method | Whether this round, the session, or persistent storage is decided by the product |
26
+ | Review/publication status | Candidate material cannot automatically become shared authoritative knowledge |
27
+
28
+ See [Material record](records.md#material-record) for a reference. It is an App-owned record sample with no corresponding Core persistence API.
29
+
30
+ ## Context and tools
31
+
32
+ Use Support fragments to note the real source, `trust: 'user'`, and the corresponding lifecycle. The trust label is part of the assembly contract, not a sandbox; the App still needs to prevent material body text from being treated as higher-privilege instructions or executable code. Do not dynamically add one executable tool per uploaded file; usually keep a controlled `material.read` whose parameters reference IDs authorized for this round.
33
+
34
+ When continuing use across rounds, pass only references available to the session and re-confirm permissions and lifecycle. When persistent storage is needed, enter the application's own candidate and publication flow. After deleting an original, also clean up extracted text, summaries, indexes, and references according to the App policy—do not delete only the UI list.
35
+
36
+ ## Delivery limits
37
+
38
+ Do not output the full material text by default in errors, logs, or receipts. Partial reads, insufficient budget, and incomplete parsing should become explicit check results; retries cannot widen the visible scope. Source references, file download URLs, and cross-end presentation are chosen by the App; the Interaction Kit is optional, and front and back ends are not forced to use InteractionProtocol/CommandCatalog uniformly.
@@ -0,0 +1,227 @@
1
+ # How the mechanism works
2
+
3
+ [Back to development handbook](README.md) · [API handbook](api/README.md) · [Knowledge answering contract](api/knowledge-answering.md)
4
+
5
+ This document explains the current implementation with diagrams. Flows labeled "App composition example" are explicitly orchestrated by the application, not a fixed Agent flow built into Core; Core does not require the App to use Support, Kit, or task decomposition.
6
+
7
+ ## 1. Overall collaboration relationship
8
+
9
+ ```mermaid
10
+ flowchart LR
11
+ User[User input] --> App[App: identity, configuration, business orchestration and delivery]
12
+ App -->|calls runtime APIs, registers handlers| Core[Core: execution, model, tools, context contracts]
13
+ Core -->|calls back according to registered contracts| Handler[App handler: business processing and actual ports]
14
+ Handler -->|state updates, results or errors| Core
15
+ App -->|optional integration assistance| Support[Support: builds configuration, adapters and handlers]
16
+ Support -->|artifacts handed to the App for registration| App
17
+ Handler -->|calls as needed| Kit[Optional Kit: knowledge, answering, presentation, interaction, etc.]
18
+ Kit -->|local business results| Handler
19
+ Handler --> IO[App databases, files and external services]
20
+ Core -->|ChatProvider contract| Provider[Model connection provided by the App]
21
+ Provider --> Model[Model service]
22
+ App --> Output[User-visible output]
23
+ ```
24
+
25
+ Core and App have a call/callback relationship. Support assists the App in integrating the same set of contracts; Kit is chosen one-way by the App, and a Kit may call Core APIs internally, still bound by the same budget, cancellation, and error contracts.
26
+
27
+ ## 2. How task concepts map to execution mechanisms
28
+
29
+ ```mermaid
30
+ flowchart TD
31
+ Question[User question] --> Compose[App organizes this round's processing by business]
32
+ Catalog[Central capability manifest: purpose, schema, constraints, handler] --> View[Capability view visible this round]
33
+ Identity[Server-side identity and resource permissions] --> View
34
+ View --> Compose
35
+ Compose --> Workflow[Optional AgentWorkflow: declares execution nodes and routing]
36
+ Workflow --> Node[Node: requires, run, provides, routes, onErrorNodeId]
37
+ Node --> Handler[App handler]
38
+ Handler --> Model[ModelRunner: obtains model proposals or answers]
39
+ Handler --> Tool[ToolRegistry: executes registered tools]
40
+ Handler --> Tasks[Optional Answering: domain answering tasks]
41
+ Tasks --> Definition[Task declaration: id, inputSchema, readerId, outputId, checkIds, intentIds, scopeId]
42
+ Definition --> Evidence[App reader: authorization, actual reading and evidence]
43
+ Evidence --> Items[AnswerItem: source status and owning input ID]
44
+ Items --> Answer[Generation, checks, local repair and delivery status]
45
+ Model --> Update[Handler returns results or local state updates]
46
+ Tool --> Update
47
+ Answer --> Update
48
+ Update --> Route[Core commits compliant updates, then selects a route per declarations]
49
+ Route -->|continue| Node
50
+ Route -->|complete| Result[Return to App for delivery]
51
+ ```
52
+
53
+ The three concepts here are different: the **user question** is input, a **workflow node** is an execution stage, and an **answering task/item** is a domain object of the Answering Kit. One node can process multiple answer items; model proposals do not automatically create workflow nodes or install new handlers. A basic `ModelRunner.invoke` call needs neither a workflow nor answering tasks.
54
+
55
+ ## 3. How a Core workflow advances
56
+
57
+ Corresponds to the actual rules of `AgentWorkflow` and a bound `AgentCoreEngine.run`.
58
+
59
+ ```mermaid
60
+ flowchart TD
61
+ Definition[App declares workflow manifest] --> Validate[Validate on construction: nodes, route references, reachability, bounded cycles]
62
+ Validate --> Entry[entryNodeId corresponds to a startsRound node]
63
+ Entry --> Abort[Check cancellation, obtain target node]
64
+ Abort --> Round{Node marked startsRound?}
65
+ Round -->|yes| Budget{Enough round budget?}
66
+ Budget -->|no| Exhaust[Throw budget exhausted error]
67
+ Budget -->|yes| Count[Consume one round]
68
+ Round -->|no| Enter[Emit enter event]
69
+ Count --> Enter
70
+ Enter --> Requires[Check requires fields]
71
+ Requires --> Run[Call node run, obtain local updates]
72
+ Run --> Commit[Check cancellation, update shape and provides, then commit updates]
73
+ Commit --> Select[Select the first match in routes order]
74
+ Select --> Route{Match result}
75
+ Route -->|target node| Transition[Emit transition, clear previous node error]
76
+ Transition --> Abort
77
+ Route -->|complete| Complete[Compute result, isResult, check cancellation]
78
+ Complete --> End[Emit complete and return]
79
+ Route -->|no match| Contract[Workflow contract error]
80
+ Requires -.->|exception| Error[Error handling within the node try scope]
81
+ Run -.->|exception| Error
82
+ Commit -.->|exception| Error
83
+ Complete -.->|exception| Error
84
+ Contract --> Error
85
+ Error --> Recover{Not cancelled, not a contract error, and onErrorNodeId present?}
86
+ Recover -->|yes| ErrorNode[Move to the error node with context.error]
87
+ ErrorNode --> Abort
88
+ Recover -->|no| Throw[Throw to the caller]
89
+ ```
90
+
91
+ Only entering a node with `startsRound: true` consumes a round; other stages in the same round do not count separately. Every possible cycle (including error routing) must pass through a round boundary. When the entry node omits the field, it starts a round by default. The budget entry check is outside the node's try scope, so exhaustion is not routed to that node's onErrorNodeId. `run(step)` uses an explicit StepOutcome: `{ type: 'continue' }` to continue, `{ type: 'complete', value }` to complete; value may legitimately be undefined.
92
+
93
+ The commit guard covers only local state updates managed by Core; it does not roll back external writes that the handler has already performed. A failed diagnostic observation does not change business execution.
94
+
95
+ ## 4. Timing from model proposal to actual tool execution
96
+
97
+ **App composition example**: uses the Support tool catalog, ModelRunner, and the Core tool executor.
98
+
99
+ ```mermaid
100
+ sequenceDiagram
101
+ actor U as User
102
+ participant A as App orchestration
103
+ participant S as Support tool catalog
104
+ participant M as ModelRunner
105
+ participant P as ChatProvider / model
106
+ participant T as Core ToolRegistry
107
+ participant H as App tool handler
108
+ U->>A: asks a question
109
+ A->>S: Obtains capability view and in-request runtime from the same manifest
110
+ S-->>A: Model declarations, parsers, real execution registration
111
+ A->>M: invoke (input and registered transport)
112
+ M->>M: Check cancellation, call quota, input and schema budget
113
+ M->>P: stream (input and visible capabilities)
114
+ P-->>M: Model chunks
115
+ M->>M: Full collection, protocol parsing
116
+ M-->>A: ToolProposal (tool name and raw parameters)
117
+ A->>T: runtime.invoke (tool name, parameters)
118
+ T->>T: Look up registered tool, parseInput
119
+ T->>H: authorize (parameters, server-side context, signal)
120
+ alt Authorization passes
121
+ H-->>T: Allowed
122
+ T->>H: execute, and wait for actual I/O
123
+ H-->>T: Actual result
124
+ T->>T: parseOutput, record success event
125
+ T-->>A: Validated result
126
+ opt App needs to continue generation based on the result
127
+ A->>M: invoke (tool result and follow-up input)
128
+ M->>P: Generate within the remaining quota
129
+ P-->>M: Complete response
130
+ M-->>A: Parsed result
131
+ end
132
+ A->>A: Business checks, bind facts and deliver
133
+ A-->>U: Final reply
134
+ else Authorization denied or execution/output check fails
135
+ H-->>T: Denied or exception
136
+ T-->>A: Error and failure event
137
+ A-->>U: App handles the failure according to the actual cause
138
+ end
139
+ ```
140
+
141
+ The error branch in the diagram also covers input/output check failures in the Registry itself, where a handler call may not occur. A model proposal is not a success receipt, and Core does not automatically execute a tool just because the model proposed its name; whether to call it subsequently, generate again, or end is decided by the App handler/workflow. A failed tool output check also does not mean side effects that already occurred are rolled back.
142
+
143
+ ## 5. Internal flow of one model call
144
+
145
+ ```mermaid
146
+ flowchart TD
147
+ Invoke[invoke: normalize input, select registered transport] --> Initial[Check cancellation and remaining call quota]
148
+ Initial --> Prepare[Prepare or reuse this transport snapshot]
149
+ Prepare --> Assemble[Core assembles text, messages, BuiltContext or ContextPlan]
150
+ Assemble --> Check[Actual message, transport instruction, Schema and optional token budget checks]
151
+ Check --> Consume[Obtain model call quota, set call deadline]
152
+ Consume --> Stream[Provider stream: collect chunks and check output budget]
153
+ Stream --> Finish[Complete response: finish, parse, resolve]
154
+ Finish --> Deliver[Await content delivery in order, check cancellation]
155
+ Deliver --> Journal[Commit Journal and completion information]
156
+ Journal --> Result[Return value and invocation]
157
+ Stream -.->|cancellation, timeout, upstream or output error| Error[Mark stage and error code and throw]
158
+ Finish -.->|protocol parsing failure| Error
159
+ ```
160
+
161
+ Core is responsible for generic input assembly and final budget checks and does not implicitly select or compress. When processing is needed, the App registers Support or custom processing nodes into the same Workflow and uses ordinary routes to decide when to execute them. Model calls inside processing nodes share the request quota, cancellation, and deadlines; see [Context nodes](api/context-processing.md) for details.
162
+
163
+ An ordinary invoke does not require prepare in advance. When early measurement is needed, use `model.prepare(...)` to obtain a single snapshot, call `prepared.measure(input)` repeatedly, then still consume the same handle through `model.invoke({ input, prepared })`. Measurement covers the actual transport instructions and Schema; the final check remains in effect, and the handle is not a quota reservation.
164
+
165
+ `ModelRunner.sink.output` waits in order for consumers of generated chunks, and the fully parsed value is still returned through invoke; `execution.observe.event` is side-channel observation with isolated failures. Chunk preview and final business delivery are different boundaries.
166
+
167
+ ## 6. Task checks and local repair in the Answering Kit
168
+
169
+ Corresponds to the seven nodes currently registered by `defineAnswerFlow`; this flow exists only when the Kit is adopted.
170
+
171
+ ```mermaid
172
+ flowchart TD
173
+ Input[Validate input IDs, item ownership and count] --> Generate[generate: generate only source=ready items]
174
+ Generate --> Validate[validate: local checks and keep normalized values]
175
+ Validate --> Review[review: review per off / optional / required policy]
176
+ Review --> Select[select-repair: select items that are ready and still have issues]
177
+ Select --> Can{Failed items, repair count and call quota available?}
178
+ Can -->|yes| Repair[repair: consume one repair chance, submit only failed items and issues]
179
+ Repair --> Recheck[recheck: re-check only items generated this time]
180
+ Recheck --> Select
181
+ Can -->|no| Deliver[deliver: judge item by item]
182
+ Deliver --> Accepted[accepted: source ready, value present and checks satisfied]
183
+ Deliver --> Fallback[fallback: App fallback provided a value]
184
+ Deliver --> Blocked[blocked: no deliverable value]
185
+ ```
186
+
187
+ Initial generation and each repair consume one workflow round; `maxRepairs` additionally limits the number of repairs. `canInvoke` reads the real quota provided by the App, and the Kit does not create an extra model budget. Non-ready sources do not enter generation or repair; items whose review has explicitly failed cannot become passing because review later becomes unavailable. Cancellation, invalid item ownership, and program contract errors throw, and are not automatically disguised as fallback.
188
+
189
+ ## 7. Composition timing of App knowledge answering
190
+
191
+ The diagram below illustrates an App composition organized by the [Knowledge, Answering, and Presentation contracts](api/knowledge-answering.md); the concrete orchestration and ports are provided by the App. For complete code that can be copied and run directly see [Offline service answering](examples/offline-agent.md); that code does not enable Knowledge/Answering.
192
+
193
+ ```mermaid
194
+ sequenceDiagram
195
+ actor U as User
196
+ participant A as App answer
197
+ participant T as Answering task catalog
198
+ participant K as Knowledge / App reader
199
+ participant F as Answering Flow
200
+ participant M as Same ModelRunner
201
+ participant C as App checks and review
202
+ participant O as Presentation
203
+ U->>A: question, signal
204
+ A->>T: Parse task parameters and read
205
+ T->>K: Call the registered reader
206
+ K->>K: App authorize, read the fixed revision snapshot
207
+ K-->>A: Question and source evidence
208
+ A->>F: Run declared answer items
209
+ F->>M: generate: call with evidence
210
+ M-->>F: Draft
211
+ F->>C: Local checks and policy review
212
+ C-->>F: Check results and issues
213
+ loop issues remain and repair count, real quota allow
214
+ F->>M: Repair only failed items
215
+ M-->>F: Repaired draft
216
+ F->>C: Re-check and review
217
+ C-->>F: Latest check results
218
+ end
219
+ F-->>A: accepted / fallback / blocked
220
+ opt A deliverable value exists
221
+ A->>O: Bind program source fields and render the template
222
+ O-->>A: Body text and sources
223
+ end
224
+ A-->>U: status, text (if any), issues
225
+ ```
226
+
227
+ If review uses a model, it should consume quota through the same ModelRunner passed in. Fallback evidence and allowed wording are provided by the App; when no deliverable value is provided, blocked is returned. Authorization, reading, cancellation, or contract errors may be thrown directly, with no guarantee of reaching final delivery.
@@ -0,0 +1,42 @@
1
+ # Memory and continuous accumulation
2
+
3
+ [Back to development handbook](README.md) · [Shared flow](flows/knowledge-maintenance.md) · [Record templates](records.md)
4
+
5
+ The library has no out-of-the-box long-term memory database, user profile merging service, or automatic learner of business experience. Core provides execution contracts, Support helps assemble context and calls, and Kits such as Knowledge/Answering provide local processing once adopted. Whether to record, how to assign ownership, and when to update and delete are all explicitly implemented by the App; not recording is also a valid choice.
6
+
7
+ ## Different data needs different rules
8
+
9
+ | Data | Recommended use | Should not be equated with |
10
+ | --- | --- | --- |
11
+ | Recent Q&A | Session continuity, disambiguation | Tool execution logs, permanent knowledge |
12
+ | Accumulated user preferences | Addressing, expression preferences, ongoing topics | Identity, permissions, public facts |
13
+ | Business experience candidates | Inducing reusable suggestions and failure patterns from results | Proven rules, automatic authorization |
14
+ | Published knowledge | Business facts with explicit sources, scope, and versions | Unverified user self-descriptions |
15
+ | Original materials and extraction results | Current task evidence or authorized archives | Automatically shared knowledge |
16
+
17
+ Do not use one source-less large summary to hold all categories. Each record category should at least have stable identity, ownership, source, version, status, and retention policy. Template fields are only a starting point; the App defines and validates them, and they are not a new Core protocol that all consumers must follow.
18
+
19
+ ## Application flow for updating user preferences
20
+
21
+ ```text
22
+ Select final Q&A allowed to be recorded, and the watermark
23
+ → Old summary + new Q&A + explicit merge rules
24
+ → Model extraction of candidates under budget constraints
25
+ → Parsing and length/source/sensitive-scope checks
26
+ → Commit summary and new watermark on the premise of the old version
27
+ → Subsequent requests read by identity and mark it as low-trust memory
28
+ ```
29
+
30
+ Do not mix the model's internal reasoning, corrections, or unexecuted actions into user profiles. When new expressions conflict with old preferences, apply the App's explicit rules; authoritative human facts are still provided by the corresponding data source. On model failure or version conflict, keep the old summary and the unconsumed watermark and retry with bounds, avoiding lost messages or duplicate merges. Scheduled tasks, storage transactions/CAS, leases, and retries are implemented by the App; the Core per-request budget cannot be assumed to cover background jobs.
31
+
32
+ ## Application flow for experience growth
33
+
34
+ Register extraction, validation, query, and publication implementations with a fixed task type; adding an experience record is only a data change and does not automatically add a handler. Candidates should be associated with actual sources and results, retain applicability scope, counterexamples, and conflicts, and not treat one success as a universal rule.
35
+
36
+ Candidate formation → deduplication/conflict checks → business validation or human confirmation → versioned publication → controlled reading, consistent with the [shared flow](flows/knowledge-maintenance.md). To integrate with Knowledge, the App converts permitted records into `KnowledgeDocument`, compiles a new catalog, and switches the request reference; active requests keep using the old snapshot.
37
+
38
+ `prepare-source.mjs` is used to organize text candidates during development. Runtime persistent learning can reuse its compilation logic and source constraints, while storage, concurrency, and publication policies are provided by the App.
39
+
40
+ ## Decisions required before runtime integration
41
+
42
+ Record scope and user choices, tenant isolation, visibility scope, retention and deletion, source priority, update conflicts, idempotency keys/consumption watermarks, failure recovery, and which content is forever candidate-only. Without these implementations, documentation and interfaces should state clearly "used for this round/session" or "manually maintained", and must not claim automatic learning.