generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 411
Closed
Labels
enhancementNew feature or requestNew feature or request
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
Status & tasking
As of Jul 11, we've recently added the core system of hooks which allows you to observe a subset of events within the event-loop.
Current Available Events
Event | Description |
---|---|
AgentInitializedEvent | Triggered when an agent has been constructed and finished initialization at the end of Agent.init |
BeforeInvocationEvent | Triggered at the beginning of a new agent request (call, stream_async, or structured_output) |
AfterInvocationEvent | Triggered at the end of an agent request, regardless of success or failure. Uses reverse callback ordering |
MessageAddedEvent | Triggered when a message is added to the agent's conversation history |
Experimental Events
Event | Description |
---|---|
BeforeModelInvocationEvent | Triggered before the model is invoked for inference |
AfterModelInvocationEvent | Triggered after model invocation completes. Uses reverse callback ordering |
BeforeToolInvocationEvent | Triggered before a tool is invoked |
AfterToolInvocationEvent | Triggered after tool invocation completes. Uses reverse callback ordering |
Documentation is currently pending release, but was added via PR #130
Sub-tasks
- Core system of hooks for requests feat: Implement the core system of typed hooks & callbacks #304
- Add before/after tool invocation hooks feat: Add hooks for before/after tool calls + allow hooks to update values #352
- Add model hooks Add Model Invocation Hooks #387
- Add message-based hooks Add hooks for when new messages are appended to the agent's messages #385
- Mark hooks non-experimental Mark hooks as non-experimental #410 (marked a subset)
- Document hooks Add hooks documentation docs#130
- [-]
Mark tool & model hooks as non-experimental- moved to separate issue ([FEATURE] Release tool and model hooks as non-experimental #667) - [-]
Allow exiting the loop via hooks(will be implemented as part of [FEATURE] Support Human-in-the-Loop (HIL) capabilities #204) - [-]
Add data hooks- will add as needed
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request