Skip to content

Commit 7135b39

Browse files
committed
feat(langgraph-py): properly read forwarded props
1 parent 208e007 commit 7135b39

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

typescript-sdk/integrations/langgraph/python/ag_ui_langgraph/agent.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
get_stream_payload_input,
2727
langchain_messages_to_agui,
2828
resolve_reasoning_content,
29-
resolve_message_content
29+
resolve_message_content,
30+
camel_to_snake
3031
)
3132

3233
from ag_ui.core import (
@@ -88,8 +89,13 @@ def __init__(self, *, name: str, graph: CompiledStateGraph, description: Optiona
8889
def _dispatch_event(self, event: ProcessedEvents) -> str:
8990
return event # Fallback if no encoder
9091

91-
async def run(self, input_data: RunAgentInput) -> AsyncGenerator[str, None]:
92-
async for event_str in self._handle_stream_events(input_data):
92+
async def run(self, input: RunAgentInput) -> AsyncGenerator[str, None]:
93+
forwarded_props = {}
94+
if hasattr(input, "forwarded_props") and input.forwarded_props:
95+
forwarded_props = {
96+
camel_to_snake(k): v for k, v in input.forwarded_props.items()
97+
}
98+
async for event_str in self._handle_stream_events(input.copy(update={"forwarded_props": forwarded_props})):
9399
yield event_str
94100

95101
async def _handle_stream_events(self, input: RunAgentInput) -> AsyncGenerator[str, None]:
@@ -304,7 +310,7 @@ async def prepare_stream(self, input: RunAgentInput, agent_state: State, config:
304310
state=state,
305311
schema_keys=self.active_run["schema_keys"],
306312
)
307-
stream_input = {**forwarded_props, **payload_input}
313+
stream_input = {**forwarded_props, **payload_input} if payload_input else None
308314

309315
return {
310316
"stream": self.graph.astream_events(stream_input, config, version="v2"),

typescript-sdk/integrations/langgraph/python/ag_ui_langgraph/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import re
23
from typing import List, Any, Dict, Union
34

45
from langchain_core.messages import BaseMessage, HumanMessage, AIMessage, SystemMessage, ToolMessage
@@ -173,3 +174,6 @@ def resolve_message_content(content: Any) -> str | None:
173174
return content_text
174175

175176
return None
177+
178+
def camel_to_snake(name):
179+
return re.sub(r'(?<!^)(?=[A-Z])', '_', name).lower()

0 commit comments

Comments
 (0)