fix: log the exception of graph execution (#577)
* fix: log the exeption of graph execution * Update src/server/app.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
parent
a265ef47ff
commit
dac0afbca4
|
|
@ -4,7 +4,7 @@
|
||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from typing import Annotated, List, cast
|
from typing import Annotated, Any, List, cast
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
from fastapi import FastAPI, HTTPException, Query
|
from fastapi import FastAPI, HTTPException, Query
|
||||||
|
|
@ -244,25 +244,36 @@ async def _stream_graph_events(
|
||||||
graph_instance, workflow_input, workflow_config, thread_id
|
graph_instance, workflow_input, workflow_config, thread_id
|
||||||
):
|
):
|
||||||
"""Stream events from the graph and process them."""
|
"""Stream events from the graph and process them."""
|
||||||
async for agent, _, event_data in graph_instance.astream(
|
try:
|
||||||
workflow_input,
|
async for agent, _, event_data in graph_instance.astream(
|
||||||
config=workflow_config,
|
workflow_input,
|
||||||
stream_mode=["messages", "updates"],
|
config=workflow_config,
|
||||||
subgraphs=True,
|
stream_mode=["messages", "updates"],
|
||||||
):
|
subgraphs=True,
|
||||||
if isinstance(event_data, dict):
|
):
|
||||||
if "__interrupt__" in event_data:
|
if isinstance(event_data, dict):
|
||||||
yield _create_interrupt_event(thread_id, event_data)
|
if "__interrupt__" in event_data:
|
||||||
continue
|
yield _create_interrupt_event(thread_id, event_data)
|
||||||
|
continue
|
||||||
|
|
||||||
message_chunk, message_metadata = cast(
|
message_chunk, message_metadata = cast(
|
||||||
tuple[BaseMessage, dict[str, any]], event_data
|
tuple[BaseMessage, dict[str, Any]], event_data
|
||||||
|
)
|
||||||
|
|
||||||
|
async for event in _process_message_chunk(
|
||||||
|
message_chunk, message_metadata, thread_id, agent
|
||||||
|
):
|
||||||
|
yield event
|
||||||
|
except Exception as e:
|
||||||
|
logger.exception("Error during graph execution")
|
||||||
|
yield _make_event(
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"thread_id": thread_id,
|
||||||
|
"error": str(e),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
async for event in _process_message_chunk(
|
|
||||||
message_chunk, message_metadata, thread_id, agent
|
|
||||||
):
|
|
||||||
yield event
|
|
||||||
|
|
||||||
|
|
||||||
async def _astream_workflow_generator(
|
async def _astream_workflow_generator(
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue