-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Problem
I'm working on a multi-agent computer use system for accessibility tech, and I need to execute callbacks at different points in the CodeAgent's execution flow, not just after step completion.
The current step_callbacks only fires after a step has fully completed (in _finalize_step()). For my particular use case, I needed to send the LLM's generated text to a TTS service before code execution. This is because code execution takes some time and I need to queue the TTS asap.
But I can think of a few other cases where having more life cycle hooks would be helpful, like custom code validation logic, human-in-the-loop approval for critical code, etc...
Currently, I'm subclassing CodeAgent and overriding step_stream() to work around this limitation and run callbacks at the right moment in the flow.
Proposed solution
I am not sure if there is a better way to do this, but my patch makes the class look like:
CodeAgent(
tools=[...],
model=...,
step_callbacks=[...], # Keep existing - backward compatible
pre_execution_callbacks=[Callable]
# more hooks?
)
And adds the appropriate hook in step_stream()
Would love to get your feedback here!
Is this not possible with the current options.
No, this is not possible with current step_callbacks, as this only runs callbacks at the end of the step.
Alternatives considered
Couldn't find anything, if I missed something do let me know!
Checklist
- I have searched the existing issues and have not found a similar feature request.
- I have verified that this feature is not already implemented in the latest version.
- I am willing to work on this feature and submit a pull request. (optional)