Skip to content

Can I still check messages even if the API is interrupted due to an error? #3518

@phi-friday

Description

@phi-friday

Question

I am using ag-ui, and on the frontend, I am building a chat UI with @ag-ui/client.
I have several questions about this process, but one of them concerns error handling.

When the API finishes normally, on_complete is called, and since this function takes AgentRunResult as a parameter, it’s easy to get the user’s input and the newly generated LLM messages. I use this callback to store messages in the database.

However, if an error occurs during API execution (especially when client.abortAgent is executed from the frontend), this callback is not triggered. I considered implementing a subclass of AGUIEventStream to handle errors, but I noticed that not all event objects have a result, only certain events have one, and these events appear to be generated from the graph.

Is there a way to collect the ModelRequest and ModelResponse up until just before the error occurs, even in cases of errors? If not, would I need to collect all events and manually construct ModelRequest and ModelResponse from them to achieve this?

Since a function that converts ag-ui messages into ModelMessage is already implemented(AGUIAdapter.load_messages), this isn’t a difficult task. However, I want to avoid handling event branching and collection twic, once on the frontend and again on the backend. I’m asking because there might be a better way that I’m unaware of.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions