Skip to content

Commit eae9f11

Browse files
authored
fix: dump safe json whenever string is required in lg-python fastapi (#648)
* fix: dump safe json whenever string is required in lg-python fastapi * chore: release agui langgraph fastapi 0.0.19
1 parent b5df850 commit eae9f11

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

integrations/langgraph/python/ag_ui_langgraph/agent.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ async def _handle_stream_events(self, input: RunAgentInput) -> AsyncGenerator[st
235235
CustomEvent(
236236
type=EventType.CUSTOM,
237237
name=LangGraphEventTypes.OnInterrupt.value,
238-
value=json.dumps(interrupt.value, default=json_safe_stringify) if not isinstance(interrupt.value, str) else interrupt.value,
238+
value=dump_json_safe(interrupt.value),
239239
raw_event=interrupt,
240240
)
241241
)
@@ -311,7 +311,7 @@ async def prepare_stream(self, input: RunAgentInput, agent_state: State, config:
311311
CustomEvent(
312312
type=EventType.CUSTOM,
313313
name=LangGraphEventTypes.OnInterrupt.value,
314-
value=json.dumps(interrupt.value) if not isinstance(interrupt.value, str) else interrupt.value,
314+
value=dump_json_safe(interrupt.value),
315315
raw_event=interrupt,
316316
)
317317
)
@@ -741,7 +741,7 @@ async def _handle_single_event(self, event: Any, state: State) -> AsyncGenerator
741741
ToolCallArgsEvent(
742742
type=EventType.TOOL_CALL_ARGS,
743743
tool_call_id=tool_call_output.tool_call_id,
744-
delta=json.dumps(event["data"]["input"]),
744+
delta=dump_json_safe(event["data"]["input"]),
745745
raw_event=event
746746
)
747747
)
@@ -758,7 +758,7 @@ async def _handle_single_event(self, event: Any, state: State) -> AsyncGenerator
758758
type=EventType.TOOL_CALL_RESULT,
759759
tool_call_id=tool_call_output.tool_call_id,
760760
message_id=str(uuid.uuid4()),
761-
content=tool_call_output.content,
761+
content=dump_json_safe(tool_call_output.content),
762762
role="tool"
763763
)
764764
)
@@ -917,3 +917,7 @@ def get_stream_kwargs(
917917
kwargs.update(fork)
918918

919919
return kwargs
920+
921+
922+
def dump_json_safe(value):
923+
return json.dumps(value, default=json_safe_stringify) if not isinstance(value, str) else value

integrations/langgraph/python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "ag-ui-langgraph"
3-
version = "0.0.18a0"
3+
version = "0.0.19"
44
description = "Implementation of the AG-UI protocol for LangGraph."
55
authors = ["Ran Shem Tov <[email protected]>"]
66
readme = "README.md"

0 commit comments

Comments
 (0)