langgraph (python): let LangGraphAgent emit state keys outside the graph's output schema
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 plusconstant_schema_keys(['messages', 'tools'], line 695). It does not readself.config.get_state_snapshot()(line 3164) keeps only[*DEFAULT_SCHEMA_KEYS, *schema_keys["output"]].
Reproduction
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 frontendProposed 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 theinput,output,configandcontextbuckets. 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_keysis malformed, or a bucket name is unknown (for exampleoutputs), log a warning and ignore that part. Do not raise: today a strayschema_keysis ignored, so raising would stop existing apps from starting after an upgrade. clone()already passesself.configthrough, so the keys survive the per-request clone.
When this ships, CopilotKit's subclass override can be reduced or removed.
Source: ag-ui-protocol/ag-ui