feat: add --reload_agents flag to watch agent files for changes#304
feat: add --reload_agents flag to watch agent files for changes#304nuthalapativarun wants to merge 5 commits into
Conversation
|
Hi @kalenkevich — I've addressed all the review comments (replaced |
|
Hi @kalenkevich — this PR is approved and mergeable. Could you merge when you get a chance? Thanks! |
When --reload_agents is passed to 'npx adk web' or 'npx adk api_server', AgentLoader watches the agents directory for file changes using the Node.js built-in fs.watch API. When a JS/TS agent file is modified, the in-memory agent cache is invalidated so that the next HTTP request triggers a fresh load from disk. This matches the --reload_agents behaviour in adk-python and removes the need to restart the dev server after editing an agent file. Closes google#196
- Replace console.log/warn with AdkLogger in AgentLoader.startWatching - Update RELOAD_AGENTS_OPTION description to note new run required - Add --reload_agents option to the run command - Add onAgentFileReloaded callback to runInteractively so agent hot-reload preserves the existing session when triggered from the run command
f685432 to
8640f0c
Compare
|
Rebased on current main — the branch is now up to date and ready to merge. Thanks again for the approval @kalenkevich! |
ESLint (@typescript-eslint/no-explicit-any) rejects the bare `as any` casts that were merged from main. Replace them with typed alternatives: - basic_llm_request_processor_test.ts: use Modality.AUDIO enum value instead of 'AUDIO' as any - code_execution_utils_test.ts: use `as unknown as Content` for the tests that intentionally omit required fields This resolves the Windows-only lint failure on CI (PowerShell expands the **/**.ts glob more broadly than bash, exposing these errors). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Found and fixed the Windows CI failure. The issue was not in the hot-reload implementation itself, but in test files that were merged in from main (#372\ and #374) and contain bare \�s any\ casts that ESLint rejects. Root cause: On Linux/macOS CI, bash passes */**.ts\ to ESLint as a literal string (bash *\ requires globstar). ESLint handles the glob internally and evaluates it from the repo root, but the files happen to be scanned in a different order or subset. On Windows CI with PowerShell, the shell expands **/**.ts\ itself, producing a different (larger) file list that includes the test files — exposing the 3 @typescript-eslint/no-explicit-any\ errors. Fixes applied:
All tests still pass locally. |
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
Testing Plan
Unit Tests:
Manual End-to-End (E2E) Tests:
npx adk web --reload_agents my-agents/instructionstring)[AgentLoader] Detected change in agent.ts, reloading agents...Without
--reload_agents(defaultfalse), behaviour is unchanged — agents are loaded once at startup and cached for the process lifetime.Checklist
Additional context
Adds
--reload_agents [boolean]option to bothnpx adk webandnpx adk api_server, matching the--reload_agentsflag in adk-python.Implementation:
AgentLoaderaccepts a newwatchForChangesconstructor parameter (defaultfalse).preloadAgents()call, ifwatchForChangesistrue, afs.watchwatcher is started on the agents directory using the Node.js built-infsmodule (no new dependencies).invalidateAll()disposes all cachedAgentFileinstances and resetsagentsAlreadyPreloaded = false, so the next request triggers a fresh scan.disposeAll()closes the watcher to prevent resource leaks on shutdown.AdkApiServerforwards thereloadAgentsoption from server config toAgentLoader.