agentfootprint 7.24.0 → 7.26.0

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 (220) hide show
  1. package/AGENTS.md +1 -1
  2. package/CLAUDE.md +5 -3
  3. package/ai-instructions/claude-code/SKILL.md +1 -1
  4. package/dist/adapters/hosting/agentcore.js +112 -1
  5. package/dist/adapters/hosting/agentcore.js.map +1 -1
  6. package/dist/adapters/llm/AnthropicProvider.js +10 -0
  7. package/dist/adapters/llm/AnthropicProvider.js.map +1 -1
  8. package/dist/adapters/llm/BedrockProvider.js +13 -1
  9. package/dist/adapters/llm/BedrockProvider.js.map +1 -1
  10. package/dist/adapters/llm/BrowserAnthropicProvider.js +6 -0
  11. package/dist/adapters/llm/BrowserAnthropicProvider.js.map +1 -1
  12. package/dist/adapters/llm/BrowserOpenAIProvider.js +18 -0
  13. package/dist/adapters/llm/BrowserOpenAIProvider.js.map +1 -1
  14. package/dist/adapters/llm/MockProvider.js +9 -0
  15. package/dist/adapters/llm/MockProvider.js.map +1 -1
  16. package/dist/adapters/llm/OpenAIProvider.js +21 -0
  17. package/dist/adapters/llm/OpenAIProvider.js.map +1 -1
  18. package/dist/conventions.js +12 -0
  19. package/dist/conventions.js.map +1 -1
  20. package/dist/core/Agent.js +56 -2
  21. package/dist/core/Agent.js.map +1 -1
  22. package/dist/core/agent/AgentBuilder.js +98 -1
  23. package/dist/core/agent/AgentBuilder.js.map +1 -1
  24. package/dist/core/agent/buildAgentChart.js +12 -2
  25. package/dist/core/agent/buildAgentChart.js.map +1 -1
  26. package/dist/core/agent/buildDynamicAgentChart.js +12 -3
  27. package/dist/core/agent/buildDynamicAgentChart.js.map +1 -1
  28. package/dist/core/agent/outputEnforcement.js +192 -0
  29. package/dist/core/agent/outputEnforcement.js.map +1 -0
  30. package/dist/core/agent/stages/callLLM.js +31 -1
  31. package/dist/core/agent/stages/callLLM.js.map +1 -1
  32. package/dist/core/agent/stages/outputRetry.js +102 -0
  33. package/dist/core/agent/stages/outputRetry.js.map +1 -0
  34. package/dist/core/agent/stages/route.js +111 -6
  35. package/dist/core/agent/stages/route.js.map +1 -1
  36. package/dist/core/outputSchema.js.map +1 -1
  37. package/dist/esm/adapters/hosting/agentcore.d.ts +50 -1
  38. package/dist/esm/adapters/hosting/agentcore.js +110 -0
  39. package/dist/esm/adapters/hosting/agentcore.js.map +1 -1
  40. package/dist/esm/adapters/llm/AnthropicProvider.d.ts +10 -0
  41. package/dist/esm/adapters/llm/AnthropicProvider.js +10 -0
  42. package/dist/esm/adapters/llm/AnthropicProvider.js.map +1 -1
  43. package/dist/esm/adapters/llm/BedrockProvider.d.ts +9 -0
  44. package/dist/esm/adapters/llm/BedrockProvider.js +13 -1
  45. package/dist/esm/adapters/llm/BedrockProvider.js.map +1 -1
  46. package/dist/esm/adapters/llm/BrowserAnthropicProvider.d.ts +1 -0
  47. package/dist/esm/adapters/llm/BrowserAnthropicProvider.js +6 -0
  48. package/dist/esm/adapters/llm/BrowserAnthropicProvider.js.map +1 -1
  49. package/dist/esm/adapters/llm/BrowserOpenAIProvider.d.ts +4 -0
  50. package/dist/esm/adapters/llm/BrowserOpenAIProvider.js +18 -0
  51. package/dist/esm/adapters/llm/BrowserOpenAIProvider.js.map +1 -1
  52. package/dist/esm/adapters/llm/MockProvider.d.ts +9 -0
  53. package/dist/esm/adapters/llm/MockProvider.js +9 -0
  54. package/dist/esm/adapters/llm/MockProvider.js.map +1 -1
  55. package/dist/esm/adapters/llm/OpenAIProvider.d.ts +12 -0
  56. package/dist/esm/adapters/llm/OpenAIProvider.js +21 -0
  57. package/dist/esm/adapters/llm/OpenAIProvider.js.map +1 -1
  58. package/dist/esm/adapters/types.d.ts +46 -0
  59. package/dist/esm/conventions.d.ts +4 -0
  60. package/dist/esm/conventions.js +12 -0
  61. package/dist/esm/conventions.js.map +1 -1
  62. package/dist/esm/core/Agent.d.ts +26 -1
  63. package/dist/esm/core/Agent.js +56 -2
  64. package/dist/esm/core/Agent.js.map +1 -1
  65. package/dist/esm/core/agent/AgentBuilder.d.ts +15 -0
  66. package/dist/esm/core/agent/AgentBuilder.js +98 -1
  67. package/dist/esm/core/agent/AgentBuilder.js.map +1 -1
  68. package/dist/esm/core/agent/buildAgentChart.d.ts +13 -1
  69. package/dist/esm/core/agent/buildAgentChart.js +12 -2
  70. package/dist/esm/core/agent/buildAgentChart.js.map +1 -1
  71. package/dist/esm/core/agent/buildDynamicAgentChart.js +12 -3
  72. package/dist/esm/core/agent/buildDynamicAgentChart.js.map +1 -1
  73. package/dist/esm/core/agent/outputEnforcement.d.ts +173 -0
  74. package/dist/esm/core/agent/outputEnforcement.js +180 -0
  75. package/dist/esm/core/agent/outputEnforcement.js.map +1 -0
  76. package/dist/esm/core/agent/stages/callLLM.d.ts +15 -0
  77. package/dist/esm/core/agent/stages/callLLM.js +31 -1
  78. package/dist/esm/core/agent/stages/callLLM.js.map +1 -1
  79. package/dist/esm/core/agent/stages/outputRetry.d.ts +34 -0
  80. package/dist/esm/core/agent/stages/outputRetry.js +98 -0
  81. package/dist/esm/core/agent/stages/outputRetry.js.map +1 -0
  82. package/dist/esm/core/agent/stages/route.d.ts +18 -2
  83. package/dist/esm/core/agent/stages/route.js +111 -6
  84. package/dist/esm/core/agent/stages/route.js.map +1 -1
  85. package/dist/esm/core/agent/types.d.ts +18 -0
  86. package/dist/esm/core/outputSchema.d.ts +51 -0
  87. package/dist/esm/core/outputSchema.js.map +1 -1
  88. package/dist/esm/events/payloads.d.ts +47 -1
  89. package/dist/esm/events/registry.d.ts +3 -1
  90. package/dist/esm/events/registry.js +2 -0
  91. package/dist/esm/events/registry.js.map +1 -1
  92. package/dist/esm/hosting/errors.d.ts +44 -2
  93. package/dist/esm/hosting/errors.js +63 -0
  94. package/dist/esm/hosting/errors.js.map +1 -1
  95. package/dist/esm/hosting/headers.d.ts +16 -0
  96. package/dist/esm/hosting/headers.js +24 -0
  97. package/dist/esm/hosting/headers.js.map +1 -0
  98. package/dist/esm/hosting/httpHost.d.ts +70 -4
  99. package/dist/esm/hosting/httpHost.js +211 -47
  100. package/dist/esm/hosting/httpHost.js.map +1 -1
  101. package/dist/esm/hosting/index.d.ts +23 -8
  102. package/dist/esm/hosting/index.js +21 -6
  103. package/dist/esm/hosting/index.js.map +1 -1
  104. package/dist/esm/hosting/nodeHost.d.ts +23 -0
  105. package/dist/esm/hosting/nodeHost.js +21 -1
  106. package/dist/esm/hosting/nodeHost.js.map +1 -1
  107. package/dist/esm/hosting/types.d.ts +212 -6
  108. package/dist/esm/hosting/types.js +7 -5
  109. package/dist/esm/hosting/types.js.map +1 -1
  110. package/dist/esm/hosting/webSocketConversation.d.ts +101 -0
  111. package/dist/esm/hosting/webSocketConversation.js +341 -0
  112. package/dist/esm/hosting/webSocketConversation.js.map +1 -0
  113. package/dist/esm/hosting/webSocketFrames.d.ts +164 -0
  114. package/dist/esm/hosting/webSocketFrames.js +284 -0
  115. package/dist/esm/hosting/webSocketFrames.js.map +1 -0
  116. package/dist/esm/hosting-providers.d.ts +7 -2
  117. package/dist/esm/hosting-providers.js +7 -2
  118. package/dist/esm/hosting-providers.js.map +1 -1
  119. package/dist/esm/index.d.ts +2 -1
  120. package/dist/esm/index.js +5 -0
  121. package/dist/esm/index.js.map +1 -1
  122. package/dist/esm/resilience/withCircuitBreaker.js +5 -0
  123. package/dist/esm/resilience/withCircuitBreaker.js.map +1 -1
  124. package/dist/esm/resilience/withFallback.js +5 -0
  125. package/dist/esm/resilience/withFallback.js.map +1 -1
  126. package/dist/esm/resilience/withRetry.js +6 -0
  127. package/dist/esm/resilience/withRetry.js.map +1 -1
  128. package/dist/events/registry.js +2 -0
  129. package/dist/events/registry.js.map +1 -1
  130. package/dist/hosting/errors.js +66 -1
  131. package/dist/hosting/errors.js.map +1 -1
  132. package/dist/hosting/headers.js +28 -0
  133. package/dist/hosting/headers.js.map +1 -0
  134. package/dist/hosting/httpHost.js +211 -47
  135. package/dist/hosting/httpHost.js.map +1 -1
  136. package/dist/hosting/index.js +23 -6
  137. package/dist/hosting/index.js.map +1 -1
  138. package/dist/hosting/nodeHost.js +20 -0
  139. package/dist/hosting/nodeHost.js.map +1 -1
  140. package/dist/hosting/types.js +7 -5
  141. package/dist/hosting/types.js.map +1 -1
  142. package/dist/hosting/webSocketConversation.js +345 -0
  143. package/dist/hosting/webSocketConversation.js.map +1 -0
  144. package/dist/hosting/webSocketFrames.js +297 -0
  145. package/dist/hosting/webSocketFrames.js.map +1 -0
  146. package/dist/hosting-providers.js +8 -2
  147. package/dist/hosting-providers.js.map +1 -1
  148. package/dist/index.js +9 -1
  149. package/dist/index.js.map +1 -1
  150. package/dist/resilience/withCircuitBreaker.js +5 -0
  151. package/dist/resilience/withCircuitBreaker.js.map +1 -1
  152. package/dist/resilience/withFallback.js +5 -0
  153. package/dist/resilience/withFallback.js.map +1 -1
  154. package/dist/resilience/withRetry.js +6 -0
  155. package/dist/resilience/withRetry.js.map +1 -1
  156. package/dist/types/adapters/hosting/agentcore.d.ts +50 -1
  157. package/dist/types/adapters/hosting/agentcore.d.ts.map +1 -1
  158. package/dist/types/adapters/llm/AnthropicProvider.d.ts +10 -0
  159. package/dist/types/adapters/llm/AnthropicProvider.d.ts.map +1 -1
  160. package/dist/types/adapters/llm/BedrockProvider.d.ts +9 -0
  161. package/dist/types/adapters/llm/BedrockProvider.d.ts.map +1 -1
  162. package/dist/types/adapters/llm/BrowserAnthropicProvider.d.ts +1 -0
  163. package/dist/types/adapters/llm/BrowserAnthropicProvider.d.ts.map +1 -1
  164. package/dist/types/adapters/llm/BrowserOpenAIProvider.d.ts +4 -0
  165. package/dist/types/adapters/llm/BrowserOpenAIProvider.d.ts.map +1 -1
  166. package/dist/types/adapters/llm/MockProvider.d.ts +9 -0
  167. package/dist/types/adapters/llm/MockProvider.d.ts.map +1 -1
  168. package/dist/types/adapters/llm/OpenAIProvider.d.ts +12 -0
  169. package/dist/types/adapters/llm/OpenAIProvider.d.ts.map +1 -1
  170. package/dist/types/adapters/types.d.ts +46 -0
  171. package/dist/types/adapters/types.d.ts.map +1 -1
  172. package/dist/types/conventions.d.ts +4 -0
  173. package/dist/types/conventions.d.ts.map +1 -1
  174. package/dist/types/core/Agent.d.ts +26 -1
  175. package/dist/types/core/Agent.d.ts.map +1 -1
  176. package/dist/types/core/agent/AgentBuilder.d.ts +15 -0
  177. package/dist/types/core/agent/AgentBuilder.d.ts.map +1 -1
  178. package/dist/types/core/agent/buildAgentChart.d.ts +13 -1
  179. package/dist/types/core/agent/buildAgentChart.d.ts.map +1 -1
  180. package/dist/types/core/agent/buildDynamicAgentChart.d.ts.map +1 -1
  181. package/dist/types/core/agent/outputEnforcement.d.ts +174 -0
  182. package/dist/types/core/agent/outputEnforcement.d.ts.map +1 -0
  183. package/dist/types/core/agent/stages/callLLM.d.ts +15 -0
  184. package/dist/types/core/agent/stages/callLLM.d.ts.map +1 -1
  185. package/dist/types/core/agent/stages/outputRetry.d.ts +35 -0
  186. package/dist/types/core/agent/stages/outputRetry.d.ts.map +1 -0
  187. package/dist/types/core/agent/stages/route.d.ts +18 -2
  188. package/dist/types/core/agent/stages/route.d.ts.map +1 -1
  189. package/dist/types/core/agent/types.d.ts +18 -0
  190. package/dist/types/core/agent/types.d.ts.map +1 -1
  191. package/dist/types/core/outputSchema.d.ts +51 -0
  192. package/dist/types/core/outputSchema.d.ts.map +1 -1
  193. package/dist/types/events/payloads.d.ts +47 -1
  194. package/dist/types/events/payloads.d.ts.map +1 -1
  195. package/dist/types/events/registry.d.ts +3 -1
  196. package/dist/types/events/registry.d.ts.map +1 -1
  197. package/dist/types/hosting/errors.d.ts +44 -2
  198. package/dist/types/hosting/errors.d.ts.map +1 -1
  199. package/dist/types/hosting/headers.d.ts +17 -0
  200. package/dist/types/hosting/headers.d.ts.map +1 -0
  201. package/dist/types/hosting/httpHost.d.ts +70 -4
  202. package/dist/types/hosting/httpHost.d.ts.map +1 -1
  203. package/dist/types/hosting/index.d.ts +23 -8
  204. package/dist/types/hosting/index.d.ts.map +1 -1
  205. package/dist/types/hosting/nodeHost.d.ts +23 -0
  206. package/dist/types/hosting/nodeHost.d.ts.map +1 -1
  207. package/dist/types/hosting/types.d.ts +212 -6
  208. package/dist/types/hosting/types.d.ts.map +1 -1
  209. package/dist/types/hosting/webSocketConversation.d.ts +102 -0
  210. package/dist/types/hosting/webSocketConversation.d.ts.map +1 -0
  211. package/dist/types/hosting/webSocketFrames.d.ts +165 -0
  212. package/dist/types/hosting/webSocketFrames.d.ts.map +1 -0
  213. package/dist/types/hosting-providers.d.ts +7 -2
  214. package/dist/types/hosting-providers.d.ts.map +1 -1
  215. package/dist/types/index.d.ts +2 -1
  216. package/dist/types/index.d.ts.map +1 -1
  217. package/dist/types/resilience/withCircuitBreaker.d.ts.map +1 -1
  218. package/dist/types/resilience/withFallback.d.ts.map +1 -1
  219. package/dist/types/resilience/withRetry.d.ts.map +1 -1
  220. package/package.json +1 -1
