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 4 times, most recently 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
@DouweM
Copy link
Collaborator

DouweM commented Sep 1, 2025

@ChuckJonas Yeah let's go back to what you had!

@ryeguard
Copy link

ryeguard commented Sep 9, 2025

Thanks @ChuckJonas for suggesting and looking into this! It's something I'm also interested in using for accessing run.result.new_messages() for persisting to db.

@ChuckJonas ChuckJonas force-pushed the #2398-ag-ui-on-complete-callback branch from 9dab158 to badcea0 Compare September 9, 2025 16:21
@ChuckJonas
Copy link
Contributor Author

@ChuckJonas Yeah let's go back to what you had!

@DouweM I think I correctly reverted these line and I rebased to resolve conflicts. AFIAK the PR should be good (not sure why the CI coverage check is failing, I believe it's unrelated but not familiar enough with the tooling to say for sure).

@DouweM DouweM enabled auto-merge (squash) September 10, 2025 17:48
@DouweM DouweM merged commit d78a3db into pydantic:main Sep 10, 2025
29 checks passed
@DouweM
Copy link
Collaborator

DouweM commented Sep 10, 2025

@ChuckJonas Thanks Charlie!

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
3 participants