-
Notifications
You must be signed in to change notification settings - Fork 0
Enable writable hooks for tool and result modification #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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
|
/strands ensure your conforming to the PR and test standards |
|
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. |
| } | ||
| readonly tool: Tool | undefined | ||
| readonly result: ToolResultBlock | ||
| result: ToolResultBlock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separate out writable properties by moving them lower below the readonly properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Moved writable result property below readonly properties.
|
/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
7cb5147 to
828f44d
Compare
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