kagent-ts 0.1.3 → 0.1.5

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 (349) hide show
  1. package/LICENSE +68 -21
  2. package/README.md +27 -371
  3. package/dist/compression/progressive-compressor.d.ts +66 -0
  4. package/dist/compression/progressive-compressor.d.ts.map +1 -0
  5. package/dist/compression/progressive-compressor.js +367 -0
  6. package/dist/compression/progressive-compressor.js.map +1 -0
  7. package/dist/compression/types.d.ts +1 -5
  8. package/dist/compression/types.d.ts.map +1 -1
  9. package/dist/context/context-manager.d.ts +34 -15
  10. package/dist/context/context-manager.d.ts.map +1 -1
  11. package/dist/context/context-manager.js +78 -28
  12. package/dist/context/context-manager.js.map +1 -1
  13. package/dist/context/types.d.ts +20 -4
  14. package/dist/context/types.d.ts.map +1 -1
  15. package/dist/core/agent.d.ts +407 -35
  16. package/dist/core/agent.d.ts.map +1 -1
  17. package/dist/core/agent.js +685 -70
  18. package/dist/core/agent.js.map +1 -1
  19. package/dist/core/fusion-agent.d.ts +207 -0
  20. package/dist/core/fusion-agent.d.ts.map +1 -0
  21. package/dist/core/fusion-agent.js +769 -0
  22. package/dist/core/fusion-agent.js.map +1 -0
  23. package/dist/core/hooks.d.ts +19 -7
  24. package/dist/core/hooks.d.ts.map +1 -1
  25. package/dist/core/plan-solve-agent.d.ts +1 -15
  26. package/dist/core/plan-solve-agent.d.ts.map +1 -1
  27. package/dist/core/plan-solve-agent.js +144 -117
  28. package/dist/core/plan-solve-agent.js.map +1 -1
  29. package/dist/core/react-agent.d.ts +0 -13
  30. package/dist/core/react-agent.d.ts.map +1 -1
  31. package/dist/core/react-agent.js +128 -101
  32. package/dist/core/react-agent.js.map +1 -1
  33. package/dist/core/response-schema.d.ts +65 -0
  34. package/dist/core/response-schema.d.ts.map +1 -1
  35. package/dist/core/response-schema.js +174 -1
  36. package/dist/core/response-schema.js.map +1 -1
  37. package/dist/core/system-prompts.d.ts +27 -0
  38. package/dist/core/system-prompts.d.ts.map +1 -0
  39. package/dist/core/system-prompts.js +112 -0
  40. package/dist/core/system-prompts.js.map +1 -0
  41. package/dist/eval/benchmark.d.ts +81 -0
  42. package/dist/eval/benchmark.d.ts.map +1 -0
  43. package/dist/eval/benchmark.js +292 -0
  44. package/dist/eval/benchmark.js.map +1 -0
  45. package/dist/eval/eval-runner.d.ts +79 -0
  46. package/dist/eval/eval-runner.d.ts.map +1 -0
  47. package/dist/eval/eval-runner.js +252 -0
  48. package/dist/eval/eval-runner.js.map +1 -0
  49. package/dist/eval/index.d.ts +7 -0
  50. package/dist/eval/index.d.ts.map +1 -0
  51. package/dist/eval/index.js +13 -0
  52. package/dist/eval/index.js.map +1 -0
  53. package/dist/eval/tool-call-evaluator.d.ts +72 -0
  54. package/dist/eval/tool-call-evaluator.d.ts.map +1 -0
  55. package/dist/eval/tool-call-evaluator.js +265 -0
  56. package/dist/eval/tool-call-evaluator.js.map +1 -0
  57. package/dist/eval/types.d.ts +219 -0
  58. package/dist/eval/types.d.ts.map +1 -0
  59. package/dist/eval/types.js +3 -0
  60. package/dist/eval/types.js.map +1 -0
  61. package/dist/index.d.ts +61 -14
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.js +121 -8
  64. package/dist/index.js.map +1 -1
  65. package/dist/llm/anthropic-provider.d.ts +141 -0
  66. package/dist/llm/anthropic-provider.d.ts.map +1 -0
  67. package/dist/llm/anthropic-provider.js +486 -0
  68. package/dist/llm/anthropic-provider.js.map +1 -0
  69. package/dist/llm/errors.d.ts +26 -0
  70. package/dist/llm/errors.d.ts.map +1 -0
  71. package/dist/llm/errors.js +19 -0
  72. package/dist/llm/errors.js.map +1 -0
  73. package/dist/llm/factory.d.ts +73 -0
  74. package/dist/llm/factory.d.ts.map +1 -0
  75. package/dist/llm/factory.js +77 -0
  76. package/dist/llm/factory.js.map +1 -0
  77. package/dist/llm/fallback-provider.d.ts +47 -0
  78. package/dist/llm/fallback-provider.d.ts.map +1 -0
  79. package/dist/llm/fallback-provider.js +91 -0
  80. package/dist/llm/fallback-provider.js.map +1 -0
  81. package/dist/llm/interface.d.ts +54 -11
  82. package/dist/llm/interface.d.ts.map +1 -1
  83. package/dist/llm/interface.js +34 -0
  84. package/dist/llm/interface.js.map +1 -1
  85. package/dist/llm/model-router.d.ts +126 -0
  86. package/dist/llm/model-router.d.ts.map +1 -0
  87. package/dist/llm/model-router.js +178 -0
  88. package/dist/llm/model-router.js.map +1 -0
  89. package/dist/llm/openai-provider.d.ts +8 -32
  90. package/dist/llm/openai-provider.d.ts.map +1 -1
  91. package/dist/llm/openai-provider.js +27 -60
  92. package/dist/llm/openai-provider.js.map +1 -1
  93. package/dist/llm/rate-limiter.d.ts +41 -0
  94. package/dist/llm/rate-limiter.d.ts.map +1 -0
  95. package/dist/llm/rate-limiter.js +93 -0
  96. package/dist/llm/rate-limiter.js.map +1 -0
  97. package/dist/llm/retry.d.ts +26 -0
  98. package/dist/llm/retry.d.ts.map +1 -0
  99. package/dist/llm/retry.js +44 -0
  100. package/dist/llm/retry.js.map +1 -0
  101. package/dist/llm/token-budget.d.ts +97 -0
  102. package/dist/llm/token-budget.d.ts.map +1 -0
  103. package/dist/llm/token-budget.js +115 -0
  104. package/dist/llm/token-budget.js.map +1 -0
  105. package/dist/logging/index.d.ts +2 -0
  106. package/dist/logging/index.d.ts.map +1 -0
  107. package/dist/logging/index.js +7 -0
  108. package/dist/logging/index.js.map +1 -0
  109. package/dist/logging/logger.d.ts +38 -0
  110. package/dist/logging/logger.d.ts.map +1 -0
  111. package/dist/logging/logger.js +34 -0
  112. package/dist/logging/logger.js.map +1 -0
  113. package/dist/mcp/index.d.ts +4 -0
  114. package/dist/mcp/index.d.ts.map +1 -0
  115. package/dist/mcp/index.js +8 -0
  116. package/dist/mcp/index.js.map +1 -0
  117. package/dist/mcp/mcp-client-manager.d.ts +72 -0
  118. package/dist/mcp/mcp-client-manager.d.ts.map +1 -0
  119. package/dist/mcp/mcp-client-manager.js +235 -0
  120. package/dist/mcp/mcp-client-manager.js.map +1 -0
  121. package/dist/mcp/mcp-types.d.ts +58 -0
  122. package/dist/mcp/mcp-types.d.ts.map +1 -0
  123. package/dist/mcp/mcp-types.js +20 -0
  124. package/dist/mcp/mcp-types.js.map +1 -0
  125. package/dist/memory/index.d.ts +3 -0
  126. package/dist/memory/index.d.ts.map +1 -0
  127. package/dist/memory/index.js +6 -0
  128. package/dist/memory/index.js.map +1 -0
  129. package/dist/memory/memory-manager.d.ts +119 -0
  130. package/dist/memory/memory-manager.d.ts.map +1 -0
  131. package/dist/memory/memory-manager.js +334 -0
  132. package/dist/memory/memory-manager.js.map +1 -0
  133. package/dist/messages/types.d.ts +2 -0
  134. package/dist/messages/types.d.ts.map +1 -1
  135. package/dist/orchestrator/index.d.ts +5 -0
  136. package/dist/orchestrator/index.d.ts.map +1 -0
  137. package/dist/orchestrator/index.js +13 -0
  138. package/dist/orchestrator/index.js.map +1 -0
  139. package/dist/orchestrator/json-extractor.d.ts +18 -0
  140. package/dist/orchestrator/json-extractor.d.ts.map +1 -0
  141. package/dist/orchestrator/json-extractor.js +111 -0
  142. package/dist/orchestrator/json-extractor.js.map +1 -0
  143. package/dist/orchestrator/orchestrator-agent.d.ts +152 -0
  144. package/dist/orchestrator/orchestrator-agent.d.ts.map +1 -0
  145. package/dist/orchestrator/orchestrator-agent.js +675 -0
  146. package/dist/orchestrator/orchestrator-agent.js.map +1 -0
  147. package/dist/orchestrator/orchestrator-response.d.ts +40 -0
  148. package/dist/orchestrator/orchestrator-response.d.ts.map +1 -0
  149. package/dist/orchestrator/orchestrator-response.js +275 -0
  150. package/dist/orchestrator/orchestrator-response.js.map +1 -0
  151. package/dist/orchestrator/orchestrator-types.d.ts +116 -0
  152. package/dist/orchestrator/orchestrator-types.d.ts.map +1 -0
  153. package/dist/orchestrator/orchestrator-types.js +3 -0
  154. package/dist/orchestrator/orchestrator-types.js.map +1 -0
  155. package/dist/preferences/preference-manager.d.ts +8 -3
  156. package/dist/preferences/preference-manager.d.ts.map +1 -1
  157. package/dist/preferences/preference-manager.js +17 -4
  158. package/dist/preferences/preference-manager.js.map +1 -1
  159. package/dist/rag/chroma-store.d.ts +52 -0
  160. package/dist/rag/chroma-store.d.ts.map +1 -0
  161. package/dist/rag/chroma-store.js +110 -0
  162. package/dist/rag/chroma-store.js.map +1 -0
  163. package/dist/rag/document-loader.d.ts +21 -0
  164. package/dist/rag/document-loader.d.ts.map +1 -0
  165. package/dist/rag/document-loader.js +129 -0
  166. package/dist/rag/document-loader.js.map +1 -0
  167. package/dist/rag/embedding-provider.d.ts +36 -0
  168. package/dist/rag/embedding-provider.d.ts.map +1 -0
  169. package/dist/rag/embedding-provider.js +74 -0
  170. package/dist/rag/embedding-provider.js.map +1 -0
  171. package/dist/rag/index.d.ts +17 -0
  172. package/dist/rag/index.d.ts.map +1 -0
  173. package/dist/rag/index.js +27 -0
  174. package/dist/rag/index.js.map +1 -0
  175. package/dist/rag/keyword-index.d.ts +53 -0
  176. package/dist/rag/keyword-index.d.ts.map +1 -0
  177. package/dist/rag/keyword-index.js +161 -0
  178. package/dist/rag/keyword-index.js.map +1 -0
  179. package/dist/rag/llm-reranker.d.ts +36 -0
  180. package/dist/rag/llm-reranker.d.ts.map +1 -0
  181. package/dist/rag/llm-reranker.js +95 -0
  182. package/dist/rag/llm-reranker.js.map +1 -0
  183. package/dist/rag/rag-manager.d.ts +54 -0
  184. package/dist/rag/rag-manager.d.ts.map +1 -0
  185. package/dist/rag/rag-manager.js +179 -0
  186. package/dist/rag/rag-manager.js.map +1 -0
  187. package/dist/rag/rag-types.d.ts +143 -0
  188. package/dist/rag/rag-types.d.ts.map +1 -0
  189. package/dist/rag/rag-types.js +9 -0
  190. package/dist/rag/rag-types.js.map +1 -0
  191. package/dist/rag/rrf.d.ts +47 -0
  192. package/dist/rag/rrf.d.ts.map +1 -0
  193. package/dist/rag/rrf.js +70 -0
  194. package/dist/rag/rrf.js.map +1 -0
  195. package/dist/rag/search-knowledge.d.ts +24 -0
  196. package/dist/rag/search-knowledge.d.ts.map +1 -0
  197. package/dist/rag/search-knowledge.js +86 -0
  198. package/dist/rag/search-knowledge.js.map +1 -0
  199. package/dist/rag/text-splitter.d.ts +25 -0
  200. package/dist/rag/text-splitter.d.ts.map +1 -0
  201. package/dist/rag/text-splitter.js +136 -0
  202. package/dist/rag/text-splitter.js.map +1 -0
  203. package/dist/rag/vector-store.d.ts +34 -0
  204. package/dist/rag/vector-store.d.ts.map +1 -0
  205. package/dist/rag/vector-store.js +73 -0
  206. package/dist/rag/vector-store.js.map +1 -0
  207. package/dist/reflection/error-notebook.d.ts +125 -0
  208. package/dist/reflection/error-notebook.d.ts.map +1 -0
  209. package/dist/reflection/error-notebook.js +368 -0
  210. package/dist/reflection/error-notebook.js.map +1 -0
  211. package/dist/reflection/index.d.ts +8 -0
  212. package/dist/reflection/index.d.ts.map +1 -0
  213. package/dist/reflection/index.js +12 -0
  214. package/dist/reflection/index.js.map +1 -0
  215. package/dist/reflection/memory-reflector.d.ts +97 -0
  216. package/dist/reflection/memory-reflector.d.ts.map +1 -0
  217. package/dist/reflection/memory-reflector.js +215 -0
  218. package/dist/reflection/memory-reflector.js.map +1 -0
  219. package/dist/reflection/reflection-agent.d.ts +105 -0
  220. package/dist/reflection/reflection-agent.d.ts.map +1 -0
  221. package/dist/reflection/reflection-agent.js +234 -0
  222. package/dist/reflection/reflection-agent.js.map +1 -0
  223. package/dist/reflection/reflection-hook.d.ts +50 -0
  224. package/dist/reflection/reflection-hook.d.ts.map +1 -0
  225. package/dist/reflection/reflection-hook.js +108 -0
  226. package/dist/reflection/reflection-hook.js.map +1 -0
  227. package/dist/rules/project-rules.d.ts +47 -0
  228. package/dist/rules/project-rules.d.ts.map +1 -0
  229. package/dist/rules/project-rules.js +166 -0
  230. package/dist/rules/project-rules.js.map +1 -0
  231. package/dist/security/boundaries.d.ts +81 -0
  232. package/dist/security/boundaries.d.ts.map +1 -0
  233. package/dist/security/boundaries.js +158 -0
  234. package/dist/security/boundaries.js.map +1 -0
  235. package/dist/security/index.d.ts +2 -0
  236. package/dist/security/index.d.ts.map +1 -0
  237. package/dist/security/index.js +11 -0
  238. package/dist/security/index.js.map +1 -0
  239. package/dist/session/session-types.d.ts +25 -4
  240. package/dist/session/session-types.d.ts.map +1 -1
  241. package/dist/skills/file-skill-loader.d.ts +9 -20
  242. package/dist/skills/file-skill-loader.d.ts.map +1 -1
  243. package/dist/skills/file-skill-loader.js +35 -164
  244. package/dist/skills/file-skill-loader.js.map +1 -1
  245. package/dist/skills/index.d.ts +1 -1
  246. package/dist/skills/index.d.ts.map +1 -1
  247. package/dist/skills/index.js +1 -2
  248. package/dist/skills/index.js.map +1 -1
  249. package/dist/skills/skill-manager.d.ts +22 -29
  250. package/dist/skills/skill-manager.d.ts.map +1 -1
  251. package/dist/skills/skill-manager.js +63 -85
  252. package/dist/skills/skill-manager.js.map +1 -1
  253. package/dist/skills/types.d.ts +4 -16
  254. package/dist/skills/types.d.ts.map +1 -1
  255. package/dist/subagent/index.d.ts +4 -0
  256. package/dist/subagent/index.d.ts.map +1 -0
  257. package/dist/subagent/index.js +8 -0
  258. package/dist/subagent/index.js.map +1 -0
  259. package/dist/subagent/subagent-loader.d.ts +53 -0
  260. package/dist/subagent/subagent-loader.d.ts.map +1 -0
  261. package/dist/subagent/subagent-loader.js +155 -0
  262. package/dist/subagent/subagent-loader.js.map +1 -0
  263. package/dist/subagent/subagent-manager.d.ts +161 -0
  264. package/dist/subagent/subagent-manager.d.ts.map +1 -0
  265. package/dist/subagent/subagent-manager.js +468 -0
  266. package/dist/subagent/subagent-manager.js.map +1 -0
  267. package/dist/subagent/subagent-types.d.ts +77 -0
  268. package/dist/subagent/subagent-types.d.ts.map +1 -0
  269. package/dist/subagent/subagent-types.js +3 -0
  270. package/dist/subagent/subagent-types.js.map +1 -0
  271. package/dist/tools/builtin/bash.d.ts +3 -0
  272. package/dist/tools/builtin/bash.d.ts.map +1 -0
  273. package/dist/tools/builtin/bash.js +87 -0
  274. package/dist/tools/builtin/bash.js.map +1 -0
  275. package/dist/tools/builtin/edit-file.d.ts.map +1 -1
  276. package/dist/tools/builtin/edit-file.js +1 -0
  277. package/dist/tools/builtin/edit-file.js.map +1 -1
  278. package/dist/tools/builtin/index.d.ts +14 -0
  279. package/dist/tools/builtin/index.d.ts.map +1 -1
  280. package/dist/tools/builtin/index.js +45 -1
  281. package/dist/tools/builtin/index.js.map +1 -1
  282. package/dist/tools/builtin/list-errors.d.ts +7 -0
  283. package/dist/tools/builtin/list-errors.d.ts.map +1 -0
  284. package/dist/tools/builtin/list-errors.js +64 -0
  285. package/dist/tools/builtin/list-errors.js.map +1 -0
  286. package/dist/tools/builtin/list-subagents.d.ts +7 -0
  287. package/dist/tools/builtin/list-subagents.d.ts.map +1 -0
  288. package/dist/tools/builtin/list-subagents.js +21 -0
  289. package/dist/tools/builtin/list-subagents.js.map +1 -0
  290. package/dist/tools/builtin/recall.d.ts +11 -0
  291. package/dist/tools/builtin/recall.d.ts.map +1 -0
  292. package/dist/tools/builtin/recall.js +60 -0
  293. package/dist/tools/builtin/recall.js.map +1 -0
  294. package/dist/tools/builtin/remember.d.ts +12 -0
  295. package/dist/tools/builtin/remember.d.ts.map +1 -0
  296. package/dist/tools/builtin/remember.js +72 -0
  297. package/dist/tools/builtin/remember.js.map +1 -0
  298. package/dist/tools/builtin/skill.d.ts +14 -0
  299. package/dist/tools/builtin/skill.d.ts.map +1 -0
  300. package/dist/tools/builtin/skill.js +71 -0
  301. package/dist/tools/builtin/skill.js.map +1 -0
  302. package/dist/tools/builtin/spawn-subagent.d.ts +7 -0
  303. package/dist/tools/builtin/spawn-subagent.d.ts.map +1 -0
  304. package/dist/tools/builtin/spawn-subagent.js +43 -0
  305. package/dist/tools/builtin/spawn-subagent.js.map +1 -0
  306. package/dist/tools/builtin/web-fetch.d.ts +3 -0
  307. package/dist/tools/builtin/web-fetch.d.ts.map +1 -0
  308. package/dist/tools/builtin/web-fetch.js +101 -0
  309. package/dist/tools/builtin/web-fetch.js.map +1 -0
  310. package/dist/tools/builtin/write-file.d.ts.map +1 -1
  311. package/dist/tools/builtin/write-file.js +1 -0
  312. package/dist/tools/builtin/write-file.js.map +1 -1
  313. package/dist/tools/circuit-breaker.d.ts +19 -10
  314. package/dist/tools/circuit-breaker.d.ts.map +1 -1
  315. package/dist/tools/circuit-breaker.js +22 -11
  316. package/dist/tools/circuit-breaker.js.map +1 -1
  317. package/dist/tools/error-tracker.d.ts +28 -44
  318. package/dist/tools/error-tracker.d.ts.map +1 -1
  319. package/dist/tools/error-tracker.js +39 -156
  320. package/dist/tools/error-tracker.js.map +1 -1
  321. package/dist/tools/tool-filter.d.ts +70 -0
  322. package/dist/tools/tool-filter.d.ts.map +1 -0
  323. package/dist/tools/tool-filter.js +92 -0
  324. package/dist/tools/tool-filter.js.map +1 -0
  325. package/dist/tools/tool-output-truncator.d.ts +36 -0
  326. package/dist/tools/tool-output-truncator.d.ts.map +1 -0
  327. package/dist/tools/tool-output-truncator.js +117 -0
  328. package/dist/tools/tool-output-truncator.js.map +1 -0
  329. package/dist/tools/tool-registry.d.ts +25 -9
  330. package/dist/tools/tool-registry.d.ts.map +1 -1
  331. package/dist/tools/tool-registry.js +77 -28
  332. package/dist/tools/tool-registry.js.map +1 -1
  333. package/dist/tools/tool-validator.d.ts +13 -0
  334. package/dist/tools/tool-validator.d.ts.map +1 -0
  335. package/dist/tools/tool-validator.js +116 -0
  336. package/dist/tools/tool-validator.js.map +1 -0
  337. package/dist/tools/types.d.ts +86 -3
  338. package/dist/tools/types.d.ts.map +1 -1
  339. package/dist/tools/types.js +51 -2
  340. package/dist/tools/types.js.map +1 -1
  341. package/dist/trace/trace-logger.d.ts +30 -4
  342. package/dist/trace/trace-logger.d.ts.map +1 -1
  343. package/dist/trace/trace-logger.js +83 -7
  344. package/dist/trace/trace-logger.js.map +1 -1
  345. package/package.json +14 -4
  346. package/dist/compression/sliding-window.d.ts +0 -21
  347. package/dist/compression/sliding-window.d.ts.map +0 -1
  348. package/dist/compression/sliding-window.js +0 -44
  349. package/dist/compression/sliding-window.js.map +0 -1
