Skip to content

AGUI threadId is regenerated on every message, breaking session persistence #1678

Description

@robechon

Description

When running agentcore dev in browser mode (default, without -b), the HTTP proxy
layer generates a new threadId for every AGUI request. This prevents agents from
maintaining multi-turn session state (e.g., via AgentCore Memory STM).

The root cause is in src/cli/operations/dev/web-ui/handlers/invocations.ts,
function handleAguiInvocation:

  const aguiBody = JSON.stringify({
      threadId: randomUUID(),  // ← new UUID on every message
      runId: randomUUID(),
      ...
  });

The sessionId parameter is already available in scope, stable per chat session,
and even returned as an x-session-id response header — but it's never used as the
threadId.

Suggested fix:

  - threadId: randomUUID(),
  + threadId: sessionId ?? randomUUID()

Steps to Reproduce

  1. Create an AGUI agent with "protocol": "AGUI" in agentcore.json
  2. Run agentcore dev (browser mode, no -b flag)
  3. Send two or more messages in the chat UI
  4. Log input_data.thread_id in the agent's request handler

Expected Behavior

The threadId remains stable across messages within the same conversation, allowing
agents to maintain session state.

Actual Behavior

A new random threadId is sent with every message:

  [2026-07-01T10:32:56] thread_id=d5fa1ec3-87c9-4ca3-84ab-498c15608fbe
  [2026-07-01T10:33:05] thread_id=a4fe3ccf-c0cb-4954-9a03-2344efd277ee

Note: TUI mode (agentcore dev -b) does not have this issue — it uses
aguiThreadIdRef in useDevServer.ts which correctly maintains a stable threadId.
The bug is specific to the browser mode HTTP proxy.

CLI Version

0.21.1

Operating System

Linux

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions