πŸ”„ Hot Reload

Live development without restarts

File Watcher Agent Protection Tool Hot-Load
πŸ”„

Zero-Restart Development

Modify DevDuck's code while it's running. Changes apply instantly without losing context. Protected during agent execution.

πŸ”„ How It Works

DevDuck watches its own source file and automatically reloads when changes are detected.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        Hot Reload System                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                     β”‚
β”‚   File Watcher Thread                                               β”‚
β”‚   β”‚                                                                 β”‚
β”‚   β”œβ”€β”€ Every 1 second:                                            β”‚
β”‚   β”‚   └── Check devduck/__init__.py mtime                           β”‚
β”‚   β”‚                                                                 β”‚
β”‚   β”œβ”€β”€ Change Detected?                                            β”‚
β”‚   β”‚   β”‚                                                             β”‚
β”‚   β”‚   β”œβ”€β”€ Agent Executing?                                        β”‚
β”‚   β”‚   β”‚   └── Set _reload_pending = True                            β”‚
β”‚   β”‚   β”‚   └── Wait for agent to finish                              β”‚
β”‚   β”‚   β”‚                                                             β”‚
β”‚   β”‚   └── Agent Idle?                                               β”‚
β”‚   β”‚       └── Trigger os.execv() β†’ Full Process Restart           β”‚
β”‚   β”‚                                                                 β”‚
β”‚   └── 3 second debounce to prevent rapid reloads                  β”‚
β”‚                                                                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

⚑ Live Demo

devduck β€” hot reload
πŸ¦† # DevDuck running normally...
# You edit devduck/__init__.py in another terminal
πŸ¦† Detected changes in __init__.py!
πŸ¦† Restarting process with fresh code...
πŸ¦† DevDuck
πŸ“ Logs: /tmp/devduck/logs
πŸ¦† βœ“ Zenoh peer: hostname-abc123
πŸ¦† # Ready with your changes!

During Agent Execution

devduck β€” protected reload
πŸ¦† run a complex task...
πŸ› οΈ Tool #1: shell
# You edit code while agent is working...
πŸ¦† Agent is currently executing - reload will trigger after completion
βœ… Tool completed successfully
[Agent finishes response]
πŸ¦† Agent finished - triggering pending hot-reload...
πŸ¦† Restarting process with fresh code...

πŸ›‘οΈ Agent Protection

⚠️ Safe Reload Mechanism

Hot reload never interrupts a running agent. When code changes are detected during execution:

  • _reload_pending flag is set
  • Agent continues processing normally
  • After agent completes, reload triggers automatically
  • No lost work, no corrupted state

πŸ”§ Tool Hot Loading

Create new tools by saving .py files to the ./tools/ directory.

# Create ./tools/my_tool.py
from strands import tool

@tool
def my_custom_tool(param: str) -> dict:
    """My custom tool description."""
    return {
        "status": "success",
        "content": [{"text": f"Processed: {param}"}]
    }

# Save the file β†’ Tool is immediately available!
# No restart needed

Disable Tool Auto-Loading

# Disable auto-loading tools from ./tools/ directory
export DEVDUCK_LOAD_TOOLS_FROM_DIR=false
devduck

✨ Features

πŸ‘οΈ

File Watcher

Background thread monitors source file every second for changes.

⏱️

Debounce

3-second debounce prevents rapid reloads during file saves.

πŸ›‘οΈ

Execution Protection

Never interrupts running agentβ€”waits for completion.

πŸ”„

Full Restart

Uses os.execv() for clean process restart with fresh code.

πŸ”§

Tool Directory

Drop .py files in ./tools/ for instant tool availability.

πŸ“Š

Status Tracking

Check watcher status via devduck.status()["file_watcher"].

🐍 Python API

import devduck

# Check file watcher status
status = devduck.status()
print(status["file_watcher"])
# {
#     "enabled": True,
#     "watching": "/path/to/devduck/__init__.py"
# }

# Manually trigger hot reload
devduck.hot_reload()

# Full restart (re-initializes everything)
devduck.restart()

βš™οΈ Configuration

Variable Default Description
DEVDUCK_LOAD_TOOLS_FROM_DIR true Auto-load tools from ./tools/ directory