Skip to content

Commit fafa463

Browse files
committed
Emit custom event
1 parent 91c5ea4 commit fafa463

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

backend/retrieval_graph/researcher_graph/graph.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from langchain_core.runnables import RunnableConfig
1111
from langgraph.constants import Send
1212
from langgraph.graph import END, START, StateGraph
13+
from langgraph.config import get_stream_writer
1314
from typing_extensions import TypedDict
1415

1516
from backend import retrieval
@@ -67,8 +68,10 @@ async def retrieve_documents(
6768
Returns:
6869
dict[str, list[Document]]: A dictionary with a 'documents' key containing the list of retrieved documents.
6970
"""
71+
writer = get_stream_writer()
7072
with retrieval.make_retriever(config) as retriever:
7173
response = await retriever.ainvoke(state.query, config)
74+
writer({"retrieve_documents": {"index": state.index, "documents": response}})
7275
return {"documents": response}
7376

7477

frontend/app/contexts/GraphContext.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,9 @@ export function GraphProvider({ children }: { children: ReactNode }) {
826826
}
827827
},
828828
onUpdateEvent: handleUpdateEvent,
829+
onCustomEvent: (event) => {
830+
console.log("Custom event", event);
831+
},
829832
onFinish: async (state, meta) => {
830833
setIsStreaming(false);
831834
const currentState = streamStateRef.current;
@@ -1092,7 +1095,7 @@ export function GraphProvider({ children }: { children: ReactNode }) {
10921095
metadata: userId ? { user_id: userId } : undefined,
10931096
streamResumable: true,
10941097
onDisconnect: "continue",
1095-
streamMode: ["messages", "messages-tuple", "updates"],
1098+
streamMode: ["messages-tuple", "custom"],
10961099
},
10971100
);
10981101
} catch (error) {

0 commit comments

Comments
 (0)