#2880·ag-ui

aws-strands: let the host pass `invocationState` to `agent.stream()`

Author: opncowCreated Sep 30, 2026Updated Oct 1, 2026

Package: @ag-ui/aws-strands 0.3.0 (TypeScript), with @strands-agents/sdk 1.17.0

Problem

Hooks and tools running inside a turn have no way to reach the request that started it.

Strands has a slot for exactly this: invocationState, documented as the place for request-scoped context (userId, requestId, traceId), which transport bridges may populate, as A2AExecutor does with a2aRequestContext. The adapter starts every turn with agent.stream(input, { cancelSignal }), so hooks and tools always see {}.

threadAgentConfig and sessionManagerProvider don't close the gap: they run once per thread, and the agent is then reused for later runs.

Use cases

  1. Reporting what a hook did back to the client. A MessageAddedEvent hook persists each message to an external store, and the host wants to announce the store's ids in a CUSTOM event before RUN_FINISHED. The hook needs a per-run object to record them in, one the host can also read.
  2. Per-request identity in tools. A tool calls a downstream API on behalf of the authenticated user. The user id or token is known to the HTTP layer, but not to the tool.
  3. Correlation. Hooks that log or trace want the request id or trace context of the run they belong to, and RunAgentInput.runId for support lookups.

Workaround today

Override StrandsAgent.run, keep a per-run object in an AsyncLocalStorage, and enter it around every next() of the stream, because a generator body runs in the context of each pull. It works, and the adapter uses the same technique internally for its model context, but it depends on run staying overridable and is hard to follow.

Possible shapes

Either would work for the cases above; the maintainers will know which fits the adapter better.

A. A host callback, called once per run, before agent.stream(), with the same RunAgentInput object that was passed to run():

typescript
interface StrandsAgentConfig {
  invocationState?: (input: RunAgentInput) => InvocationState | Promise<InvocationState>
}

The adapter passes the result as agent.stream(input, { cancelSignal, invocationState }), including on resumed runs. With no callback, nothing changes.

B. A reserved key, set by the adapter the way A2AExecutor sets a2aRequestContext, for example invocationState.agUiRunInput. That covers use case 3 with no configuration, but not values the HTTP layer knows and RunAgentInput doesn't (use cases 1 and 2).

Both could also coexist: the reserved key always, and the callback's result merged in.

Happy to send a PR once the shape is agreed.