Skip to content

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

Open
nuthalapativarun wants to merge 4 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 4 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.

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
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
- 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
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!

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