@illuma-ai/agents 1.4.0-alpha.6 → 1.5.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 (653) hide show
  1. package/README.md +62 -0
  2. package/dist/cjs/agents/AgentContext.cjs +274 -67
  3. package/dist/cjs/agents/AgentContext.cjs.map +1 -1
  4. package/dist/cjs/common/enum.cjs +44 -13
  5. package/dist/cjs/common/enum.cjs.map +1 -1
  6. package/dist/cjs/graphs/Graph.cjs +182 -5
  7. package/dist/cjs/graphs/Graph.cjs.map +1 -1
  8. package/dist/cjs/graphs/MultiAgentGraph.cjs +152 -1167
  9. package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
  10. package/dist/cjs/graphs/phases/memoryFlushPhase.cjs +1 -1
  11. package/dist/cjs/graphs/phases/memoryFlushPhase.cjs.map +1 -1
  12. package/dist/cjs/hooks/HookRegistry.cjs +162 -0
  13. package/dist/cjs/hooks/HookRegistry.cjs.map +1 -0
  14. package/dist/cjs/hooks/executeHooks.cjs +276 -0
  15. package/dist/cjs/hooks/executeHooks.cjs.map +1 -0
  16. package/dist/cjs/hooks/matchers.cjs +256 -0
  17. package/dist/cjs/hooks/matchers.cjs.map +1 -0
  18. package/dist/cjs/hooks/types.cjs +27 -0
  19. package/dist/cjs/hooks/types.cjs.map +1 -0
  20. package/dist/cjs/langchain/google-common.cjs +3 -0
  21. package/dist/cjs/langchain/google-common.cjs.map +1 -0
  22. package/dist/cjs/langchain/index.cjs +86 -0
  23. package/dist/cjs/langchain/index.cjs.map +1 -0
  24. package/dist/cjs/langchain/language_models/chat_models.cjs +3 -0
  25. package/dist/cjs/langchain/language_models/chat_models.cjs.map +1 -0
  26. package/dist/cjs/langchain/messages/tool.cjs +3 -0
  27. package/dist/cjs/langchain/messages/tool.cjs.map +1 -0
  28. package/dist/cjs/langchain/messages.cjs +51 -0
  29. package/dist/cjs/langchain/messages.cjs.map +1 -0
  30. package/dist/cjs/langchain/openai.cjs +3 -0
  31. package/dist/cjs/langchain/openai.cjs.map +1 -0
  32. package/dist/cjs/langchain/prompts.cjs +11 -0
  33. package/dist/cjs/langchain/prompts.cjs.map +1 -0
  34. package/dist/cjs/langchain/runnables.cjs +19 -0
  35. package/dist/cjs/langchain/runnables.cjs.map +1 -0
  36. package/dist/cjs/langchain/tools.cjs +23 -0
  37. package/dist/cjs/langchain/tools.cjs.map +1 -0
  38. package/dist/cjs/langchain/utils/env.cjs +11 -0
  39. package/dist/cjs/langchain/utils/env.cjs.map +1 -0
  40. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs +5 -1
  41. package/dist/cjs/llm/anthropic/utils/message_inputs.cjs.map +1 -1
  42. package/dist/cjs/llm/bedrock/cacheSupport.cjs +55 -0
  43. package/dist/cjs/llm/bedrock/cacheSupport.cjs.map +1 -0
  44. package/dist/cjs/llm/bedrock/index.cjs +61 -33
  45. package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
  46. package/dist/cjs/llm/openai/index.cjs +1 -4
  47. package/dist/cjs/llm/openai/index.cjs.map +1 -1
  48. package/dist/cjs/llm/openai/utils/index.cjs +27 -10
  49. package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
  50. package/dist/cjs/main.cjs +178 -127
  51. package/dist/cjs/main.cjs.map +1 -1
  52. package/dist/cjs/memory/citations.cjs +4 -4
  53. package/dist/cjs/memory/citations.cjs.map +1 -1
  54. package/dist/cjs/memory/constants.cjs +17 -17
  55. package/dist/cjs/memory/constants.cjs.map +1 -1
  56. package/dist/cjs/memory/mmr.cjs +1 -1
  57. package/dist/cjs/memory/mmr.cjs.map +1 -1
  58. package/dist/cjs/memory/paths.cjs +1 -1
  59. package/dist/cjs/memory/paths.cjs.map +1 -1
  60. package/dist/cjs/memory/recallTracking.cjs +3 -3
  61. package/dist/cjs/memory/recallTracking.cjs.map +1 -1
  62. package/dist/cjs/memory/temporalDecay.cjs +2 -2
  63. package/dist/cjs/memory/temporalDecay.cjs.map +1 -1
  64. package/dist/cjs/messages/cache.cjs +89 -0
  65. package/dist/cjs/messages/cache.cjs.map +1 -1
  66. package/dist/cjs/messages/contextPruning.cjs +156 -0
  67. package/dist/cjs/messages/contextPruning.cjs.map +1 -0
  68. package/dist/cjs/messages/contextPruningSettings.cjs +53 -0
  69. package/dist/cjs/messages/contextPruningSettings.cjs.map +1 -0
  70. package/dist/cjs/messages/format.cjs +144 -20
  71. package/dist/cjs/messages/format.cjs.map +1 -1
  72. package/dist/cjs/messages/prune.cjs +505 -4
  73. package/dist/cjs/messages/prune.cjs.map +1 -1
  74. package/dist/cjs/run.cjs +141 -1
  75. package/dist/cjs/run.cjs.map +1 -1
  76. package/dist/cjs/tools/BashExecutor.cjs +235 -0
  77. package/dist/cjs/tools/BashExecutor.cjs.map +1 -0
  78. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs +297 -0
  79. package/dist/cjs/tools/BashProgrammaticToolCalling.cjs.map +1 -0
  80. package/dist/cjs/tools/CodeExecutor.cjs +45 -47
  81. package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
  82. package/dist/cjs/tools/ProgrammaticToolCalling.cjs +16 -11
  83. package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -1
  84. package/dist/cjs/tools/ReadFile.cjs +44 -0
  85. package/dist/cjs/tools/ReadFile.cjs.map +1 -0
  86. package/dist/cjs/tools/SkillTool.cjs +51 -0
  87. package/dist/cjs/tools/SkillTool.cjs.map +1 -0
  88. package/dist/cjs/tools/SubagentTool.cjs +93 -0
  89. package/dist/cjs/tools/SubagentTool.cjs.map +1 -0
  90. package/dist/cjs/tools/ToolNode.cjs +450 -24
  91. package/dist/cjs/tools/ToolNode.cjs.map +1 -1
  92. package/dist/cjs/tools/memory/memoryAppendTool.cjs +1 -1
  93. package/dist/cjs/tools/memory/memoryAppendTool.cjs.map +1 -1
  94. package/dist/cjs/tools/memory/memoryGetTool.cjs +2 -2
  95. package/dist/cjs/tools/memory/memoryGetTool.cjs.map +1 -1
  96. package/dist/cjs/tools/memory/memorySearchTool.cjs +3 -3
  97. package/dist/cjs/tools/memory/memorySearchTool.cjs.map +1 -1
  98. package/dist/cjs/tools/memory/shared.cjs +1 -1
  99. package/dist/cjs/tools/memory/shared.cjs.map +1 -1
  100. package/dist/cjs/tools/search/search.cjs +11 -3
  101. package/dist/cjs/tools/search/search.cjs.map +1 -1
  102. package/dist/cjs/tools/search/tavily-scraper.cjs +189 -0
  103. package/dist/cjs/tools/search/tavily-scraper.cjs.map +1 -0
  104. package/dist/cjs/tools/search/tavily-search.cjs +372 -0
  105. package/dist/cjs/tools/search/tavily-search.cjs.map +1 -0
  106. package/dist/cjs/tools/search/tool.cjs +28 -4
  107. package/dist/cjs/tools/search/tool.cjs.map +1 -1
  108. package/dist/cjs/tools/search/utils.cjs +10 -3
  109. package/dist/cjs/tools/search/utils.cjs.map +1 -1
  110. package/dist/cjs/tools/skillCatalog.cjs +84 -0
  111. package/dist/cjs/tools/skillCatalog.cjs.map +1 -0
  112. package/dist/cjs/tools/subagent/SubagentExecutor.cjs +512 -0
  113. package/dist/cjs/tools/subagent/SubagentExecutor.cjs.map +1 -0
  114. package/dist/cjs/tools/toolOutputReferences.cjs +670 -0
  115. package/dist/cjs/tools/toolOutputReferences.cjs.map +1 -0
  116. package/dist/cjs/types/agent-cache.cjs +54 -0
  117. package/dist/cjs/types/agent-cache.cjs.map +1 -0
  118. package/dist/cjs/types/graph.cjs.map +1 -1
  119. package/dist/cjs/utils/truncation.cjs +135 -0
  120. package/dist/cjs/utils/truncation.cjs.map +1 -0
  121. package/dist/esm/agents/AgentContext.mjs +274 -67
  122. package/dist/esm/agents/AgentContext.mjs.map +1 -1
  123. package/dist/esm/common/enum.mjs +44 -12
  124. package/dist/esm/common/enum.mjs.map +1 -1
  125. package/dist/esm/graphs/Graph.mjs +182 -5
  126. package/dist/esm/graphs/Graph.mjs.map +1 -1
  127. package/dist/esm/graphs/MultiAgentGraph.mjs +155 -1170
  128. package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
  129. package/dist/esm/graphs/phases/memoryFlushPhase.mjs +1 -1
  130. package/dist/esm/graphs/phases/memoryFlushPhase.mjs.map +1 -1
  131. package/dist/esm/hooks/HookRegistry.mjs +160 -0
  132. package/dist/esm/hooks/HookRegistry.mjs.map +1 -0
  133. package/dist/esm/hooks/executeHooks.mjs +273 -0
  134. package/dist/esm/hooks/executeHooks.mjs.map +1 -0
  135. package/dist/esm/hooks/matchers.mjs +251 -0
  136. package/dist/esm/hooks/matchers.mjs.map +1 -0
  137. package/dist/esm/hooks/types.mjs +25 -0
  138. package/dist/esm/hooks/types.mjs.map +1 -0
  139. package/dist/esm/langchain/google-common.mjs +2 -0
  140. package/dist/esm/langchain/google-common.mjs.map +1 -0
  141. package/dist/esm/langchain/index.mjs +5 -0
  142. package/dist/esm/langchain/language_models/chat_models.mjs +2 -0
  143. package/dist/esm/langchain/language_models/chat_models.mjs.map +1 -0
  144. package/dist/esm/langchain/messages/tool.mjs +2 -0
  145. package/dist/esm/langchain/messages/tool.mjs.map +1 -0
  146. package/dist/esm/langchain/messages.mjs +2 -0
  147. package/dist/esm/langchain/messages.mjs.map +1 -0
  148. package/dist/esm/langchain/openai.mjs +2 -0
  149. package/dist/esm/langchain/openai.mjs.map +1 -0
  150. package/dist/esm/langchain/prompts.mjs +2 -0
  151. package/dist/esm/langchain/prompts.mjs.map +1 -0
  152. package/dist/esm/langchain/runnables.mjs +2 -0
  153. package/dist/esm/langchain/runnables.mjs.map +1 -0
  154. package/dist/esm/langchain/tools.mjs +2 -0
  155. package/dist/esm/langchain/tools.mjs.map +1 -0
  156. package/dist/esm/langchain/utils/env.mjs +2 -0
  157. package/dist/esm/langchain/utils/env.mjs.map +1 -0
  158. package/dist/esm/llm/anthropic/utils/message_inputs.mjs +5 -1
  159. package/dist/esm/llm/anthropic/utils/message_inputs.mjs.map +1 -1
  160. package/dist/esm/llm/bedrock/cacheSupport.mjs +52 -0
  161. package/dist/esm/llm/bedrock/cacheSupport.mjs.map +1 -0
  162. package/dist/esm/llm/bedrock/index.mjs +61 -34
  163. package/dist/esm/llm/bedrock/index.mjs.map +1 -1
  164. package/dist/esm/llm/openai/index.mjs +1 -4
  165. package/dist/esm/llm/openai/index.mjs.map +1 -1
  166. package/dist/esm/llm/openai/utils/index.mjs +27 -10
  167. package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
  168. package/dist/esm/main.mjs +21 -27
  169. package/dist/esm/main.mjs.map +1 -1
  170. package/dist/esm/memory/citations.mjs +4 -4
  171. package/dist/esm/memory/citations.mjs.map +1 -1
  172. package/dist/esm/memory/constants.mjs +17 -17
  173. package/dist/esm/memory/constants.mjs.map +1 -1
  174. package/dist/esm/memory/mmr.mjs +1 -1
  175. package/dist/esm/memory/mmr.mjs.map +1 -1
  176. package/dist/esm/memory/paths.mjs +1 -1
  177. package/dist/esm/memory/paths.mjs.map +1 -1
  178. package/dist/esm/memory/recallTracking.mjs +3 -3
  179. package/dist/esm/memory/recallTracking.mjs.map +1 -1
  180. package/dist/esm/memory/temporalDecay.mjs +2 -2
  181. package/dist/esm/memory/temporalDecay.mjs.map +1 -1
  182. package/dist/esm/messages/cache.mjs +89 -0
  183. package/dist/esm/messages/cache.mjs.map +1 -1
  184. package/dist/esm/messages/contextPruning.mjs +154 -0
  185. package/dist/esm/messages/contextPruning.mjs.map +1 -0
  186. package/dist/esm/messages/contextPruningSettings.mjs +50 -0
  187. package/dist/esm/messages/contextPruningSettings.mjs.map +1 -0
  188. package/dist/esm/messages/format.mjs +136 -12
  189. package/dist/esm/messages/format.mjs.map +1 -1
  190. package/dist/esm/messages/prune.mjs +504 -7
  191. package/dist/esm/messages/prune.mjs.map +1 -1
  192. package/dist/esm/run.mjs +141 -1
  193. package/dist/esm/run.mjs.map +1 -1
  194. package/dist/esm/tools/BashExecutor.mjs +227 -0
  195. package/dist/esm/tools/BashExecutor.mjs.map +1 -0
  196. package/dist/esm/tools/BashProgrammaticToolCalling.mjs +288 -0
  197. package/dist/esm/tools/BashProgrammaticToolCalling.mjs.map +1 -0
  198. package/dist/esm/tools/CodeExecutor.mjs +45 -48
  199. package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
  200. package/dist/esm/tools/ProgrammaticToolCalling.mjs +17 -12
  201. package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -1
  202. package/dist/esm/tools/ReadFile.mjs +39 -0
  203. package/dist/esm/tools/ReadFile.mjs.map +1 -0
  204. package/dist/esm/tools/SkillTool.mjs +46 -0
  205. package/dist/esm/tools/SkillTool.mjs.map +1 -0
  206. package/dist/esm/tools/SubagentTool.mjs +86 -0
  207. package/dist/esm/tools/SubagentTool.mjs.map +1 -0
  208. package/dist/esm/tools/ToolNode.mjs +452 -26
  209. package/dist/esm/tools/ToolNode.mjs.map +1 -1
  210. package/dist/esm/tools/memory/memoryAppendTool.mjs +1 -1
  211. package/dist/esm/tools/memory/memoryAppendTool.mjs.map +1 -1
  212. package/dist/esm/tools/memory/memoryGetTool.mjs +2 -2
  213. package/dist/esm/tools/memory/memoryGetTool.mjs.map +1 -1
  214. package/dist/esm/tools/memory/memorySearchTool.mjs +3 -3
  215. package/dist/esm/tools/memory/memorySearchTool.mjs.map +1 -1
  216. package/dist/esm/tools/memory/shared.mjs +1 -1
  217. package/dist/esm/tools/memory/shared.mjs.map +1 -1
  218. package/dist/esm/tools/search/search.mjs +11 -3
  219. package/dist/esm/tools/search/search.mjs.map +1 -1
  220. package/dist/esm/tools/search/tavily-scraper.mjs +186 -0
  221. package/dist/esm/tools/search/tavily-scraper.mjs.map +1 -0
  222. package/dist/esm/tools/search/tavily-search.mjs +370 -0
  223. package/dist/esm/tools/search/tavily-search.mjs.map +1 -0
  224. package/dist/esm/tools/search/tool.mjs +28 -4
  225. package/dist/esm/tools/search/tool.mjs.map +1 -1
  226. package/dist/esm/tools/search/utils.mjs +10 -3
  227. package/dist/esm/tools/search/utils.mjs.map +1 -1
  228. package/dist/esm/tools/skillCatalog.mjs +82 -0
  229. package/dist/esm/tools/skillCatalog.mjs.map +1 -0
  230. package/dist/esm/tools/subagent/SubagentExecutor.mjs +506 -0
  231. package/dist/esm/tools/subagent/SubagentExecutor.mjs.map +1 -0
  232. package/dist/esm/tools/toolOutputReferences.mjs +662 -0
  233. package/dist/esm/tools/toolOutputReferences.mjs.map +1 -0
  234. package/dist/esm/types/agent-cache.mjs +52 -0
  235. package/dist/esm/types/agent-cache.mjs.map +1 -0
  236. package/dist/esm/types/graph.mjs.map +1 -1
  237. package/dist/esm/utils/truncation.mjs +128 -0
  238. package/dist/esm/utils/truncation.mjs.map +1 -0
  239. package/dist/types/agents/AgentContext.d.ts +101 -8
  240. package/dist/types/common/enum.d.ts +39 -12
  241. package/dist/types/common/index.d.ts +0 -1
  242. package/dist/types/graphs/Graph.d.ts +43 -0
  243. package/dist/types/graphs/MultiAgentGraph.d.ts +26 -150
  244. package/dist/types/graphs/index.d.ts +0 -1
  245. package/dist/types/graphs/phases/memoryFlushPhase.d.ts +2 -2
  246. package/dist/types/hooks/HookRegistry.d.ts +56 -0
  247. package/dist/types/hooks/executeHooks.d.ts +79 -0
  248. package/dist/types/hooks/index.d.ts +6 -0
  249. package/dist/types/hooks/matchers.d.ts +95 -0
  250. package/dist/types/hooks/types.d.ts +320 -0
  251. package/dist/types/index.d.ts +9 -9
  252. package/dist/types/langchain/google-common.d.ts +1 -0
  253. package/dist/types/langchain/index.d.ts +8 -0
  254. package/dist/types/langchain/language_models/chat_models.d.ts +1 -0
  255. package/dist/types/langchain/messages/tool.d.ts +1 -0
  256. package/dist/types/langchain/messages.d.ts +2 -0
  257. package/dist/types/langchain/openai.d.ts +1 -0
  258. package/dist/types/langchain/prompts.d.ts +1 -0
  259. package/dist/types/langchain/runnables.d.ts +2 -0
  260. package/dist/types/langchain/tools.d.ts +2 -0
  261. package/dist/types/langchain/utils/env.d.ts +1 -0
  262. package/dist/types/llm/bedrock/cacheSupport.d.ts +35 -0
  263. package/dist/types/llm/bedrock/index.d.ts +54 -1
  264. package/dist/types/llm/openai/index.d.ts +1 -1
  265. package/dist/types/memory/citations.d.ts +4 -4
  266. package/dist/types/memory/constants.d.ts +17 -17
  267. package/dist/types/memory/mmr.d.ts +3 -3
  268. package/dist/types/memory/paths.d.ts +1 -1
  269. package/dist/types/memory/temporalDecay.d.ts +2 -2
  270. package/dist/types/memory/types.d.ts +3 -3
  271. package/dist/types/messages/contextPruning.d.ts +42 -0
  272. package/dist/types/messages/contextPruningSettings.d.ts +44 -0
  273. package/dist/types/messages/format.d.ts +9 -1
  274. package/dist/types/messages/index.d.ts +2 -0
  275. package/dist/types/messages/prune.d.ts +91 -1
  276. package/dist/types/run.d.ts +2 -0
  277. package/dist/types/tools/BashExecutor.d.ts +76 -0
  278. package/dist/types/tools/BashProgrammaticToolCalling.d.ts +72 -0
  279. package/dist/types/tools/CodeExecutor.d.ts +8 -26
  280. package/dist/types/tools/ReadFile.d.ts +28 -0
  281. package/dist/types/tools/SkillTool.d.ts +40 -0
  282. package/dist/types/tools/SubagentTool.d.ts +36 -0
  283. package/dist/types/tools/ToolNode.d.ts +77 -5
  284. package/dist/types/tools/memory/shared.d.ts +1 -1
  285. package/dist/types/tools/search/tavily-scraper.d.ts +19 -0
  286. package/dist/types/tools/search/tavily-search.d.ts +4 -0
  287. package/dist/types/tools/search/types.d.ts +99 -5
  288. package/dist/types/tools/search/utils.d.ts +2 -2
  289. package/dist/types/tools/skillCatalog.d.ts +19 -0
  290. package/dist/types/tools/subagent/SubagentExecutor.d.ts +137 -0
  291. package/dist/types/tools/subagent/index.d.ts +2 -0
  292. package/dist/types/tools/subagent/types.d.ts +84 -0
  293. package/dist/types/tools/toolOutputReferences.d.ts +236 -0
  294. package/dist/types/types/agent-cache.d.ts +71 -0
  295. package/dist/types/types/graph.d.ts +163 -22
  296. package/dist/types/types/index.d.ts +3 -0
  297. package/dist/types/types/messages.d.ts +26 -0
  298. package/dist/types/types/run.d.ts +22 -0
  299. package/dist/types/types/skill.d.ts +9 -0
  300. package/dist/types/types/tools.d.ts +111 -0
  301. package/dist/types/utils/index.d.ts +1 -3
  302. package/dist/types/utils/truncation.d.ts +70 -0
  303. package/package.json +57 -17
  304. package/src/agents/AgentContext.ts +321 -78
  305. package/src/agents/__tests__/AgentContext.cacheTtl.live.test.ts +259 -0
  306. package/src/agents/__tests__/AgentContext.crossAgentTier1.live.test.ts +266 -0
  307. package/src/agents/__tests__/AgentContext.crossUserCache.live.test.ts +342 -0
  308. package/src/agents/__tests__/AgentContext.test.ts +632 -0
  309. package/src/common/__tests__/enum.test.ts +7 -17
  310. package/src/common/enum.ts +43 -12
  311. package/src/common/index.ts +0 -1
  312. package/src/graphs/Graph.ts +222 -2
  313. package/src/graphs/MultiAgentGraph.ts +154 -1466
  314. package/src/graphs/__tests__/MultiAgentGraph.test.ts +91 -0
  315. package/src/graphs/gapFeatures.test.ts +1 -1
  316. package/src/graphs/index.ts +0 -1
  317. package/src/graphs/phases/__tests__/memoryFlushPhase.test.ts +1 -1
  318. package/src/graphs/phases/memoryFlushPhase.ts +2 -2
  319. package/src/hooks/HookRegistry.ts +208 -0
  320. package/src/hooks/__tests__/HookRegistry.test.ts +190 -0
  321. package/src/hooks/__tests__/compactHooks.test.ts +214 -0
  322. package/src/hooks/__tests__/executeHooks.test.ts +1013 -0
  323. package/src/hooks/__tests__/integration.test.ts +337 -0
  324. package/src/hooks/__tests__/matchers.test.ts +238 -0
  325. package/src/hooks/__tests__/toolHooks.test.ts +665 -0
  326. package/src/hooks/executeHooks.ts +375 -0
  327. package/src/hooks/index.ts +57 -0
  328. package/src/hooks/matchers.ts +280 -0
  329. package/src/hooks/types.ts +404 -0
  330. package/src/index.ts +15 -24
  331. package/src/langchain/google-common.ts +1 -0
  332. package/src/langchain/index.ts +8 -0
  333. package/src/langchain/language_models/chat_models.ts +1 -0
  334. package/src/langchain/messages/tool.ts +5 -0
  335. package/src/langchain/messages.ts +21 -0
  336. package/src/langchain/openai.ts +1 -0
  337. package/src/langchain/prompts.ts +1 -0
  338. package/src/langchain/runnables.ts +7 -0
  339. package/src/langchain/tools.ts +8 -0
  340. package/src/langchain/utils/env.ts +1 -0
  341. package/src/llm/anthropic/utils/message_inputs.ts +10 -1
  342. package/src/llm/anthropic/utils/server-tool-inputs.test.ts +436 -0
  343. package/src/llm/bedrock/__tests__/bedrock-caching.test.ts +166 -18
  344. package/src/llm/bedrock/cacheSupport.test.ts +99 -0
  345. package/src/llm/bedrock/cacheSupport.ts +53 -0
  346. package/src/llm/bedrock/index.ts +116 -41
  347. package/src/llm/openai/index.ts +2 -2
  348. package/src/llm/openai/utils/index.ts +31 -14
  349. package/src/memory/citations.ts +4 -4
  350. package/src/memory/constants.ts +17 -17
  351. package/src/memory/mmr.ts +3 -3
  352. package/src/memory/paths.ts +1 -1
  353. package/src/memory/recallTracking.ts +3 -3
  354. package/src/memory/temporalDecay.ts +2 -2
  355. package/src/memory/types.ts +3 -3
  356. package/src/messages/__tests__/contextPruning.test.ts +228 -0
  357. package/src/messages/cache.test.ts +62 -24
  358. package/src/messages/cache.ts +112 -0
  359. package/src/messages/contextPruning.ts +191 -0
  360. package/src/messages/contextPruningSettings.ts +90 -0
  361. package/src/messages/ensureThinkingBlock.test.ts +1 -1
  362. package/src/messages/format.ts +164 -12
  363. package/src/messages/formatAgentMessages.skills.test.ts +413 -0
  364. package/src/messages/formatAgentMessages.test.ts +1 -1
  365. package/src/messages/index.ts +2 -0
  366. package/src/messages/prune.ts +661 -4
  367. package/src/run.ts +155 -1
  368. package/src/scripts/multi-agent-chain.ts +2 -2
  369. package/src/scripts/multi-agent-document-review-chain.ts +2 -2
  370. package/src/scripts/multi-agent-hybrid-flow.ts +4 -4
  371. package/src/scripts/multi-agent-parallel.ts +3 -3
  372. package/src/scripts/multi-agent-sequence.ts +3 -3
  373. package/src/scripts/multi-agent-subagent.ts +246 -0
  374. package/src/scripts/multi-agent-supervisor.ts +5 -5
  375. package/src/scripts/poc-multi-agent-comprehensive.ts +8 -8
  376. package/src/scripts/sequential-full-metadata-test.ts +2 -2
  377. package/src/scripts/subagent-event-driven-debug.ts +190 -0
  378. package/src/scripts/subagent-tools-debug.ts +160 -0
  379. package/src/scripts/test-custom-prompt-key.ts +3 -3
  380. package/src/scripts/test-handoff-input.ts +1 -1
  381. package/src/scripts/test-handoff-steering.ts +3 -3
  382. package/src/scripts/test-multi-agent-list-handoff.ts +1 -1
  383. package/src/scripts/test-parallel-agent-labeling.ts +3 -3
  384. package/src/scripts/test-parallel-handoffs.ts +2 -2
  385. package/src/scripts/test-thinking-handoff-bedrock.ts +1 -1
  386. package/src/scripts/test-thinking-handoff.ts +1 -1
  387. package/src/scripts/test-thinking-to-thinking-handoff-bedrock.ts +1 -1
  388. package/src/scripts/test-tool-before-handoff-role-order.ts +1 -1
  389. package/src/scripts/test-tools-before-handoff.ts +1 -1
  390. package/src/specs/agent-handoffs.test.ts +26 -483
  391. package/src/specs/anthropic.simple.test.ts +61 -0
  392. package/src/specs/multi-agent-summarization.test.ts +396 -0
  393. package/src/specs/prune.orphans.test.ts +248 -0
  394. package/src/specs/prune.test.ts +104 -16
  395. package/src/specs/thinking-handoff.test.ts +19 -19
  396. package/src/tools/BashExecutor.ts +281 -0
  397. package/src/tools/BashProgrammaticToolCalling.ts +397 -0
  398. package/src/tools/CodeExecutor.ts +63 -54
  399. package/src/tools/ProgrammaticToolCalling.ts +29 -14
  400. package/src/tools/ReadFile.ts +39 -0
  401. package/src/tools/SkillTool.ts +46 -0
  402. package/src/tools/SubagentTool.ts +100 -0
  403. package/src/tools/ToolNode.ts +548 -26
  404. package/src/tools/__tests__/BashExecutor.test.ts +49 -0
  405. package/src/tools/__tests__/CodeExecutor.test.ts +37 -36
  406. package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +60 -0
  407. package/src/tools/__tests__/ReadFile.test.ts +44 -0
  408. package/src/tools/__tests__/SkillTool.test.ts +442 -0
  409. package/src/tools/__tests__/SubagentExecutor.test.ts +1148 -0
  410. package/src/tools/__tests__/SubagentTool.test.ts +149 -0
  411. package/src/tools/__tests__/ToolNode.outputReferences.test.ts +1438 -0
  412. package/src/tools/__tests__/annotateMessagesForLLM.test.ts +479 -0
  413. package/src/tools/__tests__/skillCatalog.test.ts +161 -0
  414. package/src/tools/__tests__/subagentHooks.test.ts +210 -0
  415. package/src/tools/__tests__/toolOutputReferences.test.ts +415 -0
  416. package/src/tools/memory/memoryAppendTool.ts +1 -1
  417. package/src/tools/memory/memoryGetTool.ts +2 -2
  418. package/src/tools/memory/memorySearchTool.ts +3 -3
  419. package/src/tools/memory/shared.ts +1 -1
  420. package/src/tools/search/search.ts +12 -2
  421. package/src/tools/search/tavily-scraper.ts +235 -0
  422. package/src/tools/search/tavily-search.ts +424 -0
  423. package/src/tools/search/tavily.test.ts +965 -0
  424. package/src/tools/search/tool.ts +36 -2
  425. package/src/tools/search/types.ts +133 -8
  426. package/src/tools/search/utils.ts +13 -5
  427. package/src/tools/skillCatalog.ts +126 -0
  428. package/src/tools/subagent/SubagentExecutor.ts +676 -0
  429. package/src/tools/subagent/index.ts +13 -0
  430. package/src/tools/subagent/types.test.ts +70 -0
  431. package/src/tools/subagent/types.ts +115 -0
  432. package/src/tools/toolOutputReferences.ts +825 -0
  433. package/src/types/agent-cache.ts +74 -0
  434. package/src/types/graph.ts +172 -20
  435. package/src/types/index.ts +3 -0
  436. package/src/types/messages.ts +27 -0
  437. package/src/types/run.ts +22 -0
  438. package/src/types/skill.ts +11 -0
  439. package/src/types/tools.ts +118 -0
  440. package/src/utils/__tests__/truncation.test.ts +66 -0
  441. package/src/utils/index.ts +1 -3
  442. package/src/utils/truncation.ts +154 -0
  443. package/dist/cjs/common/spawnPath.cjs +0 -104
  444. package/dist/cjs/common/spawnPath.cjs.map +0 -1
  445. package/dist/cjs/content/ArtifactStore.cjs +0 -579
  446. package/dist/cjs/content/ArtifactStore.cjs.map +0 -1
  447. package/dist/cjs/content/ContentStore.cjs +0 -638
  448. package/dist/cjs/content/ContentStore.cjs.map +0 -1
  449. package/dist/cjs/content/contentAnalyzer.cjs +0 -91
  450. package/dist/cjs/content/contentAnalyzer.cjs.map +0 -1
  451. package/dist/cjs/content/index.cjs +0 -20
  452. package/dist/cjs/content/index.cjs.map +0 -1
  453. package/dist/cjs/content/mcpAutoCache.cjs +0 -115
  454. package/dist/cjs/content/mcpAutoCache.cjs.map +0 -1
  455. package/dist/cjs/graphs/HandoffRegistry.cjs +0 -143
  456. package/dist/cjs/graphs/HandoffRegistry.cjs.map +0 -1
  457. package/dist/cjs/providers/a2a/A2ACapabilityProvider.cjs +0 -288
  458. package/dist/cjs/providers/a2a/A2ACapabilityProvider.cjs.map +0 -1
  459. package/dist/cjs/providers/a2a/client.cjs +0 -92
  460. package/dist/cjs/providers/a2a/client.cjs.map +0 -1
  461. package/dist/cjs/providers/a2a/config.cjs +0 -38
  462. package/dist/cjs/providers/a2a/config.cjs.map +0 -1
  463. package/dist/cjs/providers/capabilityNaming.cjs +0 -43
  464. package/dist/cjs/providers/capabilityNaming.cjs.map +0 -1
  465. package/dist/cjs/providers/mcp/MCPCapabilityProvider.cjs +0 -244
  466. package/dist/cjs/providers/mcp/MCPCapabilityProvider.cjs.map +0 -1
  467. package/dist/cjs/providers/mcp/config.cjs +0 -42
  468. package/dist/cjs/providers/mcp/config.cjs.map +0 -1
  469. package/dist/cjs/providers/mcp/transport.cjs +0 -65
  470. package/dist/cjs/providers/mcp/transport.cjs.map +0 -1
  471. package/dist/cjs/providers/tools-server/ToolsServerCapabilityProvider.cjs +0 -128
  472. package/dist/cjs/providers/tools-server/ToolsServerCapabilityProvider.cjs.map +0 -1
  473. package/dist/cjs/providers/types.cjs +0 -51
  474. package/dist/cjs/providers/types.cjs.map +0 -1
  475. package/dist/cjs/tools/artifacts/schema.cjs +0 -86
  476. package/dist/cjs/tools/artifacts/schema.cjs.map +0 -1
  477. package/dist/cjs/tools/artifacts/tool.cjs +0 -219
  478. package/dist/cjs/tools/artifacts/tool.cjs.map +0 -1
  479. package/dist/cjs/tools/fileSearch/formatter.cjs +0 -93
  480. package/dist/cjs/tools/fileSearch/formatter.cjs.map +0 -1
  481. package/dist/cjs/tools/fileSearch/ragClient.cjs +0 -102
  482. package/dist/cjs/tools/fileSearch/ragClient.cjs.map +0 -1
  483. package/dist/cjs/tools/fileSearch/schema.cjs +0 -18
  484. package/dist/cjs/tools/fileSearch/schema.cjs.map +0 -1
  485. package/dist/cjs/tools/fileSearch/tool.cjs +0 -155
  486. package/dist/cjs/tools/fileSearch/tool.cjs.map +0 -1
  487. package/dist/cjs/tools/proxyTool.cjs +0 -102
  488. package/dist/cjs/tools/proxyTool.cjs.map +0 -1
  489. package/dist/cjs/utils/childAgentContext.cjs +0 -242
  490. package/dist/cjs/utils/childAgentContext.cjs.map +0 -1
  491. package/dist/cjs/utils/credentials.cjs +0 -142
  492. package/dist/cjs/utils/credentials.cjs.map +0 -1
  493. package/dist/cjs/utils/httpClient.cjs +0 -74
  494. package/dist/cjs/utils/httpClient.cjs.map +0 -1
  495. package/dist/cjs/utils/toolManifest.cjs +0 -100
  496. package/dist/cjs/utils/toolManifest.cjs.map +0 -1
  497. package/dist/esm/common/spawnPath.mjs +0 -95
  498. package/dist/esm/common/spawnPath.mjs.map +0 -1
  499. package/dist/esm/content/ArtifactStore.mjs +0 -576
  500. package/dist/esm/content/ArtifactStore.mjs.map +0 -1
  501. package/dist/esm/content/ContentStore.mjs +0 -635
  502. package/dist/esm/content/ContentStore.mjs.map +0 -1
  503. package/dist/esm/content/contentAnalyzer.mjs +0 -87
  504. package/dist/esm/content/contentAnalyzer.mjs.map +0 -1
  505. package/dist/esm/content/index.mjs +0 -5
  506. package/dist/esm/content/mcpAutoCache.mjs +0 -111
  507. package/dist/esm/content/mcpAutoCache.mjs.map +0 -1
  508. package/dist/esm/graphs/HandoffRegistry.mjs +0 -141
  509. package/dist/esm/graphs/HandoffRegistry.mjs.map +0 -1
  510. package/dist/esm/providers/a2a/A2ACapabilityProvider.mjs +0 -281
  511. package/dist/esm/providers/a2a/A2ACapabilityProvider.mjs.map +0 -1
  512. package/dist/esm/providers/a2a/client.mjs +0 -88
  513. package/dist/esm/providers/a2a/client.mjs.map +0 -1
  514. package/dist/esm/providers/a2a/config.mjs +0 -35
  515. package/dist/esm/providers/a2a/config.mjs.map +0 -1
  516. package/dist/esm/providers/capabilityNaming.mjs +0 -39
  517. package/dist/esm/providers/capabilityNaming.mjs.map +0 -1
  518. package/dist/esm/providers/mcp/MCPCapabilityProvider.mjs +0 -240
  519. package/dist/esm/providers/mcp/MCPCapabilityProvider.mjs.map +0 -1
  520. package/dist/esm/providers/mcp/config.mjs +0 -39
  521. package/dist/esm/providers/mcp/config.mjs.map +0 -1
  522. package/dist/esm/providers/mcp/transport.mjs +0 -63
  523. package/dist/esm/providers/mcp/transport.mjs.map +0 -1
  524. package/dist/esm/providers/tools-server/ToolsServerCapabilityProvider.mjs +0 -126
  525. package/dist/esm/providers/tools-server/ToolsServerCapabilityProvider.mjs.map +0 -1
  526. package/dist/esm/providers/types.mjs +0 -51
  527. package/dist/esm/providers/types.mjs.map +0 -1
  528. package/dist/esm/tools/artifacts/schema.mjs +0 -79
  529. package/dist/esm/tools/artifacts/schema.mjs.map +0 -1
  530. package/dist/esm/tools/artifacts/tool.mjs +0 -213
  531. package/dist/esm/tools/artifacts/tool.mjs.map +0 -1
  532. package/dist/esm/tools/fileSearch/formatter.mjs +0 -90
  533. package/dist/esm/tools/fileSearch/formatter.mjs.map +0 -1
  534. package/dist/esm/tools/fileSearch/ragClient.mjs +0 -98
  535. package/dist/esm/tools/fileSearch/ragClient.mjs.map +0 -1
  536. package/dist/esm/tools/fileSearch/schema.mjs +0 -15
  537. package/dist/esm/tools/fileSearch/schema.mjs.map +0 -1
  538. package/dist/esm/tools/fileSearch/tool.mjs +0 -152
  539. package/dist/esm/tools/fileSearch/tool.mjs.map +0 -1
  540. package/dist/esm/tools/proxyTool.mjs +0 -100
  541. package/dist/esm/tools/proxyTool.mjs.map +0 -1
  542. package/dist/esm/utils/childAgentContext.mjs +0 -237
  543. package/dist/esm/utils/childAgentContext.mjs.map +0 -1
  544. package/dist/esm/utils/credentials.mjs +0 -135
  545. package/dist/esm/utils/credentials.mjs.map +0 -1
  546. package/dist/esm/utils/httpClient.mjs +0 -70
  547. package/dist/esm/utils/httpClient.mjs.map +0 -1
  548. package/dist/esm/utils/toolManifest.mjs +0 -96
  549. package/dist/esm/utils/toolManifest.mjs.map +0 -1
  550. package/dist/types/common/spawnPath.d.ts +0 -59
  551. package/dist/types/content/ArtifactStore.d.ts +0 -223
  552. package/dist/types/content/ContentStore.d.ts +0 -140
  553. package/dist/types/content/contentAnalyzer.d.ts +0 -38
  554. package/dist/types/content/index.d.ts +0 -24
  555. package/dist/types/content/mcpAutoCache.d.ts +0 -89
  556. package/dist/types/content/types.d.ts +0 -75
  557. package/dist/types/graphs/HandoffRegistry.d.ts +0 -97
  558. package/dist/types/providers/a2a/A2ACapabilityProvider.d.ts +0 -89
  559. package/dist/types/providers/a2a/client.d.ts +0 -47
  560. package/dist/types/providers/a2a/config.d.ts +0 -18
  561. package/dist/types/providers/a2a/index.d.ts +0 -6
  562. package/dist/types/providers/a2a/types.d.ts +0 -173
  563. package/dist/types/providers/capabilityNaming.d.ts +0 -25
  564. package/dist/types/providers/index.d.ts +0 -12
  565. package/dist/types/providers/mcp/MCPCapabilityProvider.d.ts +0 -54
  566. package/dist/types/providers/mcp/config.d.ts +0 -20
  567. package/dist/types/providers/mcp/index.d.ts +0 -5
  568. package/dist/types/providers/mcp/transport.d.ts +0 -18
  569. package/dist/types/providers/mcp/types.d.ts +0 -112
  570. package/dist/types/providers/tools-server/ToolsServerCapabilityProvider.d.ts +0 -59
  571. package/dist/types/providers/tools-server/index.d.ts +0 -1
  572. package/dist/types/providers/types.d.ts +0 -184
  573. package/dist/types/tools/artifacts/index.d.ts +0 -3
  574. package/dist/types/tools/artifacts/schema.d.ts +0 -63
  575. package/dist/types/tools/artifacts/tool.d.ts +0 -16
  576. package/dist/types/tools/artifacts/types.d.ts +0 -127
  577. package/dist/types/tools/fileSearch/formatter.d.ts +0 -25
  578. package/dist/types/tools/fileSearch/index.d.ts +0 -5
  579. package/dist/types/tools/fileSearch/ragClient.d.ts +0 -32
  580. package/dist/types/tools/fileSearch/schema.d.ts +0 -13
  581. package/dist/types/tools/fileSearch/tool.d.ts +0 -18
  582. package/dist/types/tools/fileSearch/types.d.ts +0 -139
  583. package/dist/types/tools/proxyTool.d.ts +0 -62
  584. package/dist/types/tools/search/test.d.ts +0 -1
  585. package/dist/types/utils/childAgentContext.d.ts +0 -99
  586. package/dist/types/utils/credentials.d.ts +0 -77
  587. package/dist/types/utils/httpClient.d.ts +0 -46
  588. package/dist/types/utils/toolManifest.d.ts +0 -49
  589. package/src/common/__tests__/spawnPath.test.ts +0 -110
  590. package/src/common/spawnPath.ts +0 -101
  591. package/src/content/ArtifactStore.ts +0 -782
  592. package/src/content/ContentStore.ts +0 -753
  593. package/src/content/contentAnalyzer.ts +0 -105
  594. package/src/content/index.ts +0 -51
  595. package/src/content/mcpAutoCache.ts +0 -185
  596. package/src/content/types.ts +0 -82
  597. package/src/graphs/HandoffRegistry.ts +0 -199
  598. package/src/graphs/__tests__/HandoffRegistry.test.ts +0 -410
  599. package/src/graphs/__tests__/multi-agent-delegate.test.ts +0 -458
  600. package/src/graphs/__tests__/multi-agent-edges.test.ts +0 -276
  601. package/src/graphs/__tests__/multi-agent-nested-subgraph.test.ts +0 -221
  602. package/src/graphs/handoffValidation.test.ts +0 -353
  603. package/src/providers/__tests__/ToolsServerCapabilityProvider.integration.spec.ts +0 -79
  604. package/src/providers/__tests__/ToolsServerCapabilityProvider.test.ts +0 -271
  605. package/src/providers/__tests__/types.test.ts +0 -64
  606. package/src/providers/a2a/A2ACapabilityProvider.ts +0 -384
  607. package/src/providers/a2a/__tests__/A2ACapabilityProvider.integration.spec.ts +0 -345
  608. package/src/providers/a2a/__tests__/A2ACapabilityProvider.test.ts +0 -460
  609. package/src/providers/a2a/client.ts +0 -115
  610. package/src/providers/a2a/config.ts +0 -40
  611. package/src/providers/a2a/index.ts +0 -29
  612. package/src/providers/a2a/types.ts +0 -191
  613. package/src/providers/capabilityNaming.ts +0 -42
  614. package/src/providers/index.ts +0 -68
  615. package/src/providers/mcp/MCPCapabilityProvider.ts +0 -345
  616. package/src/providers/mcp/__tests__/MCPCapabilityProvider.integration.spec.ts +0 -386
  617. package/src/providers/mcp/__tests__/MCPCapabilityProvider.test.ts +0 -371
  618. package/src/providers/mcp/config.ts +0 -45
  619. package/src/providers/mcp/index.ts +0 -21
  620. package/src/providers/mcp/transport.ts +0 -76
  621. package/src/providers/mcp/types.ts +0 -139
  622. package/src/providers/tools-server/ToolsServerCapabilityProvider.ts +0 -249
  623. package/src/providers/tools-server/index.ts +0 -1
  624. package/src/providers/types.ts +0 -204
  625. package/src/scripts/test-bedrock-handoff-autonomous.ts +0 -267
  626. package/src/scripts/test-handoff-preamble.ts +0 -278
  627. package/src/specs/agent-handoffs-bedrock.integration.test.ts +0 -415
  628. package/src/tools/artifacts/__tests__/tool.test.ts +0 -259
  629. package/src/tools/artifacts/index.ts +0 -33
  630. package/src/tools/artifacts/schema.ts +0 -99
  631. package/src/tools/artifacts/tool.ts +0 -289
  632. package/src/tools/artifacts/types.ts +0 -162
  633. package/src/tools/fileSearch/__tests__/tool.test.ts +0 -261
  634. package/src/tools/fileSearch/formatter.ts +0 -129
  635. package/src/tools/fileSearch/index.ts +0 -23
  636. package/src/tools/fileSearch/ragClient.ts +0 -137
  637. package/src/tools/fileSearch/schema.ts +0 -19
  638. package/src/tools/fileSearch/tool.ts +0 -207
  639. package/src/tools/fileSearch/types.ts +0 -149
  640. package/src/tools/proxyTool.ts +0 -166
  641. package/src/tools/search/output.md +0 -2775
  642. package/src/tools/search/test.html +0 -884
  643. package/src/tools/search/test.md +0 -643
  644. package/src/tools/search/test.ts +0 -159
  645. package/src/utils/__tests__/childAgentContext.test.ts +0 -217
  646. package/src/utils/__tests__/credentials.test.ts +0 -130
  647. package/src/utils/__tests__/httpClient.test.ts +0 -75
  648. package/src/utils/__tests__/toolManifest.test.ts +0 -116
  649. package/src/utils/childAgentContext.ts +0 -259
  650. package/src/utils/credentials.ts +0 -157
  651. package/src/utils/httpClient.ts +0 -92
  652. package/src/utils/toolManifest.ts +0 -109
  653. /package/dist/esm/{content → langchain}/index.mjs.map +0 -0
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Agent system-message prompt-cache types.
3
+ * ==========================================
4
+ *
5
+ * `@illuma-ai/agents` exposes a generic primitive — `system_cache_blocks` —
6
+ * for composing a system message that gets explicit cache markers
7
+ * (cachePoint on Bedrock, cache_control on Anthropic) at consumer-defined
8
+ * boundaries. The library encodes each entry into the right wire format
9
+ * for the active provider; consumers decide what content to put in each
10
+ * block.
11
+ *
12
+ * Why this is generic rather than tier-named
13
+ * ------------------------------------------------
14
+ * Earlier iterations exposed `platform_instructions` and `cache_ttl:
15
+ * { platform, agent }` — vocabulary borrowed from a specific consumer's
16
+ * multi-tenant chat-platform mental model. That leaked one consumer's
17
+ * domain into the library and made it confusing for other consumers
18
+ * (CLI tools, desktop apps, gateways) which have no notion of
19
+ * "platforms" or "agents".
20
+ *
21
+ * The current shape lets every consumer define their own cache-tier
22
+ * organization without the library knowing or caring.
23
+ *
24
+ * Cache key composition
25
+ * ---------------------
26
+ * Both Anthropic and Bedrock hash the message bytes leading up to each
27
+ * cache marker. So entry N's cache key is the concatenation of bytes
28
+ * 0..N. Stable content (universal rules, framework docs) goes earlier;
29
+ * volatile content (per-agent identity, per-tool docs) goes later. The
30
+ * earlier entries get cross-tenant cache hits; the later entries get
31
+ * narrower hits.
32
+ *
33
+ * Provider budget
34
+ * ---------------
35
+ * Bedrock's Converse API supports up to 4 cachePoint blocks per request.
36
+ * The default tools-array cache strategy (see `IllumaBedrockConverse`)
37
+ * uses up to 2 of those. So at most 2 entries should appear in
38
+ * `system_cache_blocks` to leave budget for the trailing
39
+ * `instructions` block. The library throws on more than 2.
40
+ *
41
+ * Anthropic supports up to 4 cache breakpoints per request workspace-wide;
42
+ * the same constraint applies to keep tools + system within budget.
43
+ */
44
+
45
+ /** Provider TTL hint applied to a cachePoint / cache_control marker. */
46
+ export type AgentCacheTTL = '5m' | '1h';
47
+
48
+ /**
49
+ * One cacheable system content block. Each entry produces a text block
50
+ * followed by a provider-specific cache marker in the assembled system
51
+ * message. Entries are emitted in array order — earlier = more stable
52
+ * = wider cache key.
53
+ */
54
+ export interface SystemCacheBlock {
55
+ /**
56
+ * Text payload. Caller is responsible for keeping this byte-stable
57
+ * across requests that should share a cache entry. ANY change to
58
+ * these bytes invalidates every cache key that includes this entry.
59
+ */
60
+ text: string;
61
+ /**
62
+ * Optional TTL hint for the cache marker. Defaults to '5m' when
63
+ * omitted. '1h' costs more to write (2× base vs 1.25×) but survives
64
+ * longer idle, which is the right tradeoff for low-traffic blocks.
65
+ */
66
+ ttl?: AgentCacheTTL;
67
+ }
68
+
69
+ /**
70
+ * Maximum number of `system_cache_blocks` entries the library accepts.
71
+ * Higher than this would exceed Bedrock's 4-cachePoint budget once the
72
+ * tools array and trailing `instructions` block are counted.
73
+ */
74
+ export const MAX_SYSTEM_CACHE_BLOCKS = 2;
@@ -24,6 +24,7 @@ import type {
24
24
  GenericTool,
25
25
  LCTool,
26
26
  ToolApprovalConfig,
27
+ ToolExecuteBatchRequest,
27
28
  } from '@/types/tools';
