#2881·ag-ui

langgraph (python): let LangGraphAgent emit state keys outside the graph's output schema

Author: BenTaylorDevCreated Sep 30, 2026Updated Oct 1, 2026
Labelsenhancement

Summary

ag_ui_langgraph.LangGraphAgent filters every STATE_SNAPSHOT down to the keys in the graph's output schema. There is no way to emit a state key that is outside that schema. If a graph uses StateGraph(State, output_schema=Output) and Output is narrower than State, the frontend never sees the other state keys.

CopilotKit added a config["schema_keys"] option to its LangGraphAGUIAgent subclass in CopilotKit/CopilotKit#7537 (reported in CopilotKit/CopilotKit#3204). Users of the plain LangGraphAgent from this package still have no option. This issue proposes the same behavior here.

Where

At 4c972f82b51988d94c8f7b7d6b56bb5338c9be7f, in integrations/langgraph/python/ag_ui_langgraph/agent.py:

  • get_schema_keys() (line 2556) builds the buckets only from graph introspection plus constant_schema_keys (['messages', 'tools'], line 695). It does not read self.config.
  • get_state_snapshot() (line 3164) keeps only [*DEFAULT_SCHEMA_KEYS, *schema_keys["output"]].

Reproduction

python
from typing import Any, List
from typing_extensions import TypedDict
from langgraph.graph import StateGraph, START, END
from langgraph.checkpoint.memory import MemorySaver
from ag_ui_langgraph import LangGraphAgent

class State(TypedDict):
    messages: List[Any]
    steps: List[str]

class Out(TypedDict):
    messages: List[Any]

b = StateGraph(State, output_schema=Out)
b.add_node("n", lambda s: {"steps": ["research", "write"]})
b.add_edge(START, "n"); b.add_edge("n", END)
g = b.compile(checkpointer=MemorySaver())
cfg = {"configurable": {"thread_id": "t"}}
g.invoke({"messages": []}, cfg)

agent = LangGraphAgent(name="demo", graph=g)
agent.active_run = {"schema_keys": agent.get_schema_keys(cfg)}
print(agent.get_state_snapshot(dict(g.get_state(cfg).values)))
# {'messages': []}   <- 'steps' is in the graph state but never reaches the frontend

Proposed behavior

Match what CopilotKit shipped in #7537, so that both layers behave the same:

  • Read config["schema_keys"] once, in __init__, as a dict with any of the input, output, config and context buckets. Each bucket is a list of strings.
  • In get_schema_keys(), append the configured keys to the derived keys. Never replace or drop a derived key, and do not add duplicates.
  • Apply the configured keys on the introspection-failure fallback path too.
  • If schema_keys is malformed, or a bucket name is unknown (for example outputs), log a warning and ignore that part. Do not raise: today a stray schema_keys is ignored, so raising would stop existing apps from starting after an upgrade.
  • clone() already passes self.config through, so the keys survive the per-request clone.

When this ships, CopilotKit's subclass override can be reduced or removed.