Skip to content

Conversation

ChuckJonas
Copy link
Contributor

@ChuckJonas ChuckJonas commented Aug 5, 2025

Fixes #2398

@DouweM DouweM changed the title #2398 ag-ui on_complete callback Add on_complete callback to AG-UI functions to get access to AgentRunResult Aug 6, 2025
@DouweM DouweM self-assigned this Aug 6, 2025
@ChuckJonas ChuckJonas force-pushed the #2398-ag-ui-on-complete-callback branch 3 times, most recently from 7100b97 to a3ad970 Compare August 7, 2025 02:19
@ChuckJonas ChuckJonas force-pushed the #2398-ag-ui-on-complete-callback branch from a3ad970 to 73af2b7 Compare August 7, 2025 02:28
if _utils.is_async_callable(on_complete):
await on_complete(run)
else:
await _utils.run_in_executor(on_complete, run)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DouweM not sure this is what you meant...

if _utils.is_async_callable(on_complete):
    await on_complete(run)

"None" is not awaitable
"None" is incompatible with protocol "Awaitable[_T_co@Awaitable]"
"await" is not present

And

else:
     await _utils.run_in_executor(on_complete, run)

Is saying it's unreachable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, I just ran in my project with both a sync and async callback and it seems to work as expected... Maybe just a type issue?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, I'm seeing the same, looks like is_async_callable's TypeIs return annotation is subtly broken... I'm Ok with going back to what you had in that case, running this in an executor (i.e. a thread) seems less important than doing so for tools anyway.

Copy link

This PR is stale, and will be closed in 3 days if no reply is received.

@github-actions github-actions bot added the Stale label Aug 20, 2025
@ChuckJonas
Copy link
Contributor Author

ChuckJonas commented Aug 20, 2025

This PR is stale, and will be closed in 3 days if no reply is received.

@DouweM is this still a priority?

If the type error is blocking, I can go ahead and revert back to:

if inspect.iscoroutinefunction(on_complete):
         await on_complete(completed_run)
     else:
         on_complete(completed_run)

@github-actions github-actions bot removed the Stale label Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Callback/Middleware for responses on run_ag_ui
2 participants