⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@strands-agent
Copy link
Contributor

Description

When the ./tools directory is empty at Agent initialization and a new tool file is created, the watchdog observer fires an on_created event (not on_modified). The previous implementation only handled on_modified events, causing the first tool added to an empty directory to not be hot-reloaded.

This fix adds on_created handlers to both ToolChangeHandler and MasterChangeHandler classes, ensuring tools are loaded when files are created as well as modified.

Root Cause

The watchdog library fires different events for different file system operations:

  • on_created: When a new file is created
  • on_modified: When an existing file is modified

When adding a file to an empty directory, only on_created fires. The previous code only handled on_modified, so the first tool added to an empty ./tools directory was never detected.

Changes

  1. ToolChangeHandler: Added on_created method that delegates to the same logic as on_modified (via _handle_tool_change)
  2. MasterChangeHandler: Added on_created method that delegates to all registered handlers (via _delegate_event)
  3. Tests: Added comprehensive tests for on_created event handling

Related Issues

Fixes #264

Documentation PR

No documentation changes required - this is a bug fix.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Testing

  • I ran hatch run prepare
  • Added 4 new tests for on_created event handling
  • All 12 watcher tests pass

Checklist

  • I have read the CONTRIBUTING document
  • I have added tests that prove my fix is effective
  • I have updated the documentation accordingly (N/A - bug fix)
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

…ories

When the ./tools directory is empty at Agent initialization and a new tool
file is created, the watchdog observer fires an on_created event (not
on_modified). The previous implementation only handled on_modified events,
causing the first tool added to an empty directory to not be hot-reloaded.

This fix adds on_created handlers to both ToolChangeHandler and
MasterChangeHandler classes, ensuring tools are loaded when files are
created as well as modified.

Fixes strands-agents#264
@codecov
Copy link

codecov bot commented Jan 18, 2026

Codecov Report

❌ Patch coverage is 72.72727% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/strands/tools/watcher.py 72.72% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Hot-reloading fails for first tool when ./tools directory is empty at Agent initialization

1 participant