Open
Description
Problem Statement
Several current features under consideration/design are converging on the idea that we'd like to provide a mechanism to build primative SDK objects that can hook into events of an agent to and adapt behavior (#191, #33).
Today this can be done via the callback_handler
of the agent, however it has a couple flaws:
- The default handler is to print output; adding an explict handler disables this behavior
- Composing multiple handlers together is clunky
- It is currently invoked for all events instead of only the ones that a caller is interesting in
- Arguments passed into the callback_handler are untyped
Proposed Solution
Implement a general purpose hook system which is:
- Composable: A feature can be implemented by subscribing to multiple hooks and callers do not need to provide hooks in a specific order
- N to N: Multiple hooks can subscribe and respond to an event and a hook can subscribe to multiple events
- Hooks can be added externally allowing tools or features to add hooks as needed and allow others to subscribe
Alternatives Solutions
- Continue to use the callback system to intercept these events
- Implement a system on top of async iterators which has similar functionality
Additional Context
No response