AAI SDK
    Preparing search index...

    Function useAgentState

    • The agent's projected session state, or null before the first push.

      The counterpart to syncState on the agent: whatever that projection returns is what arrives here — no per-tool result mirroring needed.

      import { useAgentState } from "@alexkroman1/aai-ui";

      type Item = { sku: string; qty: number };

      function Cart() {
      const state = useAgentState<{ cart: Item[] }>();
      return <ul>{state?.cart.map((item) => <li key={item.sku}>{item.qty}</li>)}</ul>;
      }

      Typed by the caller for the same reason useToolResult is: the shape is the author's own projection, which the framework cannot see. It is nullable on purpose — nothing has been pushed before the first tool call, and a UI has to render that moment.

      Type Parameters

      • S = any

      Returns S | null