28
29
  import type { Providers, Callback, GraphNodeKeys } from '@/common';
29
30
  import type { StandardGraph, MultiAgentGraph } from '@/graphs';
@@ -35,6 +36,7 @@ import type {
35
36
  ReasoningDeltaEvent,
36
37
  } from '@/types/stream';
37
38
  import type { TokenCounter } from '@/types/run';
39
+ import type { SystemCacheBlock, AgentCacheTTL } from '@/types/agent-cache';
38
40
 
39
41
  /** Interface for bound model with stream and invoke methods */
40
42
  export interface ChatModel {
@@ -109,6 +111,8 @@ export interface EventHandler {
109
111
  | RunStepDeltaEvent
110
112
  | MessageDeltaEvent
111
113
  | ReasoningDeltaEvent
114
+ | SubagentUpdateEvent
115
+ | ToolExecuteBatchRequest
112
116
  | { result: ToolEndEvent },
113
117
  metadata?: Record<string, unknown>,
114
118
  graph?: StandardGraph | MultiAgentGraph
@@ -383,9 +387,13 @@ export type GraphEdge = {
383
387
  /** Can return boolean or specific destination(s) */
384
388
  condition?: (state: BaseGraphState) => boolean | string | string[];
385
389
  /**
386
- * EdgeType.HANDOFF — true agent handoff, parent calls child inline and gets result back.
387
- * EdgeType.TRANSFER one-way transfer, parent exits and child takes over.
388
- * EdgeType.SEQUENCE fixed graph edges for sequential/parallel transitions.
390
+ * EdgeType.HANDOFF — one-way routing: parent emits an `lc_transfer_to_*`
391
+ * tool call and exits, child takes over and responds directly to the
392
+ * user. Aligns with the standard handoff semantics.
393
+ * EdgeType.DIRECT — fixed graph edges for automatic sequential / parallel
394
+ * transitions. Downstream consumers may layer additional wiring on top
395
+ * (fan-in with prompt, parallel groups, approval-gate nodes,
396
+ * excludeResults / agentMessages).
389
397
  */
390
398
  edgeType?: import('@/common').EdgeType;
391
399
  /**
@@ -415,19 +423,6 @@ export type GraphEdge = {
415
423
  * For handoff edges: Customizes the parameter name for the handoff instruction input.
416
424
  */
417
425
  promptKey?: string;
418
- /**
419
- * For handoff edges: Maximum characters for the result returned to the parent.
420
- * Uses head/tail truncation (60/40 split) to preserve key findings and conclusions.
421
- * Defaults to DEFAULT_HANDOFF_MAX_RESULT_CHARS (32768 chars, ~8192 tokens).
422
- */
423
- maxResultChars?: number;
424
- /**
425
- * For handoff edges: When true, the child agent receives the full parent
426
- * conversation history plus the orchestrator's instructions appended.
427
- * When false (default), the child only receives the orchestrator's scoped
428
- * instructions — isolated from the parent conversation.
429
- */
430
- passthrough?: boolean;
431
426
  /**
432
427
  * Approval gate configuration for sequence edges.
433
428
  * When set, inserts an approval gate node between source and destination.
@@ -439,12 +434,15 @@ export type GraphEdge = {
439
434
  export type MultiAgentGraphInput = StandardGraphInput & {
440
435
  edges: GraphEdge[];
441
436
  /**
442
- * When set, the graph routes START to this agent instead of the default starting nodes.
443
- * Used for multi-turn resumption: the caller reads `lastActiveAgentId` from the
444
- * previous turn's metadata and passes it here so follow-up messages route to the
437
+ * When set, the graph routes START to this agent instead of the default
438
+ * starting nodes. Used for multi-turn resumption: the caller reads the
439
+ * last active agent id from the previous turn (e.g. via
440
+ * `Run.getLastActiveAgentId()`, which derives it from the run's content
441
+ * data trail) and passes it here so follow-up messages route to the
445
442
  * agent that last handled the conversation.
446
443
  *
447
- * If the agent ID is invalid (not in the graph), falls back to default starting nodes.
444
+ * If the agent ID is invalid (not in the graph), falls back to default
445
+ * starting nodes.
448
446
  */
449
447
  resumeFromAgentId?: string;
450
448
  };
@@ -618,6 +616,20 @@ export interface SummarizationConfig {
618
616
  * while persistedSummary is loaded from the conversation's own history.
619
617
  */
620
618
  initialSummary?: string;
619
+
620
+ /**
621
+ * optional fields. When the host wants the summarization
622
+ * pass to run on a different LLM than the agent's own (e.g. a cheaper
623
+ * model for compaction), these provider/model overrides flow through to
624
+ * the summarize callback.
625
+ */
626
+ provider?: Providers;
627
+ model?: string;
628
+ parameters?: Record<string, unknown>;
629
+ prompt?: string;
630
+ updatePrompt?: string;
631
+ trigger?: { type: string; value: number };
632
+ maxSummaryTokens?: number;
621
633
  }
622
634
 
623
635
  /**
@@ -651,6 +663,73 @@ export interface FileManifestEntry {
651
663
  messageIndex?: number;
652
664
  }
653
665
 
666
+ /** Configuration for a subagent type that can be spawned by a parent agent. */
667
+ export type SubagentConfig = {
668
+ /** Identifier used in the tool's `subagent_type` enum (e.g. 'researcher', 'coder'). */
669
+ type: string;
670
+ /** Human-readable display name. */
671
+ name: string;
672
+ /** What this subagent specializes in — shown to the LLM. */
673
+ description: string;
674
+ /** Full agent config for the child graph. Omit when `self` is true. */
675
+ agentInputs?: AgentInputs;
676
+ /** When true, reuse the parent's AgentInputs (context isolation without separate config). */
677
+ self?: boolean;
678
+ /** Max AGENT→TOOLS cycles before forced stop (default: 25). */
679
+ maxTurns?: number;
680
+ /** Allow this subagent to spawn its own subagents (default: false). */
681
+ allowNested?: boolean;
682
+ };
683
+
684
+ /** SubagentConfig with agentInputs guaranteed present (self-spawn resolved). */
685
+ export type ResolvedSubagentConfig = SubagentConfig & {
686
+ agentInputs: AgentInputs;
687
+ };
688
+
689
+ /** Lifecycle phase carried on {@link SubagentUpdateEvent}. */
690
+ export type SubagentUpdatePhase =
691
+ | 'start'
692
+ | 'run_step'
693
+ | 'run_step_delta'
694
+ | 'run_step_completed'
695
+ | 'message_delta'
696
+ | 'reasoning_delta'
697
+ | 'stop'
698
+ | 'error';
699
+
700
+ /**
701
+ * Wrapper event emitted when a subagent's child graph dispatches activity.
702
+ * Lets hosts show subagent progress in a UI surface separate from the parent
703
+ * conversation without having to untangle events by agent ID.
704
+ */
705
+ export interface SubagentUpdateEvent {
706
+ /** Parent run ID. */
707
+ runId: string;
708
+ /** Child run ID (unique per subagent execution). */
709
+ subagentRunId: string;
710
+ /**
711
+ * Parent-side `tool_call_id` for the `subagent` tool invocation that
712
+ * triggered this run. Stable for the duration of the child; lets hosts
713
+ * correlate updates deterministically instead of inferring by ordering.
714
+ * Omitted when the executor was invoked outside of a tool-call context.
715
+ */
716
+ parentToolCallId?: string;
717
+ /** Subagent `type` identifier from the SubagentConfig. */
718
+ subagentType: string;
719
+ /** Child agent ID assigned to this subagent execution. */
720
+ subagentAgentId: string;
721
+ /** Parent agent ID that spawned this subagent. */
722
+ parentAgentId?: string;
723
+ /** Lifecycle phase carried by this update. */
724
+ phase: SubagentUpdatePhase;
725
+ /** Underlying event payload (shape depends on phase). */
726
+ data?: unknown;
727
+ /** Short human-readable description. Hosts can render this directly. */
728
+ label?: string;
729
+ /** ISO timestamp for ordering / display. */
730
+ timestamp: string;
731
+ }
732
+
654
733
  export interface AgentInputs {
655
734
  agentId: string;
656
735
  /** Human-readable name for the agent (used in handoff context). Defaults to agentId if not provided. */
@@ -661,12 +740,64 @@ export interface AgentInputs {
661
740
  toolMap?: ToolMap;
662
741
  tools?: GraphTools;
663
742
  provider: Providers;
743
+ /**
744
+ * Ordered list of cacheable system content blocks emitted BEFORE
745
+ * `instructions` in the system message. Each block gets its own cache
746
+ * marker (cachePoint on Bedrock, cache_control on Anthropic) so the
747
+ * cache key for each block includes only the bytes up to and including
748
+ * its own marker. Entries are emitted in array order — earlier =
749
+ * stabler = wider cache key (best for cross-tenant sharing).
750
+ *
751
+ * See `src/types/agent-cache.ts` for full semantics. Capped at
752
+ * `MAX_SYSTEM_CACHE_BLOCKS` (2) entries to stay within Bedrock's
753
+ * 4-cachePoint budget after the tools array consumes 2.
754
+ */
755
+ system_cache_blocks?: SystemCacheBlock[];
756
+ /**
757
+ * Stable/cacheable system instructions for this agent. Always emitted
758
+ * with its own trailing cache marker (when caching is supported by
759
+ * the provider/model). Use `instructions_cache_ttl` to override the
760
+ * default '5m' TTL.
761
+ */
664
762
  instructions?: string;
763
+ /** TTL for the trailing `instructions` cache marker. Defaults to '5m'. */
764
+ instructions_cache_ttl?: AgentCacheTTL;
665
765
  streamBuffer?: number;
666
766
  maxContextTokens?: number;
667
767
  clientOptions?: ClientOptions;
768
+ /**
769
+ * Dynamic system tail appended after the cacheable instructions
770
+ * without any cache marker. Per-user / per-message context belongs
771
+ * here so it does not invalidate the cacheable prefix.
772
+ */
668
773
  additional_instructions?: string;
669
774
  reasoningKey?: 'reasoning_content' | 'reasoning';
775
+ /**
776
+ * Subagent types this agent may spawn. When non-empty, Graph injects the
777
+ * `subagent` tool into the agent's toolset with the per-config enum and
778
+ * description populated.
779
+ */
780
+ subagentConfigs?: SubagentConfig[];
781
+ /**
782
+ * Maximum subagent depth allowed below this agent. Used by SubagentExecutor
783
+ * to abort runaway nesting. Defaults to a small constant.
784
+ */
785
+ maxSubagentDepth?: number;
786
+ /**
787
+ * Pre-existing summary injected into the system message via
788
+ * AgentContext.buildInstructionsString. Populated by SubagentExecutor when
789
+ * spawning a self-config subagent that should inherit the parent's prior
790
+ * compaction summary; otherwise host-supplied at run time.
791
+ */
792
+ initialSummary?: { text: string; tokenCount: number };
793
+ /**
794
+ * opt-in for summarization. When false, the agent never
795
+ * invokes the summarize callback regardless of context utilization.
796
+ * Defaults to undefined (treated as enabled by default to preserve prior
797
+ * behaviour); hosts that want strict opt-in semantics should set it
798
+ * explicitly.
799
+ */
800
+ summarizationEnabled?: boolean;
670
801
  /** Format content blocks as strings (for legacy compatibility i.e. Ollama/Azure Serverless) */
671
802
  useLegacyContent?: boolean;
672
803
  /**
@@ -745,3 +876,24 @@ export interface AgentInputs {
745
876
  */
746
877
  fileManifest?: FileManifestEntry[];
747
878
  }
879
+
880
+ /**
881
+ * Tunable knobs for position-based content degradation.
882
+ * See `messages/contextPruning.ts` and `messages/contextPruningSettings.ts`.
883
+ */
884
+ export interface ContextPruningConfig {
885
+ enabled?: boolean;
886
+ keepLastAssistants?: number;
887
+ softTrimRatio?: number;
888
+ hardClearRatio?: number;
889
+ minPrunableToolChars?: number;
890
+ softTrim?: {
891
+ maxChars?: number;
892
+ headChars?: number;
893
+ tailChars?: number;
894
+ };
895
+ hardClear?: {
896
+ enabled?: boolean;
897
+ placeholder?: string;
898
+ };
899
+ }
@@ -1,6 +1,9 @@
1
1
  // src/types/index.ts
2
+ export * from './agent-cache';
2
3
  export * from './graph';
3
4
  export * from './llm';
5
+ export * from './messages';
4
6
  export * from './run';
5
7
  export * from './stream';
6
8
  export * from './tools';
9
+ export * from './skill';
@@ -2,3 +2,30 @@ import type Anthropic from '@anthropic-ai/sdk';
2
2
  import type { BaseMessage } from '@langchain/core/messages';
3
3
  export type AnthropicMessages = Array<AnthropicMessage | BaseMessage>;
4
4
  export type AnthropicMessage = Anthropic.MessageParam;
5
+
6
+ /**
7
+ * Per-message ref metadata stamped onto a `ToolMessage` at execution time
8
+ * (PR #117). Read by `annotateMessagesForLLM` to apply transient
9
+ * annotation to a copy of the message right before it goes on the wire to
10
+ * the provider. Never read after the run-scoped registry has been cleared.
11
+ *
12
+ * Lives in `ToolMessage.additional_kwargs`. LangChain's provider
13
+ * serializers don't transmit `additional_kwargs` to provider APIs, so the
14
+ * metadata never leaks even if you forget to clean it.
15
+ */
16
+ export interface ToolMessageRefMetadata {
17
+ /** Key under which this message's untruncated output was registered. */
18
+ _refKey?: string;
19
+ /**
20
+ * Registry bucket scope under which `_refKey` was stored. For named runs
21
+ * this equals `config.configurable.run_id`; for anonymous invocations
22
+ * (no `run_id`) ToolNode mints a per-batch synthetic scope
23
+ * (`\0anon-<n>`) so concurrent batches don't collide. Stamping the
24
+ * scope on the message itself lets `annotateMessagesForLLM` recover it
25
+ * without re-deriving from config — which is impossible for the
26
+ * anonymous case, since the scope is internal to ToolNode.
27
+ */
28
+ _refScope?: string;
29
+ /** Placeholders the model used that could not be resolved this batch. */
30
+ _unresolvedRefs?: string[];
31
+ }
package/src/types/run.ts CHANGED
@@ -11,6 +11,7 @@ import type * as s from '@/types/stream';
11
11
  import type * as e from '@/common/enum';
12
12
  import type * as g from '@/types/graph';
13
13
  import type * as l from '@/types/llm';
14
+ import type { HookRegistry } from '@/hooks';
14
15
 
15
16
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
17
  export type ZodObjectAny = z.ZodObject<any, any, any, any>;
@@ -73,7 +74,9 @@ export interface AgentStateChannels {
73
74
  messages: BaseMessage[];
74
75
  next: string;
75
76
  [key: string]: unknown;
77
+ /** Stable/cacheable system instructions for this agent. */
76
78
  instructions?: string;
79
+ /** Dynamic system tail appended after stable instructions. */
77
80
  additional_instructions?: string;
78
81
  }
79
82
 
@@ -118,6 +121,25 @@ export type RunConfig = {
118
121
  runId: string;
119
122
  graphConfig: LegacyGraphConfig | StandardGraphConfig | MultiAgentGraphConfig;
120
123
  customHandlers?: Record<string, g.EventHandler>;
124
+ /**
125
+ * Optional {@link HookRegistry} that wires host-defined hook callbacks
126
+ * (PreToolUse / PostToolUse / PreCompact / etc.) into this run.
127
+ *
128
+ * Hooks fire synchronously inside ToolNode and processStream; returning
129
+ * `deny` from a PreToolUse hook short-circuits the tool call. Lifetime
130
+ * is per-run — the host should construct a fresh registry (or reuse a
131
+ * shared one) and dispose of it together with the conversation block
132
+ * to prevent leaks.
133
+ */
134
+ hooks?: HookRegistry;
135
+ /**
136
+ * Tool output reference configuration (PRs #114 / #117).
137
+ * When `enabled` is true, the Run constructs a single
138
+ * ToolOutputReferenceRegistry and threads it to every ToolNode built by
139
+ * the graph so `{{tool<i>turn<n>}}` placeholders resolve across agents.
140
+ * Defaults to disabled (registry not constructed).
141
+ */
142
+ toolOutputReferences?: import('@/types/tools').ToolOutputReferencesConfig;
121
143
  returnContent?: boolean;
122
144
  tokenCounter?: TokenCounter;
123
145
  indexTokenCountMap?: Record<string, number>;
@@ -0,0 +1,11 @@
1
+ // src/types/skill.ts
2
+
3
+ /** Minimal skill metadata for catalog assembly. The host provides these from its own data layer. */
4
+ export type SkillCatalogEntry = {
5
+ /** Kebab-case identifier (what the model passes to SkillTool) */
6
+ name: string;
7
+ /** One-line description for the catalog listing */
8
+ description: string;
9
+ /** Optional human-readable label (UI only, not shown to model) */
10
+ displayTitle?: string;
11
+ };
@@ -2,6 +2,7 @@
2
2
  import type { StructuredToolInterface } from '@langchain/core/tools';
3
3
  import type { RunnableToolLike } from '@langchain/core/runnables';
4
4
  import type { ToolCall } from '@langchain/core/messages/tool';
5
+ import type { MessageContentComplex } from '@langchain/core/messages';
5
6
  import type { ToolErrorData } from './stream';
6
7
  import { EnvVar, ExecutionContext } from '@/common';
7
8
 
@@ -60,6 +61,35 @@ export type ToolNodeOptions = {
60
61
  * When provided, tools matching the policy will call interrupt() before execution.
61
62
  */
62
63
  toolApprovalConfig?: ToolApprovalConfig;
64
+ /**
65
+ * Optional hook registry threaded down from Run. When set, ToolNode
66
+ * fires PreToolUse / PostToolUse / PostToolUseFailure / PermissionDenied
67
+ * lifecycle events through executeHooks during event-driven dispatch.
68
+ */
69
+ hookRegistry?: import('@/hooks').HookRegistry;
70
+ /**
71
+ * Maximum characters for a single tool result (head+tail truncation).
72
+ * When omitted, derived from the agent's `maxContextTokens` (30%
73
+ * heuristic), capped at HARD_MAX_TOOL_RESULT_CHARS. —
74
+ * downstream consumers may drive truncation through other knobs;
75
+ * accepting this option keeps the test surface portable.
76
+ */
77
+ maxToolResultChars?: number;
78
+ /**
79
+ * Run-scoped tool output reference configuration (PR #114).
80
+ * When `enabled` is true, ToolNode registers successful outputs and
81
+ * substitutes `{{tool<i>turn<n>}}` placeholders found in string args.
82
+ * Ignored when `toolOutputRegistry` is also provided (the host-supplied
83
+ * registry wins).
84
+ */
85
+ toolOutputReferences?: ToolOutputReferencesConfig;
86
+ /**
87
+ * Pre-constructed registry instance shared across ToolNodes for the run.
88
+ * Graphs pass the same registry to every ToolNode they compile so
89
+ * cross-agent `{{tool<i>turn<n>}}` substitutions resolve. Takes
90
+ * precedence over `toolOutputReferences` when both are set.
91
+ */
92
+ toolOutputRegistry?: import('@/tools/toolOutputReferences').ToolOutputReferenceRegistry;
63
93
  };
64
94
 
65
95
  export type ToolNodeConstructorParams = ToolRefs & ToolNodeOptions;
@@ -90,12 +120,39 @@ export type CodeExecutionToolParams =
90
120
  [EnvVar.CODE_API_KEY]?: string;
91
121
  };
92
122
 
123
+ /**
124
+ * Bash execution tool params. Same shape as CodeExecutionToolParams —
125
+ * BashExecutor reuses the /exec endpoint with `lang: 'bash'`.
126
+ */
127
+ export type BashExecutionToolParams = CodeExecutionToolParams;
128
+
129
+ /**
130
+ * Read-file tool params. Resolution of the `file_path` to actual bytes is
131
+ * delegated to a host-supplied resolver in `RunConfig` (skill files, code
132
+ * exec session files, etc.).
133
+ */
134
+ export type ReadFileToolParams =
135
+ | undefined
136
+ | {
137
+ apiKey?: string;
138
+ [EnvVar.CODE_API_KEY]?: string;
139
+ };
140
+
93
141
  export type FileRef = {
94
142
  id: string;
95
143
  name: string;
96
144
  path?: string;
97
145
  /** Session ID this file belongs to (for multi-session file tracking) */
98
146
  session_id?: string;
147
+ /**
148
+ * `true` when the codeapi sandbox echoed this entry as an unchanged
149
+ * passthrough of an input the caller already owns (skill files,
150
+ * downloaded inputs whose hash matched the baseline, inherited
151
+ * `.dirkeep` markers). The tool-result formatter renders these as
152
+ * "Available files" rather than "Generated files" so the LLM doesn't
153
+ * conflate infrastructure inputs with newly-produced outputs.
154
+ */
155
+ inherited?: true;
99
156
  };
100
157
 
101
158
  export type FileRefs = FileRef[];
@@ -190,6 +247,27 @@ export type ToolExecuteBatchRequest = {
190
247
  reject: (error: Error) => void;
191
248
  };
192
249
 
250
+ /**
251
+ * Generic message-injection envelope used by SkillTool, hooks, and any other
252
+ * tool execution handler that needs to push extra context into graph state
253
+ * after the ToolMessage. The host's message formatter is responsible for
254
+ * placement and any per-provider merging rules.
255
+ */
256
+ export type InjectedMessage = {
257
+ /** 'user' for skill body injection, 'system' for context hints.
258
+ * Both are converted to HumanMessage at runtime; the original role
259
+ * is preserved in additional_kwargs.role. */
260
+ role: 'user' | 'system';
261
+ /** Message content: string for simple text, array for complex multi-part content */
262
+ content: string | MessageContentComplex[];
263
+ /** When true, the message is framework-internal: not shown in UI, not counted as a user turn */
264
+ isMeta?: boolean;
265
+ /** Origin tag for downstream consumers (UI, pruner, compaction) */
266
+ source?: 'skill' | 'hook' | 'system';
267
+ /** Only set when source is 'skill', for compaction preservation */
268
+ skillName?: string;
269
+ };
270
+
193
271
  /** Result for a single tool call in event-driven execution */
194
272
  export type ToolExecuteResult = {
195
273
  /** Matches ToolCallRequest.id */
@@ -202,11 +280,44 @@ export type ToolExecuteResult = {
202
280
  status: 'success' | 'error';
203
281
  /** Error message if status is 'error' */
204
282
  errorMessage?: string;
283
+ /**
284
+ * Messages to inject into graph state after the ToolMessage for this call.
285
+ * Placed after tool results to respect provider message ordering
286
+ * (tool_call -> tool_result adjacency). The host's message formatter may
287
+ * merge injected user messages with the preceding tool_result turn.
288
+ * Generic mechanism: any tool execution handler can use this.
289
+ */
290
+ injectedMessages?: InjectedMessage[];
205
291
  };
206
292
 
207
293
  /** Map of tool names to tool definitions */
208
294
  export type LCToolRegistry = Map<string, LCTool>;
209
295
 
296
+ /**
297
+ * Configuration for the tool output reference feature (PR #114).
298
+ *
299
+ * When `enabled: true`, ToolNode stores each successful tool output under
300
+ * a stable key `tool<idx>turn<turn>` and the LLM can pipe a previous output
301
+ * into a subsequent tool's args via the literal placeholder
302
+ * `{{tool<idx>turn<turn>}}`. Substitution happens immediately before tool
303
+ * invocation; the LLM-visible ToolMessage.content is annotated with a
304
+ * `_ref` JSON field or a `[ref: tool<idx>turn<turn>]` prefix so the model
305
+ * knows which key the output is stored under.
306
+ *
307
+ * Disabled by default. Hosts that want to opt in pass
308
+ * `toolOutputReferences: { enabled: true }` on RunConfig and (optionally)
309
+ * append the bash tool's tool-output-references guide to the bash tool
310
+ * description so the LLM learns the substitution syntax.
311
+ */
312
+ export type ToolOutputReferencesConfig = {
313
+ /** Enable the registry and placeholder substitution. Defaults to `false`. */
314
+ enabled?: boolean;
315
+ /** Maximum characters stored (and substituted) per registered output. */
316
+ maxOutputSize?: number;
317
+ /** Hard cap on total characters retained across all registered outputs for the run. */
318
+ maxTotalSize?: number;
319
+ };
320
+
210
321
  export type ProgrammaticCache = { toolMap: ToolMap; toolDefs: LCTool[] };
211
322
 
212
323
  // ============================================================================
@@ -456,6 +567,13 @@ export type ProgrammaticToolCallingParams = {
456
567
  [key: string]: unknown;
457
568
  };
458
569
 
570
+ /**
571
+ * Initialization parameters for the BashPTC tool. Same shape as
572
+ * {@link ProgrammaticToolCallingParams}; the bash variant just runs
573
+ * generated code through `lang: 'bash'` instead of `lang: 'python'`.
574
+ */
575
+ export type BashProgrammaticToolCallingParams = ProgrammaticToolCallingParams;
576
+
459
577
  // ============================================================================
460
578
  // Tool Session Context Types
461
579
  // ============================================================================
@@ -0,0 +1,66 @@
1
+ import { describe, it, expect } from '@jest/globals';
2
+ import {
3
+ HARD_MAX_TOOL_RESULT_CHARS,
4
+ HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE,
5
+ calculateMaxToolResultChars,
6
+ calculateMaxTotalToolOutputSize,
7
+ } from '@/utils/truncation';
8
+
9
+ describe('truncation helpers', () => {
10
+ describe('calculateMaxToolResultChars', () => {
11
+ it('returns the hard cap when context tokens are missing', () => {
12
+ expect(calculateMaxToolResultChars()).toBe(HARD_MAX_TOOL_RESULT_CHARS);
13
+ expect(calculateMaxToolResultChars(undefined)).toBe(
14
+ HARD_MAX_TOOL_RESULT_CHARS
15
+ );
16
+ expect(calculateMaxToolResultChars(0)).toBe(HARD_MAX_TOOL_RESULT_CHARS);
17
+ expect(calculateMaxToolResultChars(-100)).toBe(
18
+ HARD_MAX_TOOL_RESULT_CHARS
19
+ );
20
+ });
21
+
22
+ it('computes 30% of context-window characters for normal inputs', () => {
23
+ // 100k tokens * 0.3 = 30k tokens * 4 chars/token = 120k chars
24
+ expect(calculateMaxToolResultChars(100_000)).toBe(120_000);
25
+ });
26
+
27
+ it('clamps to the hard cap for large context windows', () => {
28
+ // 1M tokens * 0.3 * 4 = 1.2M chars, exceeds 400k cap
29
+ expect(calculateMaxToolResultChars(1_000_000)).toBe(
30
+ HARD_MAX_TOOL_RESULT_CHARS
31
+ );
32
+ });
33
+ });
34
+
35
+ describe('calculateMaxTotalToolOutputSize', () => {
36
+ it('returns the absolute hard cap when no per-output is provided', () => {
37
+ expect(calculateMaxTotalToolOutputSize()).toBe(
38
+ HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE
39
+ );
40
+ expect(calculateMaxTotalToolOutputSize(0)).toBe(
41
+ HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE
42
+ );
43
+ expect(calculateMaxTotalToolOutputSize(-1)).toBe(
44
+ HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE
45
+ );
46
+ });
47
+
48
+ it('doubles the per-output cap by default', () => {
49
+ expect(calculateMaxTotalToolOutputSize(100_000)).toBe(200_000);
50
+ expect(calculateMaxTotalToolOutputSize(1)).toBe(2);
51
+ });
52
+
53
+ it('clamps the doubled value to HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE', () => {
54
+ // 4M * 2 = 8M, exceeds 5M
55
+ expect(calculateMaxTotalToolOutputSize(4_000_000)).toBe(
56
+ HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE
57
+ );
58
+ // Right at the boundary: 2.5M * 2 = 5M (no clamp).
59
+ expect(calculateMaxTotalToolOutputSize(2_500_000)).toBe(5_000_000);
60
+ // Just past it: 2_500_001 * 2 = 5_000_002 -> clamped.
61
+ expect(calculateMaxTotalToolOutputSize(2_500_001)).toBe(
62
+ HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE
63
+ );
64
+ });
65
+ });
66
+ });
@@ -13,6 +13,4 @@ export * from './toolDiscoveryCache';
13
13
  export * from './pruneCalibration';
14
14
  export * from './fileManifest';
15
15
  export * from './errors';
16
- export * from './httpClient';
17
- export * from './credentials';
18
- export * from './toolManifest';
16
+ export * from './truncation';