Skip to content

How to handle follow-up actions when the agent is aborted during a tool invocation. #3461

@phi-friday

Description

@phi-friday

Question

First, thank you for providing the ag_ui integration feature—I’m using it very well.

However, while recently testing the abort function, I encountered the following error:

data: {"type":"RUN_STARTED","threadId":"553632f0-09a6-4053-8c95-61b85b03a1b9","runId":"8735d904-7b17-4adc-b7fe-3dca71bf0fb8"}

data: {"type":"RUN_ERROR","message":"status_code: 400, model_name: gpt-4, body: {'message': 'No tool output found for function call call_tYFQBQ4RTmvnbPkV40KWCKCh.', 'type': 'invalid_request_error', 'param': 'input', 'code': None}"}

Right after the error occurred, agent.messages is as follows.

[
  {
    "id": "019a9502-57fb-7209-a94f-c47d2b2f3647",
    "role": "user",
    "content": "test"
  },
  {
    "id": "d9d864d5-3adb-4c92-b42d-489b65e68639",
    "role": "assistant",
    "toolCalls": [
      {
        "id": "call_tYFQBQ4RTmvnbPkV40KWCKCh",
        "type": "function",
        "function": {
          "name": "retrieve_documents",
          "arguments": "{\n  \"search_query\": \"test\"\n}"
        }
      }
    ]
  },
  {
    "id": "019a9502-d49b-7159-bfc5-dc3142d2255b",
    "role": "user",
    "content": "test"
  }
]

I executed abort while a tool was running.
After it was aborted, when I entered a new message, there was still a message indicating a tool had been called, but there was no result from the tool in the message, so all subsequent workflows seemed to fail.

It seems to be related to this issue #2050.
Is there a good way to resolve this?

For a new message, is the best approach to check whether a tool call has results; and if not, to explicitly enter a failure result?
If this is an issue that should be handled on the frontend rather than by pydantic-ai, just let me know.

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