@@ -25,6 +25,7 @@ const typedEmit_js_1 = require("../../../recorders/core/typedEmit.js");
25
25
  const resilienceHooks_js_1 = require("../../../recorders/core/resilienceHooks.js");
26
26
  const cost_js_1 = require("../../cost.js");
27
27
  const outputSchema_js_1 = require("../../outputSchema.js");
28
+ const outputEnforcement_js_1 = require("../outputEnforcement.js");
28
29
  const reliabilityExecution_js_1 = require("./reliabilityExecution.js");
29
30
  /**
30
31
  * Drop the fields that exist for the library and never for the model.
@@ -94,7 +95,14 @@ function buildCallLLMStage(deps) {
94
95
  // schemas at startup before the tools slot has run. Computed BEFORE the
95
96
  // llm_start emit so the event reports what the model ACTUALLY saw this call
96
97
  // (count + the name/description catalog), not the static startup set.
97
- const activeToolSchemas = scope.dynamicToolSchemas ?? deps.toolSchemas;
98
+ const registeredToolSchemas = scope.dynamicToolSchemas ?? deps.toolSchemas;
99
+ // Under `'tool-forced'` the schema rides along as one more tool ON THE
100
+ // WIRE. It is reported in `llm_start` too, and deliberately: that event's
101
+ // whole claim is "what the model actually saw this call", and a tool the
102
+ // model was forced to use is the last thing to leave out of it.
103
+ const activeToolSchemas = deps.schemaTool
104
+ ? [...registeredToolSchemas, deps.schemaTool]
105
+ : registeredToolSchemas;
98
106
  (0, typedEmit_js_1.typedEmit)(scope, 'agentfootprint.stream.llm_start', {
99
107
  iteration,
100
108
  provider: deps.provider.name,
@@ -121,6 +129,9 @@ function buildCallLLMStage(deps) {
121
129
  ...(deps.thinkingBudget !== undefined && {
122
130
  thinking: { budget: deps.thinkingBudget },
123
131
  }),
132
+ ...(deps.schemaTool !== undefined && {
133
+ toolChoice: { type: 'tool', name: deps.schemaTool.name },
134
+ }),
124
135
  };
125
136
  // v2.6+ — call cache strategy to attach provider-specific cache
126
137
  // hints. CacheGate has already routed (apply-markers / no-markers)
@@ -191,6 +202,25 @@ function buildCallLLMStage(deps) {
191
202
  // after a stream is a pre-existing quirk; see MENTAL_MODEL §14.)
192
203
  resp = await deps.provider.complete(req, providerHooks);
193
204
  }
205
+ // `'tool-forced'`: the answer arrived as the synthetic tool's ARGUMENTS,
206
+ // so it is moved into `content` and the call is taken off the list here,
207
+ // at the single seam every later reader goes through. Everything
208
+ // downstream — the reliability validator, the scope writes, the Route
209
+ // decider, the retry loop — then sees the response it would have seen
210
+ // under `'instruct'`: a final answer that is a JSON string, and no tool
211
+ // calls. One normalization, no second code path, and nothing further
212
+ // down has to know which strategy is in force.
213
+ const forcedName = deps.schemaTool?.name;
214
+ if (forcedName !== undefined) {
215
+ const answer = (0, outputEnforcement_js_1.readSchemaToolAnswer)(resp);
216
+ if (answer !== undefined) {
217
+ resp = {
218
+ ...resp,
219
+ content: answer,
220
+ toolCalls: resp.toolCalls.filter((tc) => tc.name !== forcedName),
221
+ };
222
+ }
223
+ }
194
224
  return resp;
195
225
  };
196
226
  // v2.13 — build the output-schema validator hook when both
@@ -1 +1 @@
1
- {"version":3,"file":"callLLM.js","sourceRoot":"","sources":["../../../../src/core/agent/stages/callLLM.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;;;AAYH,uEA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gB,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC;QACvE,KAAK,CAAC,iBAAiB,GAAG,KAAK,CAAC,iBAAiB,GAAG,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC;QAC1E,KAAK,CAAC,gBAAgB,GAAG,QAAQ,CAAC,OAAO,CAAC;QAC1C,KAAK,CAAC,kBAAkB,GAAG,QAAQ,CAAC,SAAS,CAAC;QAC9C,0DAA0D;QAC1D,+DAA+D;QAC/D,4DAA4D;QAC5D,+DAA+D;QAC/D,IAAI,QAAQ,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;YACtC,KAA2D,CAAC,WAAW;gBACtE,QAAQ,CAAC,WAAW,CAAC;QACzB,CAAC;QAED,IAAA,wBAAS,EAAC,KAAK,EAAE,+BAA+B,EAAE;YAChD,SAAS;YACT,OAAO,EAAE,QAAQ,CAAC,OAAO;YACzB,aAAa,EAAE,QAAQ,CAAC,SAAS,CAAC,MAAM;YACxC,KAAK,EAAE,QAAQ,CAAC,KAAK;YACrB,UAAU,EAAE,QAAQ,CAAC,UAAU;YAC/B,UAAU;SACX,CAAC,CAAC;QAEH,IAAA,sBAAY,EAAC,KAAK,EAAE,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IACjF,CAAC,CAAC;AACJ,CAAC;AA3RD,8CA2RC"}
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ /**
3
+ * outputRetry — the branch that asks again when the answer failed the schema.
4
+ *
5
+ * Mounted as a THIRD branch of the Route decider, and only on an agent that
6
+ * opted into `.outputSchema(parser, { retries })`. It carries `{ loopTo }`
7
+ * to the same target the `tool-calls` branch loops to, which is the whole
8
+ * mechanism: a retry is not a special mode, it is one more ordinary turn of
9
+ * the ReAct loop. The injection engine re-evaluates, the slots recompose,
10
+ * the cache decides, the model is called — so the attempt gets its own
11
+ * `iteration_start` / `llm_start` / `llm_end` bracket and its own `cost.tick`
12
+ * against `costBudget`.
13
+ *
14
+ * That is the difference from the in-stage schema retry the reliability gate
15
+ * has done since v2.13. There, N attempts happen inside ONE `call-llm` stage:
16
+ * one bracket for all of them, and one cost tick carrying only the last
17
+ * attempt's usage — attempts that were genuinely billed and are invisible in
18
+ * the recording. Here every attempt is a turn, and the recording says so.
19
+ *
20
+ * The two layers compose rather than collide. With `.reliability()` also
21
+ * configured, its in-stage rules run FIRST and decide what to do with a
22
+ * response before it is committed; `retries` governs answers that WERE
23
+ * committed and turned out invalid.
24
+ *
25
+ * Pure function apart from its enforcement config — no closure over Agent
26
+ * class state.
27
+ */
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.buildOutputRetryStage = void 0;
30
+ const typedEmit_js_1 = require("../../../recorders/core/typedEmit.js");
31
+ const outputEnforcement_js_1 = require("../outputEnforcement.js");
32
+ /**
33
+ * Build the retry stage. `enforcement.retries` is the cap the decider already
34
+ * checked before routing here — this stage does the work of asking again.
35
+ */
36
+ function buildOutputRetryStage(enforcement) {
37
+ return (scope) => {
38
+ const iteration = scope.iteration;
39
+ const failure = scope.outputSchemaFailure;
40
+ if (failure === undefined) {
41
+ // Unreachable through the decider, which writes the carrier immediately
42
+ // before routing here. Returning quietly rather than throwing keeps a
43
+ // hand-built chart that mounts this branch without the decider from
44
+ // taking down a run over a missing diagnostic.
45
+ return;
46
+ }
47
+ const failedAnswer = scope.llmLatestContent;
48
+ const [answerTurn, correctionTurn] = (0, outputEnforcement_js_1.buildCorrectiveTurn)(failedAnswer, failure, {
49
+ attempt: failure.attempt,
50
+ // The total the run may spend: the first attempt plus its retries.
51
+ totalAttempts: enforcement.retries + 1,
52
+ });
53
+ const hash = (0, outputEnforcement_js_1.correctiveMessageHash)(correctionTurn.content);
54
+ // The conversation, as it really went: the answer that failed, then the
55
+ // correction. A plain local array — a TypedScope array read is a live
56
+ // proxy view, and both the commit and the event payload below must be
57
+ // detached plain data.
58
+ const newHistory = [
59
+ ...scope.history,
60
+ answerTurn,
61
+ correctionTurn,
62
+ ];
63
+ scope.history = newHistory;
64
+ (0, outputEnforcement_js_1.recordOutputAttempt)(scope, {
65
+ attempt: failure.attempt,
66
+ iteration,
67
+ outcome: 'retried',
68
+ stage: failure.stage,
69
+ error: failure.error,
70
+ ...(failure.path !== undefined && { path: failure.path }),
71
+ correctiveMessageHash: hash,
72
+ });
73
+ (0, typedEmit_js_1.typedEmit)(scope, 'agentfootprint.agent.output_schema_retry', {
74
+ attempt: failure.attempt,
75
+ // What is left AFTER this correction — `0` means this is the last ask.
76
+ retriesRemaining: enforcement.retries - failure.attempt,
77
+ iteration,
78
+ stage: failure.stage,
79
+ error: failure.error,
80
+ ...(failure.path !== undefined && { path: failure.path }),
81
+ correctiveMessageHash: hash,
82
+ });
83
+ // Close this iteration's bracket before the loop turns. Every recorder
84
+ // that synthesizes steps counts on `iteration_start` and `iteration_end`
85
+ // pairing per `iterIndex`, and the crash-checkpoint tracker takes its
86
+ // history snapshot from this payload — so a retry that skipped it would
87
+ // leave a run with one more start than end and a checkpoint one turn
88
+ // behind the conversation.
89
+ (0, typedEmit_js_1.typedEmit)(scope, 'agentfootprint.agent.iteration_end', {
90
+ turnIndex: 0,
91
+ iterIndex: iteration,
92
+ toolCallCount: 0,
93
+ history: newHistory,
94
+ });
95
+ // A retry consumes an iteration, exactly as a tool call does. It is one
96
+ // more real turn against the agent's declared budget, and the iteration
97
+ // counter is the vocabulary every bracket in the run is keyed on.
98
+ scope.iteration = iteration + 1;
99
+ };
100
+ }
101
+ exports.buildOutputRetryStage = buildOutputRetryStage;
102
+ //# sourceMappingURL=outputRetry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outputRetry.js","sourceRoot":"","sources":["../../../../src/core/agent/stages/outputRetry.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;;;AAIH,uEAAiE;AACjE,kEAKiC;AAGjC;;;GAGG;AACH,SAAgB,qBAAqB,CACnC,WAAsC;IA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gB,EAAE,WAAW,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO;YACvD,SAAS;YACT,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,KAAK,EAAE,OAAO,CAAC,KAAK;YACpB,GAAG,CAAC,OAAO,CAAC,IAAI,KAAK,SAAS,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;YACzD,qBAAqB,EAAE,IAAI;SAC5B,CAAC,CAAC;QAEH,uEAAuE;QACvE,yEAAyE;QACzE,sEAAsE;QACtE,wEAAwE;QACxE,qEAAqE;QACrE,2BAA2B;QAC3B,IAAA,wBAAS,EAAC,KAAK,EAAE,oCAAoC,EAAE;YACrD,SAAS,EAAE,CAAC;YACZ,SAAS,EAAE,SAAS;YACpB,aAAa,EAAE,CAAC;YAChB,OAAO,EAAE,UAAU;SACpB,CAAC,CAAC;QAEH,wEAAwE;QACxE,wEAAwE;QACxE,kEAAkE;QAClE,KAAK,CAAC,SAAS,GAAG,SAAS,GAAG,CAAC,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC;AAxED,sDAwEC"}
@@ -18,20 +18,35 @@ exports.buildRouteDeciderStage = exports.routeDeciderStage = void 0;
18
18
  const typedEmit_js_1 = require("../../../recorders/core/typedEmit.js");
19
19
  const runChain_js_1 = require("../middleware/runChain.js");
20
20
  const ledger_js_1 = require("../middleware/ledger.js");
21
- const routeDeciderStage = (scope) => {
21
+ const outputEnforcement_js_1 = require("../outputEnforcement.js");
22
+ /** The base decision, with the sentence that explains it. Split out so the
23
+ * enforcement-enabled path can decide, then judge, then announce ONCE — an
24
+ * agent whose answer is about to be re-asked should not have a route event
25
+ * saying it finished. */
26
+ function decideBranch(scope) {
22
27
  const toolCalls = scope.llmLatestToolCalls;
23
28
  const iteration = scope.iteration;
24
29
  const chosen = toolCalls.length > 0 && iteration < scope.maxIterations ? 'tool-calls' : 'final';
25
- (0, typedEmit_js_1.typedEmit)(scope, 'agentfootprint.agent.route_decided', {
26
- turnIndex: 0,
27
- iterIndex: iteration,
30
+ return {
28
31
  chosen,
29
32
  rationale: chosen === 'tool-calls'
30
33
  ? `LLM requested ${toolCalls.length} tool call(s)`
31
34
  : iteration >= scope.maxIterations
32
35
  ? 'maxIterations reached — forcing final'
33
36
  : 'LLM produced no tool calls — final answer',
37
+ };
38
+ }
39
+ function emitRouteDecided(scope, chosen, rationale) {
40
+ (0, typedEmit_js_1.typedEmit)(scope, 'agentfootprint.agent.route_decided', {
41
+ turnIndex: 0,
42
+ iterIndex: scope.iteration,
43
+ chosen,
44
+ rationale,
34
45
  });
46
+ }
47
+ const routeDeciderStage = (scope) => {
48
+ const { chosen, rationale } = decideBranch(scope);
49
+ emitRouteDecided(scope, chosen, rationale);
35
50
  return chosen;
36
51
  };
37
52
  exports.routeDeciderStage = routeDeciderStage;
@@ -61,11 +76,28 @@ exports.routeDeciderStage = routeDeciderStage;
61
76
  * would be running it over something that is not the output.
62
77
  *
63
78
  * Empty chain → the exact synchronous decider this file has always exported.
79
+ *
80
+ * ## Why the schema is judged HERE too
81
+ *
82
+ * The same property that made this the output seam makes it the enforcement
83
+ * seam. `outputSchema` used to be judged only at the caller's boundary, after
84
+ * the run — a fine place to reject an answer and a useless place to fix one,
85
+ * because the loop has already stopped. Judged here, one stage before the
86
+ * Final branch, the run still HAS a loop: a failed answer can route to
87
+ * `'output-retry'`, which loops back for one more real turn.
88
+ *
89
+ * The judging runs AFTER the message chain, over the content the chain
90
+ * produced, because that is the string the caller will receive — validating
91
+ * the pre-chain value would judge an answer nobody gets. A DENIED answer is
92
+ * never judged or retried: it was withheld on purpose, and re-asking for it
93
+ * would be the library working around a rule the app wrote.
64
94
  */
65
- function buildRouteDeciderStage(messageMiddleware) {
95
+ function buildRouteDeciderStage(messageMiddleware, enforcement) {
66
96
  const chain = messageMiddleware ?? [];
67
- if (chain.length === 0)
97
+ if (chain.length === 0 && enforcement === undefined)
68
98
  return exports.routeDeciderStage;
99
+ if (enforcement !== undefined)
100
+ return buildEnforcingDecider(chain, enforcement);
69
101
  return async (scope) => {
70
102
  const chosen = (0, exports.routeDeciderStage)(scope);
71
103
  if (chosen !== 'final')
@@ -94,4 +126,77 @@ function buildRouteDeciderStage(messageMiddleware) {
94
126
  };
95
127
  }
96
128
  exports.buildRouteDeciderStage = buildRouteDeciderStage;
129
+ /**
130
+ * The decider an agent with `.outputSchema(parser, { retries })` runs:
131
+ * decide, run the output chain if there is one, judge the answer, THEN
132
+ * announce the branch — so `route_decided` names the branch the run actually
133
+ * took rather than the one it was heading for.
134
+ */
135
+ function buildEnforcingDecider(chain, enforcement) {
136
+ return async (scope) => {
137
+ const base = decideBranch(scope);
138
+ if (base.chosen !== 'final') {
139
+ emitRouteDecided(scope, base.chosen, base.rationale);
140
+ return base.chosen;
141
+ }
142
+ let denied = false;
143
+ if (chain.length > 0) {
144
+ const verdict = await (0, runChain_js_1.runMessageChain)(chain, {
145
+ phase: 'output',
146
+ content: scope.llmLatestContent,
147
+ history: [...scope.history],
148
+ iteration: scope.iteration,
149
+ ...(scope.runIdentity && { identity: scope.runIdentity }),
150
+ });
151
+ (0, ledger_js_1.recordDecisions)(scope, verdict.decisions);
152
+ if (verdict.kind === 'deny') {
153
+ denied = true;
154
+ scope.messageDeniedReason = verdict.reason;
155
+ scope.messageDeniedPhase = 'output';
156
+ scope.messageDeniedBy = verdict.middleware;
157
+ }
158
+ scope.llmLatestContent = verdict.content;
159
+ }
160
+ // A withheld answer is not judged and never re-asked. The app decided
161
+ // nobody gets this string; asking the model for a better-shaped version
162
+ // of it would be the library routing around that decision.
163
+ if (denied) {
164
+ emitRouteDecided(scope, 'final', base.rationale);
165
+ return 'final';
166
+ }
167
+ const attempt = (scope.outputAttempts?.length ?? 0) + 1;
168
+ const failure = (0, outputEnforcement_js_1.judgeAnswer)(scope.llmLatestContent, enforcement.parser);
169
+ if (failure === undefined) {
170
+ (0, outputEnforcement_js_1.recordOutputAttempt)(scope, {
171
+ attempt,
172
+ iteration: scope.iteration,
173
+ outcome: 'passed',
174
+ });
175
+ emitRouteDecided(scope, 'final', base.rationale);
176
+ return 'final';
177
+ }
178
+ if (attempt <= enforcement.retries) {
179
+ // The retry stage writes the correction and files the row, because it
180
+ // is the one that knows what it wrote. This is the hand-off.
181
+ scope.outputSchemaFailure = { attempt, ...failure };
182
+ emitRouteDecided(scope, 'output-retry', `final answer failed the output schema (${failure.stage}) — ` +
183
+ `asking again, attempt ${attempt + 1} of ${enforcement.retries + 1}`);
184
+ return 'output-retry';
185
+ }
186
+ // Out of retries. The answer stands as the run's answer; `runTyped()`
187
+ // throws on it at the boundary exactly as it did before any of this
188
+ // existed, and `.outputFallback()` still gets its turn there.
189
+ (0, outputEnforcement_js_1.recordOutputAttempt)(scope, {
190
+ attempt,
191
+ iteration: scope.iteration,
192
+ outcome: 'exhausted',
193
+ stage: failure.stage,
194
+ error: failure.error,
195
+ ...(failure.path !== undefined && { path: failure.path }),
196
+ });
197
+ emitRouteDecided(scope, 'final', `final answer failed the output schema (${failure.stage}) and ` +
198
+ `${enforcement.retries} retry/retries were spent`);
199
+ return 'final';
200
+ };
201
+ }
97
202
  //# sourceMappingURL=route.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../src/core/agent/stages/route.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAGH,uEAAiE;AAIjE,2DAA4D;AAC5D,uDAA0D;AAInD,MAAM,iBAAiB,GAAG,CAAC,KAA6B,EAAe,EAAE;IAC9E,MAAM,SAAS,GAAG,KAAK,CAAC,kBAAiD,CAAC;IAC1E,MAAM,SAAS,GAAG,KAAK,CAAC,SAAmB,CAAC;IAC5C,MAAM,MAAM,GACV,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,SAAS,GAAG,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC;IAEnF,IAAA,wBAAS,EAAC,KAAK,EAAE,oCAAoC,EAAE;QACrD,SAAS,EA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"status": "Healthy", "time_of_last_update": <unix seconds> }`
26
+ * GET /ws a bidirectional WebSocket, on the SAME port
26
27
  *
27
28
  * and the caller's conversation arrives in the
28
29
  * `X-Amzn-Bedrock-AgentCore-Runtime-Session-Id` header rather than in the body,
29
30
  * which is the one thing paths-and-bodies configuration alone could not
30
31
  * express before this release.
31
32
  *
33
+ * ── The second door ──────────────────────────────────────────────────────────
34
+ * `/ws` is this runtime's answer for a caller that cannot host an inbound
35
+ * endpoint — a browser, most obviously — and so dials out and parks a channel
36
+ * instead. It is the same container and the same port, which is exactly why the
37
+ * two doors here share one socket.
38
+ *
39
+ * Its wire facts are ADAPTER facts and live nowhere but this file: 32KB frames,
40
+ * a 15-minute idle ceiling, the bearer credential carried as a
41
+ * `Sec-WebSocket-Protocol` offer because a browser's WebSocket API cannot set a
42
+ * header, and session affinity that has to be readable from the query string
43
+ * for the same reason. The port knows none of it — it is handed a session id
44
+ * and a header bag, the same two things every other transport hands it.
45
+ *
32
46
  * ── Verification status, stated plainly ──────────────────────────────────────
33
47
  * `agentCoreRuntimeHost` is **plain HTTP and is really verified**: it runs the
34
48
  * same host conformance suite as `nodeHost`, over a real socket, in
@@ -54,7 +68,7 @@
54
68
  * importing this module costs zero peer-dep load.
55
69
  */
56
70
  /// <reference types="node" />
57
- import type { HttpHost, HttpWire } from '../../hosting/httpHost.js';
71
+ import type { ConversationHandshake, HandshakeFacts, HttpHost, HttpWire } from '../../hosting/httpHost.js';
58
72
  import type { CheckpointEnvelope, SessionLifecycle } from '../../hosting/types.js';
59
73
  /** Options for {@link agentCoreRuntimeHost}. */
60
74
  export interface AgentCoreRuntimeHostOptions {
@@ -104,6 +118,14 @@ export interface AgentCoreRuntimeHostOptions {
104
118
  * });
105
119
  */
106
120
  readonly server?: import('node:http').Server;
121
+ /**
122
+ * Path that takes a conversation upgrade. Default `'/ws'` — the runtime's
123
+ * own second door, beside `/invocations` on the same port.
124
+ *
125
+ * You do not need `server` for this: both doors share one socket by
126
+ * construction, which is what the single-port container required.
127
+ */
128
+ readonly conversationPath?: string;
107
129
  }
108
130
  /**
109
131
  * The AgentCore Runtime contract as an {@link HttpWire}.
@@ -113,6 +135,33 @@ export interface AgentCoreRuntimeHostOptions {
113
135
  * else can reuse them by name.
114
136
  */
115
137
  export declare function agentCoreRuntimeWire(busy?: () => boolean): HttpWire;
138
+ /**
139
+ * The `/ws` handshake, in this runtime's spelling: **header-or-query session
140
+ * affinity, and the bearer subprotocol mapped into headers.**
141
+ *
142
+ * ── Why the query string is read at all ──────────────────────────────────────
143
+ * The same header carries the session on `/invocations`, and it is preferred
144
+ * here too. But the caller this door exists for is a browser, and the browser
145
+ * WebSocket API cannot set a header — so a session id has nowhere to travel
146
+ * except the URL. Both the runtime's header name and the plain `sessionId` are
147
+ * accepted as query parameters, case-insensitively; **the header wins** when
148
+ * both arrive, so a caller that sets both is never surprised by which one the
149
+ * server preferred. That is the same precedence rule the request dialect uses.
150
+ *
151
+ * ── Why the credential becomes a header ──────────────────────────────────────
152
+ * A bearer token offered as a subprotocol is this runtime's spelling of
153
+ * `Authorization`, and a port field spelled the way one vendor spells it is how
154
+ * a port stops being one. So it lands in `headers.authorization` as
155
+ * `Bearer <token>` — the vocabulary every other transport already uses — and
156
+ * the raw `sec-websocket-protocol` header is left in place, so an application
157
+ * that reads the offer itself still can. **Nothing here authenticates
158
+ * anything**: the port never proves who is calling, and a token that arrived is
159
+ * a claim, exactly like the session id beside it.
160
+ *
161
+ * Exported by name so the mapping is inspectable and testable without binding a
162
+ * socket, the same way the body shapes are.
163
+ */
164
+ export declare function readAgentCoreConversation(facts: HandshakeFacts): ConversationHandshake;
116
165
  /**
117
166
  * An `AgentHost` that speaks AgentCore Runtime's container contract.
118
167
  *
@@ -23,12 +23,26 @@
23
23
  *
24
24
  * POST /invocations JSON `{ "prompt": "..." }` → JSON `{ "response", "status" }`
25
25
  * GET /ping → `{ "status": "Healthy", "time_of_last_update": <unix seconds> }`
26
+ * GET /ws a bidirectional WebSocket, on the SAME port
26
27
  *
27
28
  * and the caller's conversation arrives in the
28
29
  * `X-Amzn-Bedrock-AgentCore-Runtime-Session-Id` header rather than in the body,
29
30
  * which is the one thing paths-and-bodies configuration alone could not
30
31
  * express before this release.
31
32
  *
33
+ * ── The second door ──────────────────────────────────────────────────────────
34
+ * `/ws` is this runtime's answer for a caller that cannot host an inbound
35
+ * endpoint — a browser, most obviously — and so dials out and parks a channel
36
+ * instead. It is the same container and the same port, which is exactly why the
37
+ * two doors here share one socket.
38
+ *
39
+ * Its wire facts are ADAPTER facts and live nowhere but this file: 32KB frames,
40
+ * a 15-minute idle ceiling, the bearer credential carried as a
41
+ * `Sec-WebSocket-Protocol` offer because a browser's WebSocket API cannot set a
42
+ * header, and session affinity that has to be readable from the query string
43
+ * for the same reason. The port knows none of it — it is handed a session id
44
+ * and a header bag, the same two things every other transport hands it.
45
+ *
32
46
  * ── Verification status, stated plainly ──────────────────────────────────────
33
47
  * `agentCoreRuntimeHost` is **plain HTTP and is really verified**: it runs the
34
48
  * same host conformance suite as `nodeHost`, over a real socket, in
@@ -61,6 +75,7 @@ const HOST_NAME = 'agentCoreRuntimeHost';
61
75
  /** The runtime's container contract, as constants rather than as scattered literals. */
62
76
  const INVOKE_PATH = '/invocations';
63
77
  const HEALTH_PATH = '/ping';
78
+ const CONVERSATION_PATH = '/ws';
64
79
  const RUNTIME_PORT = 8080;
65
80
  /**
66
81
  * The header the runtime puts the caller's conversation in. Matched
@@ -68,6 +83,34 @@ const RUNTIME_PORT = 8080;
68
83
  * front of the container is free to re-case them.
69
84
  */
70
85
  const SESSION_HEADER = 'X-Amzn-Bedrock-AgentCore-Runtime-Session-Id';
86
+ /**
87
+ * What the `/ws` door caps, as the runtime imposes it — **32KB per frame and a
88
+ * 15-minute idle timeout.**
89
+ *
90
+ * Declared rather than worked around. A 32KB cap hidden inside auto-chunking
91
+ * would have this adapter deciding, for every consumer at once, how a message
92
+ * is split and how the far side knows the last piece landed; a 15-minute idle
93
+ * answered with an invented heartbeat would put bytes on the wire that the
94
+ * consumer's parser never agreed to. Both belong to the protocol above this
95
+ * door, and both are actionable only if the number is visible.
96
+ *
97
+ * `maxFrameBytes` is enforced here, in both directions, because a frame past it
98
+ * would be cut by the front door anyway and a refusal that names the ceiling
99
+ * beats a truncation that does not. `idleMs` is REPORTED: the timeout belongs
100
+ * to what sits in front of this container, and the honest thing is to say so
101
+ * rather than to close a channel the runtime might have kept.
102
+ */
103
+ const CONVERSATION_LIMITS = { maxFrameBytes: 32_768, idleMs: 900_000 };
104
+ /**
105
+ * The subprotocol a browser offers to carry its bearer credential, because the
106
+ * WebSocket API gives it no way to send an `Authorization` header.
107
+ *
108
+ * Two spellings are recognised and both are ordinary browser-expressible ones:
109
+ * `['bearer', '<token>']` (two offers) and `['bearer.<token>']` (one). What is
110
+ * echoed back in the 101 is the word `bearer` and never the token — a
111
+ * credential belongs in a request, not in a response header a proxy may log.
112
+ */
113
+ const BEARER_SUBPROTOCOL = 'bearer';
71
114
  /**
72
115
  * The AgentCore Runtime contract as an {@link HttpWire}.
73
116
  *
@@ -118,8 +161,73 @@ export function agentCoreRuntimeWire(busy) {
118
161
  // 'success' nor 'error' because it is neither: the run stopped to ask a
119
162
  // person, it is stored, and a later call carrying `decision` finishes it.
120
163
  awaiting: (pending) => ({ awaiting: pending, status: 'awaiting' }),
164
+ readConversation: readAgentCoreConversation,
121
165
  };
122
166
  }
167
+ /**
168
+ * The `/ws` handshake, in this runtime's spelling: **header-or-query session
169
+ * affinity, and the bearer subprotocol mapped into headers.**
170
+ *
171
+ * ── Why the query string is read at all ──────────────────────────────────────
172
+ * The same header carries the session on `/invocations`, and it is preferred
173
+ * here too. But the caller this door exists for is a browser, and the browser
174
+ * WebSocket API cannot set a header — so a session id has nowhere to travel
175
+ * except the URL. Both the runtime's header name and the plain `sessionId` are
176
+ * accepted as query parameters, case-insensitively; **the header wins** when
177
+ * both arrive, so a caller that sets both is never surprised by which one the
178
+ * server preferred. That is the same precedence rule the request dialect uses.
179
+ *
180
+ * ── Why the credential becomes a header ──────────────────────────────────────
181
+ * A bearer token offered as a subprotocol is this runtime's spelling of
182
+ * `Authorization`, and a port field spelled the way one vendor spells it is how
183
+ * a port stops being one. So it lands in `headers.authorization` as
184
+ * `Bearer <token>` — the vocabulary every other transport already uses — and
185
+ * the raw `sec-websocket-protocol` header is left in place, so an application
186
+ * that reads the offer itself still can. **Nothing here authenticates
187
+ * anything**: the port never proves who is calling, and a token that arrived is
188
+ * a claim, exactly like the session id beside it.
189
+ *
190
+ * Exported by name so the mapping is inspectable and testable without binding a
191
+ * socket, the same way the body shapes are.
192
+ */
193
+ export function readAgentCoreConversation(facts) {
194
+ const sessionId = headerValue(facts, SESSION_HEADER) ?? queryValue(facts, SESSION_HEADER, 'sessionId');
195
+ const token = bearerFromSubprotocols(facts.headers['sec-websocket-protocol']);
196
+ return {
197
+ ...(sessionId !== undefined && { sessionId }),
198
+ ...(token !== undefined && {
199
+ headers: { authorization: `Bearer ${token}` },
200
+ // Echoed so a client that offered a subprotocol gets one back — the word
201
+ // only. Putting the token in a response header would hand the credential
202
+ // to every proxy on the way home.
203
+ protocol: BEARER_SUBPROTOCOL,
204
+ }),
205
+ };
206
+ }
207
+ /** A query parameter by any of several names, matched case-insensitively. */
208
+ function queryValue(facts, ...names) {
209
+ const wanted = names.map((name) => name.toLowerCase());
210
+ for (const [key, value] of facts.query.entries()) {
211
+ if (wanted.includes(key.toLowerCase()) && value.length > 0)
212
+ return value;
213
+ }
214
+ return undefined;
215
+ }
216
+ /** The token out of a `Sec-WebSocket-Protocol` offer, in either browser spelling. */
217
+ function bearerFromSubprotocols(offered) {
218
+ if (!offered)
219
+ return undefined;
220
+ const parts = offered
221
+ .split(',')
222
+ .map((part) => part.trim())
223
+ .filter((part) => part.length > 0);
224
+ const marker = parts.findIndex((part) => part.toLowerCase() === BEARER_SUBPROTOCOL);
225
+ if (marker >= 0 && parts[marker + 1] !== undefined)
226
+ return parts[marker + 1];
227
+ const prefix = `${BEARER_SUBPROTOCOL}.`;
228
+ const dotted = parts.find((part) => part.toLowerCase().startsWith(prefix));
229
+ return dotted?.slice(prefix.length) || undefined;
230
+ }
123
231
  /**
124
232
  * An `AgentHost` that speaks AgentCore Runtime's container contract.
125
233
  *
@@ -140,6 +248,8 @@ export function agentCoreRuntimeHost(options = {}) {
140
248
  wire: agentCoreRuntimeWire(options.busy),
141
249
  invokePath: INVOKE_PATH,
142
250
  healthPath: HEALTH_PATH,
251
+ conversationPath: options.conversationPath ?? CONVERSATION_PATH,
252
+ conversationLimits: CONVERSATION_LIMITS,
143
253
  // With a caller-owned server this adapter binds nothing, so it must not
144
254
  // invent the contract's port either — the port is whatever the caller
145
255
  // listened on, and passing one anyway is refused by `httpHost` rather than