package/LICENSE CHANGED
@@ -1,21 +1,68 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 kagent-ts
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ Business Source License 1.1
2
+
3
+ License text copyright © 2017 MariaDB Corporation Ab, All Rights Reserved.
4
+ "Business Source License" is a trademark of MariaDB Corporation Ab.
5
+
6
+ Parameters
7
+
8
+ Licensor: kagent-ts
9
+
10
+ Licensed Work: kagent-ts A TypeScript agent framework.
11
+ The Licensed Work is (c) 2026 kagent-ts.
12
+
13
+ Change Date: 2030-06-26
14
+
15
+ Change License: MIT License
16
+
17
+ For information about the Change License and the Change Date, see the FAQ
18
+ below: https://mariadb.com/bsl11/faq/
19
+
20
+ -----------------------------------------------------------------------------
21
+
22
+ Terms
23
+
24
+ The Licensor hereby grants you the right to copy, modify, create derivative
25
+ works, redistribute, and make non-production use of the Licensed Work. The
26
+ Licensor may make an Additional Use Grant, above, permitting limited
27
+ production use.
28
+
29
+ Effective on the Change Date, or the fourth anniversary of the first publicly
30
+ available distribution of a specific version of the Licensed Work under this
31
+ License, whichever comes first, the Licensor hereby grants you rights under
32
+ the terms of the Change License, and the rights granted in the paragraph
33
+ above terminate.
34
+
35
+ If your use of the Licensed Work does not comply with the requirements
36
+ currently in effect as described in this License, you must purchase a
37
+ commercial license from the Licensor, its affiliated entities, or authorized
38
+ resellers, or you must refrain from using the Licensed Work.
39
+
40
+ All copies of the original and modified Licensed Work, and derivative works
41
+ of the Licensed Work, are subject to this License. This License applies
42
+ separately for each version of the Licensed Work and the Change Date may vary
43
+ for each version of the Licensed Work released by Licensor.
44
+
45
+ You must conspicuously display this License on each original or modified copy
46
+ of the Licensed Work. If you receive the Licensed Work in original or
47
+ modified form from a third party, the terms and conditions set forth in this
48
+ License apply to your use of that work.
49
+
50
+ Any use of the Licensed Work in violation of this License will automatically
51
+ terminate your rights under this License for the current and all other
52
+ versions of the Licensed Work.
53
+
54
+ This License does not grant you any right in any trademark or logo of
55
+ Licensor or its affiliates (provided that you may use a trademark or logo of
56
+ Licensor as expressly required by this License).
57
+
58
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
59
+ AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
60
+ EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
61
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
62
+ TITLE.
63
+
64
+ MariaDB hereby grants you permission to use this License's text to license
65
+ your works, and to refer to it using the trademark "Business Source License",
66
+ as long as you comply with the Covenants of Licensor linked below.
67
+
68
+ Covenants of Licensor: https://mariadb.com/bsl11/covenants/
package/README.md CHANGED
@@ -1,395 +1,51 @@
1
- # KAgent-TS
1
+ # kagent-ts
2
2
 
