Skip to content
Limited timeStarter is now $9 a month instead of $20.See plans
charmotion

Syncing LangGraph Agent States with an Animated Rive Avatar

By the Charmotion team · Updated · How we write guides

Cover illustration for the guide: Syncing LangGraph Agent States with an Animated Rive Avatar, with Charmotion demo characters

Map each LangGraph agent node state to one avatar mood, then write that mood into a Rive state machine input as the graph streams. Use the updates stream mode, because each event names the node that produced it, and add a short hold time so fast steps do not make the avatar flicker.

Key takeaways

  • Map every LangGraph node to one avatar mood before you write any front-end code.
  • The updates stream mode reports which node just ran, so the avatar follows the graph rather than guessing.
  • Put a hold time and a priority rule between the stream and the Rive input to stop flicker.
  • Test the mapping by replaying a recorded run before you connect a live model.

Already have a character or logo? See examples in real app screens: splash, onboarding, loading and empty-state screens, with the animation that plays in each.

What does a LangGraph agent send to the front end?

The core task is how to sync LangGraph agent node states with an animated Rive avatar, and it starts with what the graph actually sends to the browser. A LangGraph agent is a graph. A shared state object moves through nodes, which are functions that read the state and return an update, and edges, which decide what runs next. LangGraph applies each node's partial update through the reducer defined for each channel of the state.

For a front end, the question is how much of that state you receive and when. LangGraph's streaming docs describe three modes you can ask for:

Stream modeWhat arrives after each stepUseful for the avatar
valuesThe full graph stateRebuilding the whole UI from a snapshot
updatesOnly the changes each node returnedSwitching moods on the node that just ran
debugEach output with the node name and the full stateTracing during development

For an avatar, updates is usually the right choice. Each event is keyed by the node that produced it, so you can change the mood on the node name without parsing the whole state. Use values when the avatar also needs a field from the state, such as a status flag, and you prefer reading a complete snapshot on every step.

The graph execution pattern in LangChain's frontend docs renders one card per named node, showing that node's status and streaming its content as the run progresses. An avatar can follow the same model: one mood per node, switched as each node starts and finishes. If your agent also streams chat replies, the text side of that work is covered in animating a chat avatar from streaming events.

Which LangGraph nodes should map to which avatar moods?

Write the table before any code. List every node, the mood the avatar shows while that node runs and the number that mood uses in your Rive file. Most agents need six to eight distinct moods, and a longer list usually means nodes that could share one.

NodeMood while it runsMood number
classify_intentthinking3
search_toolsloading5
draft_replytalking7
ask_user (interrupt)attention9
wait_for_userlistening6
finalizehappy1
handle_errorsad4

The numbers above follow a common layout: idle 0, happy 1, wave 2, thinking 3, sad 4, loading 5, listening 6, talking 7, sleeping 8 and attention 9. Your Rive file may use other numbers, so keep the mapping in one place and change it there. Idle stays the default between runs.

const IDLE = 0;
const MOOD_BY_NODE: Record<string, number> = {
  classify_intent: 3,
  search_tools: 5,
  draft_reply: 7,
  ask_user: 9,
  wait_for_user: 6,
  finalize: 1,
  handle_error: 4,
};

Notice that ask_user is the node that pauses for a human answer. Showing attention there tells the user that the agent needs them, which a generic spinner does not. Node names in the map must match the graph exactly. A typo fails quietly, so log any update whose node is missing from the map during development.

How do you connect a React app to a running graph?

The LangGraph SDK includes a React hook, useStream from @langchain/langgraph-sdk/react. It handles streaming, state management and branching for React apps. You pass it the URL of the graph's API and the assistant to run, and it returns a thread object with messages, a loading flag and a submit function.

When the avatar only needs to show whether the agent is busy, the loading flag is enough. Show thinking while a run is in progress and idle when it stops:

import { useStream } from '@langchain/langgraph-sdk/react';

export function AgentAvatar({ apiUrl, assistantId }: { apiUrl: string; assistantId: string }) {
  const thread = useStream({ apiUrl, assistantId, messagesKey: 'messages' });
  const mood = thread.isLoading ? 3 : 0;
  return <RiveAvatar mood={mood} />;
}

For node-level moods you need the per-node events, not only the loading flag. Read the updates stream from the client or from your own API route. The event payload fields for the newer v3 event streaming API should be checked in the SDK reference for the version you install before you build on them. Voice agents that report their own mode follow a similar idea; see the ElevenLabs agent avatar with onModeChange guide.

How do you drive a Rive state machine from node events?

On the Rive side, the file needs a value the state machine reads. In the Rive editor that is a number input on the state machine. With data binding, it is a number property on a view model that your app writes. Data binding can drive any property from live data in an app, and it is the route Rive's runtime docs favor for new code. The React runtime's useStateMachineInput hook is marked deprecated in favor of newer data binding hooks, so check the hook names in the runtime docs for your platform before you wire anything.

