Skip to content

feat: add --reload_agents flag to watch agent files for changes#304

Open
nuthalapativarun wants to merge 5 commits into
google:mainfrom
nuthalapativarun:feat/hot-reload-agents
Open

feat: add --reload_agents flag to watch agent files for changes#304
nuthalapativarun wants to merge 5 commits into
google:mainfrom
nuthalapativarun:feat/hot-reload-agents

Conversation

@nuthalapativarun
Copy link
Copy Markdown
Contributor

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.
Test Files  112 passed (112)
Tests  1248 passed (1248)

Manual End-to-End (E2E) Tests:

  1. Start the dev server with npx adk web --reload_agents my-agents/
  2. Edit an agent file (e.g. change the instruction string)
  3. Send a new message — the updated agent is loaded automatically without restarting the server
  4. Console shows: [AgentLoader] Detected change in agent.ts, reloading agents...

Without --reload_agents (default false), behaviour is unchanged — agents are loaded once at startup and cached for the process lifetime.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

Adds --reload_agents [boolean] option to both npx adk web and npx adk api_server, matching the --reload_agents flag in adk-python.

Implementation:

  • AgentLoader accepts a new watchForChanges constructor parameter (default false).
  • After the initial preloadAgents() call, if watchForChanges is true, a fs.watch watcher is started on the agents directory using the Node.js built-in fs module (no new dependencies).
  • When a JS/TS file change is detected, invalidateAll() disposes all cached AgentFile instances and resets agentsAlreadyPreloaded = false, so the next request triggers a fresh scan.
  • disposeAll() closes the watcher to prevent resource leaks on shutdown.
  • AdkApiServer forwards the reloadAgents option from server config to AgentLoader.

Copy link
Copy Markdown
Collaborator

@kalenkevich kalenkevich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Comment thread dev/src/utils/agent_loader.ts Outdated
Comment thread dev/src/utils/agent_loader.ts Outdated
Comment thread dev/src/cli/cli.ts
Comment thread dev/src/cli/cli.ts Outdated
@nuthalapativarun
Copy link
Copy Markdown
Contributor Author

Hi @kalenkevich — I've addressed all the review comments (replaced console.log/console.warn with logger, added --reload_agents to the run command with onAgentFileReloaded callback, updated the description). Could you take another look when you get a chance? Thanks!

@nuthalapativarun
Copy link
Copy Markdown
Contributor Author

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
@nuthalapativarun nuthalapativarun force-pushed the feat/hot-reload-agents branch from f685432 to 8640f0c Compare May 26, 2026 05:00
@nuthalapativarun
Copy link
Copy Markdown
Contributor Author

Rebased on current main — the branch is now up to date and ready to merge. Thanks again for the approval @kalenkevich!

kalenkevich and others added 3 commits May 27, 2026 12:55
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>
@nuthalapativarun
Copy link
Copy Markdown
Contributor Author

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:

  • \core/test/agents/processors/basic_llm_request_processor_test.ts: imported \Modality\ from @google/genai\ and replaced 'AUDIO' as any\ with \Modality.AUDIO\
  • \core/test/code_executors/code_execution_utils_test.ts: imported \Content\ from @google/genai\ and replaced the two \�s any\ casts with \�s unknown as Content\

All tests still pass locally.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for reloading agents on file change

2 participants