3
- A TypeScript agent framework for building LLM-powered applications with structured agent loops, tool management, session persistence, and user preference injection.
3
+ 一个 TypeScript AI Agent 框架,提供 ReAct / Plan-Solve / Fusion / Orchestrator 多种 Agent 循环范式,内置工具管理(Circuit Breaker)、会话持久化、渐进式 Skill 系统、MCP 协议支持、RAG 知识检索(混合检索 + Re-rank)、Reflection 反思与 Eval 评估。
4
4
 
5
- ## Features
6
-
7
- - **Agent Loop Paradigms** — Base `Agent` + `ReActAgent` (Thought → Action → Observation → Final) + `PlanSolveAgent` (Plan → Resolve → Revise → Final)
8
- - **LLM Integration** — OpenAI provider with automatic retry (exponential backoff + jitter) and network error classification
9
- - **Tool System** — `ToolRegistry` with circuit breaker (automatic disable after threshold) and structured error tracking
10
- - **Context Management** — Automatic token tracking, threshold-based compression with sliding window
11
- - **Session Persistence** — Checkpoint-and-resume: auto-save on network error, graceful discard on abort (SIGINT)
12
- - **User Preferences** — Plain-text Markdown file (`key: value`), injected into system prompt, auto-reloaded on file change
13
- - **Skills** — Progressive disclosure: skills auto-detect from user input and load on demand
14
- - **Built-in Tools** — Read file, write file, edit file, grep search, glob search
15
-
16
- ## Installation
5
+ ## 安装
17
6
 