Keep every Rive call in one function: a bridge that takes a node name and writes the mood. The rest of the app then deals only with node names, and the animation can change without touching the agent.

type SetMood = (mood: number) => void;

export function createMoodBridge(setMood: SetMood) {
  let current = -1;
  return function apply(node: string) {
    const next = MOOD_BY_NODE[node];
    if (next === undefined || next === current) return;
    current = next;
    setMood(next);
  };
}

Any .riv file that exposes a number property named mood, either on a view model or as a number input on the state machine, can be driven this way. Moods blend into each other, so a change from thinking to loading animates rather than cuts. For talking moods that follow generated speech, the choice between lip-sync and amplitude matters; see lip-sync vs amplitude for a talking avatar. For the state machine basics, read Rive state machine inputs and moods.

How do you stop the avatar flickering between fast nodes?

Agent nodes can finish in a few milliseconds, and a mood that changes on every event looks like noise. Three rules fix most of it.

  1. Hold each mood for a minimum time. Keep short moods such as thinking on screen for at least 600 ms, and hold sad and happy a little longer so the user can read them. Queue later updates behind the hold instead of dropping them, so the last mood always appears.
  2. Let important moods win. An error or an interrupt should replace what is showing at once. A routine node finishing a moment later should not replace an error.
  3. Fall back to idle after a quiet period. If no node event arrives for a set time after the last one and the run has not ended, show listening or idle, so the avatar does not freeze in a mid-action pose.

The hold time is a product choice. Test it on slow connections, where events arrive in bursts, rather than on a fast laptop where every node looks instant.

How do you test the sync without calling a model?

Record one real run, then replay it through the same bridge. Save each update with the time it arrived, and feed the list to a timer. The replay tests the mapping, the hold times and the error path without model calls, and it behaves the same way every time.

const recorded = [
  { node: 'classify_intent', at: 0 },
  { node: 'search_tools', at: 400 },
  { node: 'draft_reply', at: 2100 },
  { node: 'finalize', at: 3900 },
];

const apply = createMoodBridge(setMood);
for (const step of recorded) {
  setTimeout(() => apply(step.node), step.at);
}

Record a second run that fails on purpose, then check that the sad mood appears and that the avatar returns to idle afterward. Keep both recordings in your test fixtures. When a node is renamed in the graph, the replay shows the missing mood at once, which is the signal you want.

What should the avatar not try to show?

  • Not every token. A mood change for each streamed word makes the character twitch. Tie moods to nodes, and let the text itself show the streaming.
  • Not a progress bar. An avatar shows what kind of work is happening. If the user needs a percentage or an estimated wait, show it as text next to the avatar.
  • Not the only status. Announce important changes, such as an error, in text that screen readers can read, and keep motion gentle when the user has reduced motion turned on.

Check plan limits before you ship. On Rive's Free plan, exported files play a Rive splash screen, and paid plans export without it. Current plan details are on Rive's pricing page and in is Rive free. If you need a finished character rather than a hand-built state machine, Charmotion turns one character image into a Rive file with the mood input described here; see AI chatbot avatar animation.

How to sync a LangGraph agent with an animated Rive avatar

  1. Map nodes to moods. List every LangGraph node and assign the avatar mood it should show while running, using the mood numbers in your Rive file.
  2. Stream node updates. Ask the graph for the updates stream mode so each event is keyed by the node that produced it.
  3. Connect the React front end. Use useStream from @langchain/langgraph-sdk/react for busy state, and read node-level updates for per-node moods.
  4. Drive the Rive input. Write a bridge function that takes a node name and sets the mood number on the Rive state machine input or data-bound property.
  5. Add hold times and priority. Hold each mood for a minimum time, let errors and interrupts replace the current mood, and fall back to idle after a quiet period.
  6. Replay a recorded run. Save one real run with timestamps, replay it through the bridge, and check the mapping, hold times and error path without calling a model.

Frequently asked questions

Do I need LangGraph hosting to use this pattern?

No particular hosting setup is required. The avatar only reads a stream of node events, so the graph can run on LangGraph's own deployment or on a server you run. Check LangGraph's documentation for current hosting options and costs as of December 2026 before you plan a budget.

Does the Rive file need to know anything about LangGraph?

No. The .riv file only exposes a mood number and, optionally, a boolean that hides the small accents such as sparkles. Your code maps node names to numbers, so you can change the agent without re-exporting the animation, and you can swap the character without touching the agent.

Can this work outside React?

Yes. Stream events are plain JSON, so any client can read them. Keep the same node-to-mood table and pass the mood number into the Rive runtime for your platform, such as the Apple, Android or Flutter runtime. The bridge pattern stays the same; only the code that reads the stream changes.

Does the free Rive plan work for a product I ship?

Exported files on the free plan play a Rive splash screen, while paid plans export without one. Read the Rive pricing page and the guide on whether Rive is free for current details, and check them again before launch, since prices change.

Sources

Related guides