Enable writable hooks for tool and result modification - #9
Open
github-actions[bot] wants to merge 12 commits into
Open
Enable writable hooks for tool and result modification#9github-actions[bot] wants to merge 12 commits into
github-actions[bot] wants to merge 12 commits into
Conversation
- Remove readonly modifiers from BeforeToolCallEvent.tool and toolUse - Remove readonly modifier from AfterToolCallEvent.result - Update agent to use modified values after yielding hook events - Add comprehensive tests for writable hook properties - Support tool replacement and toolUse modification in hooks - Support result modification in AfterToolCallEvent hooks Closes #8
Owner
|
/strands ensure your conforming to the PR and test standards |
Author
|
I've reviewed the implementation against PR.md and TESTING.md standards and made the following updates: PR Description ✅Updated to conform to PR.md guidelines:
Test Code ✅Verified against TESTING.md standards:
SummaryAll standards are now met. The implementation is ready for review. |
zastrowm
requested changes
Dec 5, 2025
| } | ||
| readonly tool: Tool | undefined | ||
| readonly result: ToolResultBlock | ||
| result: ToolResultBlock |
Owner
There was a problem hiding this comment.
Separate out writable properties by moving them lower below the readonly properties.
Author
There was a problem hiding this comment.
Done. Moved writable result property below readonly properties.
Owner
|
/strands Update in response to comments. |
- Add writable toolInput property to BeforeToolCallEvent - Keep toolUse readonly (only tool and toolInput are writable) - Remove toolUse.name re-lookup logic from agent - Make AfterToolCallEvent.error writable - Use createMockTool helper in tests per code review - Add test for writable error property
zastrowm
force-pushed
the
main
branch
2 times, most recently
from
December 8, 2025 17:08
7cb5147 to
828f44d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR implements writable hooks for the TypeScript SDK, allowing hook callbacks to modify event properties and change agent behavior, achieving parity with the Python SDK.
Changes
Event Classes (src/hooks/events.ts)
readonlymodifiers fromBeforeToolCallEvent.toolandBeforeToolCallEvent.toolUsereadonlymodifier fromAfterToolCallEvent.resultAgent Integration (src/agent/agent.ts)
toolandtoolUsefromBeforeToolCallEventafter yieldingtoolUse.namewas modifiedresultfromAfterToolCallEventafter yieldingTests
src/agent/__tests__/agent.hook.test.ts:src/hooks/__tests__/events.test.tsto verify properties are writableImplementation Notes
AfterModelCallEvent.retryModelCall(already writable)_can_write()mechanismTesting
All acceptance criteria from #8 verified:
BeforeToolCallEvent.toolis writableBeforeToolCallEvent.toolUseis writableAfterToolCallEvent.resultis writableResolves: #8