18
7
  ```bash
19
8
  npm install kagent-ts
20
9
  ```
21
10
 
22
- ## Quick Start
11
+ ## 快速开始
23
12
 
24
- ```typescript
25
- import { ReActAgent, OpenAIProvider, Tool } from "kagent-ts";
13
+ ```ts
14
+ import { ReActAgent, createLLMProvider } from "kagent-ts"
26
15
 
27
- // 1. Create an LLM provider
28
- const llm = new OpenAIProvider({
16
+ const llm = createLLMProvider({
29
17
  apiKey: process.env.OPENAI_API_KEY!,
30
18
  model: "gpt-4o",
31
- });
32
-
33
- // 2. Define a tool
34
- const calculator: Tool = {
35
- name: "calculator",
36
- description: "Perform a mathematical calculation",
37
- parameters: {
38
- type: "object",
39
- properties: {
40
- expression: {
41
- type: "string",
42
- description: "The mathematical expression to evaluate",
43
- },
44
- },
45
- required: ["expression"],
46
- },
47
- async execute(args) {
48
- const { expression } = args as { expression: string };
49
- return String(eval(expression));
50
- },
51
- };
52
-
53
- // 3. Create the agent
54
- const agent = new ReActAgent({ llm, tools: [calculator] });
55
-
56
- // 4. Run
57
- const response = await agent.run("What is 25 * 4 + 10?");
58
- console.log(response);
59
- ```
60
-
61
- ## Architecture
62
-
63
- ```
64
- src/
65
- ├── core/ # Agent classes: Agent, ReActAgent, PlanSolveAgent
66
- ├── llm/ # LLM provider interface + OpenAI implementation
67
- ├── messages/ # Message types and builder class
68
- ├── context/ # Context window management (token tracking)
69
- ├── compression/ # Compression strategies (sliding window)
70
- ├── session/ # Session checkpoint persistence & resume
71
- ├── preferences/ # User preferences (Markdown file, auto-reload)
72
- ├── skills/ # Progressive disclosure skill system
73
- ├── tools/ # Tool registry, circuit breaker, error tracker
74
- │ └── builtin/ # Built-in file tools (read, write, edit, grep, glob)
75
- ├── utils/ # Token counting utilities
76
- └── index.ts # Public API exports
77
- ```
78
-
79
- ## Agent Paradigms
80
-
81
- ### ReActAgent
82
-
83
- The classic Thought → Action → Observation loop with tool-call support:
84
-
85
- ```typescript
86
- import { ReActAgent } from "kagent-ts";
19
+ })
87
20
 
88
21
  const agent = new ReActAgent({
89
22
  llm,
90
- tools: [myTool],
91
- systemPrompt: "You are a helpful assistant.",
23
+ tools: [],
92
24
  maxIterations: 10,
93
- });
94
- const response = await agent.run("Search for the latest news.");
95
- ```
96
-
97
- ### PlanSolveAgent
98
-
99
- Plan → Resolve → Revise loop for complex multi-step tasks:
100
-
101
- ```typescript
102
- import { PlanSolveAgent } from "kagent-ts";
103
-
104
- const agent = new PlanSolveAgent({
105
- llm,
106
- tools: [searchTool, calculatorTool],
107
- maxIterations: 15,
108
- maxPlanSteps: 12,
109
- replanThreshold: 2, // auto-suggest replan after 2 consecutive failures
110
- });
111
- const response = await agent.run("Analyze Q3 financial data and generate a report.");
112
- ```
113
-
114
- The agent will:
115
- 1. Create a detailed plan
116
- 2. Execute each step with tools
117
- 3. Revise the plan mid-execution if obstacles occur
118
- 4. Deliver the final answer
119
-
120
- ## LLM & Network Resilience
121
-
122
- The OpenAI provider includes built-in retry logic:
123
-
124
- ```typescript
125
- const llm = new OpenAIProvider({
126
- apiKey: process.env.OPENAI_API_KEY!,
127
- model: "gpt-4o",
128
- retry: {
129
- maxRetries: 3,
130
- baseDelayMs: 1000,
131
- maxDelayMs: 30000,
132
- },
133
- });
134
- ```
135
-
136
- - **Retryable errors**: timeout, connection refused/reset, DNS failure, HTTP 429 (rate limit), HTTP 5xx (server error)
137
- - **Permanent errors**: HTTP 401 (auth), HTTP 400 (bad request), abort signal — propagate immediately
138
- - On retry exhaustion → throws `LLMNetworkError` with `cause` field for agent-level handling
139
-
140
- ## Tool System
141
-
142
- ### ToolRegistry + Circuit Breaker
143
-
144
- Tools can be registered with automatic failure detection and circuit breaking:
145
-
146
- ```typescript
147
- import { ToolRegistry } from "kagent-ts";
148
-
149
- const registry = new ToolRegistry({
150
- breakerConfig: {
151
- failureThreshold: 5, // disable after 5 consecutive failures
152
- cooldownMs: 60000, // re-enable after 60s
153
- halfOpenMaxRetries: 2,
154
- },
155
- });
156
-
157
- registry.register(calculatorTool);
158
- const result = await registry.execute("calculator", { expression: "2+2" });
159
- ```
160
-
161
- States: `CLOSED` (normal) → `OPEN` (disabled) → `HALF_OPEN` (probing) → `CLOSED` (recovered).
162
-
163
- ### Error Tracking
164
-
165
- Track full tool failure chains with LLM analysis:
166
-
167
- ```typescript
168
- const report = agent.generateErrorReport();
169
- // Generates a structured markdown report of all tool failures,
170
- // including LLM analysis of root cause and recovery steps.
171
- ```
172
-
173
- ### Built-in Tools
174
-
175
- ```typescript
176
- import { registerAllBuiltinTools, ReadFileTool, WriteFileTool } from "kagent-ts";
177
-
178
- // Register individually
179
- const agent = new ReActAgent({
180
- llm,
181
- tools: [...registerAllBuiltinTools()],
182
- });
183
-
184
- // Or add at runtime
185
- agent.addTool(new ReadFileTool());
186
- agent.addTool(new WriteFileTool());
187
- ```
188
-
189
- Available: `ReadFileTool`, `WriteFileTool`, `EditFileTool`, `GrepSearchTool`, `GlobSearchTool`.
190
-
191
- ## Session Persistence & Network Recovery
192
-
193
- The agent can checkpoint its state mid-run and resume after disconnection:
194
-
195
- ```typescript
196
- const agent = new ReActAgent({
197
- llm,
198
- tools: [myTool],
199
- sessionId: "my-session",
200
- enableCheckpointing: true,
201
- });
202
-
203
- // Normal execution — auto-saves after each LLM+tools cycle.
204
- // On network error: saves "interrupted" checkpoint, returns resume instructions.
205
- const result = await agent.run("Do something...");
206
-
207
- // After network is restored:
208
- const resumed = await agent.resume("my-session", "continue");
209
- ```
210
-
211
- When the user aborts (SIGINT / `agent.cancel()`), the checkpoint is discarded — no stale state persists.
212
-
213
- ## User Preferences
214
-
215
- Preferences are stored as a Markdown file (`.kagent/preferences.md` by default) and injected into the system prompt as a `=== User Preferences ===` section. File changes are auto-detected each loop iteration.
216
-
217
- ```markdown
218
- # User Preferences
219
-
220
- codeStyle: Use TypeScript with functional style. Prefer interfaces.
221
- language: Always respond in Chinese.
222
- forbidden: Never use `any` type. Avoid mutating function parameters.
223
- ```
224
-
225
- ```typescript
226
- // Via constructor
227
- const agent = new ReActAgent({
228
- llm,
229
- tools: [myTool],
230
- preferences: {
231
- codeStyle: "Use TypeScript with functional style.",
232
- language: "Always respond in Chinese.",
233
- },
234
- });
235
-
236
- // With file persistence
237
- import { PreferenceManager } from "kagent-ts";
238
-
239
- const agent = new ReActAgent({
240
- llm,
241
- tools: [myTool],
242
- preferenceManager: new PreferenceManager(),
243
- });
244
-
245
- // Runtime CRUD (auto-persists if PreferenceManager configured)
246
- agent.setPreference("codeStyle", "Use TypeScript with functional style.");
247
- agent.getPreference("language"); // "Always respond in Chinese."
248
- agent.removePreference("forbidden");
249
- agent.clearPreferences();
250
-
251
- // The LLM sees this in every system prompt:
252
- // === User Preferences ===
253
- // - codeStyle: Use TypeScript with functional style.
254
- // - language: Always respond in Chinese.
255
- ```
256
-
257
- ### File Format
258
-
259
- `preferences.md` uses simple `key: value` lines. Lines starting with `#` are comments:
260
-
261
- ```markdown
262
- # User Preferences
263
-
264
- codeStyle: Use TypeScript with functional style.
265
- replyLanguage: Always respond in Chinese.
266
- # This is a comment — ignored when loaded.
267
- ```
268
-
269
- Manually edit the file while the agent is running — changes are auto-detected before the next LLM call.
270
-
271
- ## Skills (Progressive Disclosure)
272
-
273
- Skills provide domain-specific knowledge and tools that load on demand. Skills are defined as file-based directories, making them easy to author and share.
274
-
275
- ### Directory Structure
276
-
277
- ```
278
- skills/
279
- ├── sql/
280
- │ ├── SKILL.md # Frontmatter (metadata) + system prompt body
281
- │ ├── reference/ # Reference docs loaded on activation
282
- │ │ └── cheatsheet.md
283
- │ └── scripts/ # Executable scripts registered as tools
284
- │ └── format_sql.sh
285
- ├── git/
286
- │ ├── SKILL.md
287
- │ └── scripts/
288
- │ └── list_branches.sh
289
- └── ...
290
- ```
291
-
292
- ### SKILL.md Format
293
-
294
- ```markdown
295
- ---
296
- name: sql
297
- description: SQL query writing and optimization
298
- keywords: sql, query, database, select, join
299
- ---
300
-
301
- You are an expert in SQL. Write efficient queries, use appropriate indexes, and consider EXPLAIN plans.
302
- ```
303
-
304
- ### Usage
305
-
306
- Point the agent to your `skills/` directory — skills are auto-discovered and lazily loaded:
307
-
308
- ```typescript
309
- import { ReActAgent, OpenAIProvider } from "kagent-ts";
310
-
311
- const agent = new ReActAgent({
312
- llm: provider,
313
- tools: myTools,
314
- skillsDir: "./skills", // Auto-discover file-based skills
315
- });
316
-
317
- // Manual activation
318
- agent.activateSkill("sql");
319
-
320
- // Or rely on auto-detection: when user input contains matching
321
- // keywords (e.g., "write a SQL query"), the skill activates automatically.
322
- const response = await agent.run("Write a query to find top 10 customers by revenue.");
323
- ```
324
-
325
- ### Skill Components
25
+ })
326
26
 
327
- | Component | Location | Behavior |
328
- |-----------|----------|----------|
329
- | **Metadata** | SKILL.md frontmatter (`---`) | Registered on scan — name, description, keywords |
330
- | **System Prompt** | SKILL.md body | Loaded on activation — injected into the agent's system prompt |
331
- | **Reference Docs** | `reference/*.md`, `*.txt` | Appended to system prompt on activation, with `[Reference: filename]` headers |
332
- | **Scripts** | `scripts/*.sh`, `.py`, `.js`, `.bat` | Registered as executable `Tool` objects on activation, named `{skillName}_{scriptName}` |
333
-
334
- ### Supported Script Types
335
-
336
- | Extension | Interpreter | Platform |
337
- |-----------|-------------|----------|
338
- | `.sh` | `bash` | Linux/macOS/WSL |
339
- | `.bat` / `.cmd` | `cmd.exe /c` | Windows |
340
- | `.ps1` | `powershell.exe -File` | Windows |
341
- | `.js` | `node` | Cross-platform |
342
- | `.py` | `python3` / `python` | Cross-platform |
343
-
344
- Each script becomes a Tool that accepts a single `args: string` parameter, passed as CLI arguments to the script.
345
-
346
- ## Context Management
347
-
348
- Automatic token tracking with configurable thresholds:
349
-
350
- ```typescript
351
- import { ContextManager } from "kagent-ts";
352
-
353
- const ctx = new ContextManager({
354
- maxTokens: 128000,
355
- compressionThresholdRatio: 0.75, // compress at 75% capacity
356
- compressionRatio: 0.5, // remove 50% of messages on compress
357
- });
27
+ const answer = await agent.run("请介绍一下 TypeScript 的特点。")
28
+ console.log(answer)
358
29
  ```
359
30
 
360
- ## Compression
31
+ ## 核心特性
361
32
 
362
- Sliding window strategy keeps the most recent messages:
33
+ - 🧠 **4 Agent 范式** ReAct → Plan-Solve → Fusion → Orchestrator,从简单问答到大规模多代理编排
34
+ - 🔧 **工具系统** — Circuit Breaker 熔断、JSON Schema 参数校验、HITL 审批、错误追踪链
35
+ - 🔌 **多 LLM 后端** — OpenAI / Anthropic,Fallback 降级、Rate Limiter 限流、Model Router 路由
36
+ - 💾 **会话持久化** — 自动 Checkpoint,支持网络中断恢复和取消续跑
37
+ - 📦 **渐进式 Skill** — 基于 SKILL.md 文件,按需激活,Token 友好
38
+ - 🌐 **MCP 协议** — 动态发现外部工具,支持 stdio / SSE 传输
39
+ - 📚 **RAG 知识库** — 混合检索(BM25 + 向量 + RRF 融合)、Chroma/Milvus 等向量数据库、Re-rank 精排
40
+ - 🔍 **反思与评估** — Reflection + ErrorNotebook + EvalRunner + Benchmark
41
+ - 🛡️ **安全防护** — 多层 Prompt Injection 防御
363
42
 
364
- ```typescript
365
- import { SlidingWindowCompression } from "kagent-ts";
43
+ ## 文档
366
44
 
367
- const compressor = new SlidingWindowCompression({
368
- keepLastN: 20,
369
- keepSystemMessages: true,
370
- });
45
+ 完整文档请访问:**[https://kkhhhh-ll.github.io/kagent-ts](https://kkhhhh-ll.github.io/kagent-ts)**
371
46
 
372
- const result = compressor.compress(messages, systemPrompt);
373
- // result.messages — compressed list
374
- // result.removedCount — how many were removed
375
- ```
376
-
377
- ## Message API
378
-
379
- ```typescript
380
- import { Message } from "kagent-ts";
381
-
382
- Message.user("Hello");
383
- Message.system("You are a helpful assistant.");
384
- Message.assistant("Hi there!");
385
- Message.tool("Result", "call_123", "calculator");
47
+ 本地运行文档:
386
48
 
387
- msg.toDict(); // { role: "user", content: "Hello" }
388
- msg.toJSON(); // JSON string
389
- Message.fromJSON(json); // Deserialize
390
- Message.fromJSONBulk(array); // Deserialize array
49
+ ```bash
50
+ npm run docs:dev
391
51
  ```
392
-
393
- ## License
394
-
395
- MIT
@@ -0,0 +1,66 @@
1
+ import { MessageData } from "../messages/types";
2
+ import { LLMProvider } from "../llm/interface";
3
+ import { Logger } from "../logging/logger";
4
+ interface CompressionConfig {
5
+ maxTokens: number;
6
+ compressionThreshold: number;
7
+ keepTurns: number;
8
+ toolResultMaxAgeMs: number;
9
+ }
10
+ /**
11
+ * Progressive 4-step compression.
12
+ *
13
+ * Each step is applied in order. After each step the token count is
14
+ * re-checked; if the context now fits comfortably, later steps are skipped.
15
+ */
16
+ export declare class ProgressiveCompressor {
17
+ private config;
18
+ private logger;
19
+ constructor(config: CompressionConfig, logger?: Logger);
20
+ /**
21
+ * Run progressive compression.
22
+ *
23
+ * @param messages The full message list (without system message).
24
+ * @param systemMessage The system message (preserved).
25
+ * @param llm Optional LLM provider for Step 4 summarization.
26
+ * If omitted, Step 4 is skipped.
27
+ * @returns Compressed message list + removal count.
28
+ */
29
+ compress(messages: MessageData[], systemMessage: MessageData | null, llm?: LLMProvider, model?: string): Promise<{
30
+ messages: MessageData[];
31
+ removedCount: number;
32
+ applied: boolean;
33
+ }>;
34
+ private finalize;
35
+ private tokenCount;
36
+ /**
37
+ * If total tool-result bytes exceed 200 KB, truncate the largest
38
+ * results (keep 2 KB + save to disk). Returns a new array if modified.
39
+ */
40
+ private step1TruncateToolResults;
41
+ /**
42
+ * Remove messages older than `keepTurns` conversation turns.
43
+ * A "turn" is a user message + all subsequent assistant/tool messages
44
+ * until the next user message.
45
+ */
46
+ private step2DropOldTurns;
47
+ /**
48
+ * Remove tool results older than `toolResultMaxAgeMs` for read-type
49
+ * tools (results that can be reproduced by re-running the tool).
50
+ * Sub-agent results (`<subagent-result>`) are preserved.
51
+ */
52
+ private step3DropStaleToolResults;
53
+ /**
54
+ * Generate a structured summary of ALL messages via the LLM.
55
+ *
56
+ * The entire conversation (from the first user message onward) is
57
+ * compressed into a single summary. No recent turns are kept verbatim —
58
+ * the summary is the sole source of history after compression.
59
+ *
60
+ * A continuity hint is appended so the LLM knows it is resuming, not
61
+ * starting from scratch.
62
+ */
63
+ private step4LlmSummarize;
64
+ }
65
+ export {};
66
+ //# sourceMappingURL=progressive-compressor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"progressive-compressor.d.ts","sourceRoot":"","sources":["../../src/compression/progressive-compressor.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAQ,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAiB,MAAM,mBAAmB,CAAC;AAe1D,UAAU,iBAAiB;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAID;;;;;GAKG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,MAAM,CAAS;gBAEX,MAAM,EAAE,iBAAiB,EAAE,MAAM,CAAC,EAAE,MAAM;IAKtD;;;;;;;;OAQG;IACG,QAAQ,CACZ,QAAQ,EAAE,WAAW,EAAE,EACvB,aAAa,EAAE,WAAW,GAAG,IAAI,EACjC,GAAG,CAAC,EAAE,WAAW,EACjB,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC;QAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;IAkD/E,OAAO,CAAC,QAAQ;IAchB,OAAO,CAAC,UAAU;IAWlB;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IAsDhC;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAkBzB;;;;OAIG;IACH,OAAO,CAAC,yBAAyB;IA8BjC;;;;;;;;;OASG;YACW,iBAAiB;CA6ChC"}