Skip to content

Flip ADK CLI to be ESM native instead of CommonJS#113

Merged
kalenkevich merged 1 commit intomainfrom
fix/esm_cli
Feb 5, 2026
Merged

Flip ADK CLI to be ESM native instead of CommonJS#113
kalenkevich merged 1 commit intomainfrom
fix/esm_cli

Conversation

@kalenkevich
Copy link
Collaborator

Description

This PR introduces enhanced control over how agent files are loaded and compiled in the ADK CLI. It adds support for specifying whether to compile or bundle agent code and allows explicit definition of the module type (ESM/CJS). This helps in handling different project setups and ensures better compatibility, particularly with ESM projects.

Key Changes:

New CLI Flags:

  • --compile [boolean]: Controls whether to compile TS agent files (default: true).
  • --bundle [boolean]: Controls whether to bundle agent files (default: true).
  • --file_type : Explicitly sets the module type (cjs or esm) for files to run or load (via npx adk run | web | api_server).

Enhanced Agent Loading:

AgentFile class in dev/src/utils/agent_loader.ts updated to handle compilation and bundling options.
Added logic to automatically detect module type from file extensions (.mjs, .cjs) or package.json.
Added esbuild-shim-plugin to handle shims during bundling.

Enabled Debug with ADK CLI run command:

While working with ESM .js/.ts files you can run agent without file compile and bundle: npx adk run ./agent.ts --compile=false --bundle=false. That allows to load and debug original files.

Example of the VSCode launch.json config for debug:

{
      "name": "Debug: ADK agent",
      "type": "node",
      "request": "launch",
      "runtimeExecutable": "npx",
      "runtimeArgs": [
        "@google/adk-devtools",
        "run",
        "./src/agent.ts",
        "--compile=false",
        "--bundle=false"
      ],
      "console": "integratedTerminal",
      "skipFiles": ["<node_internals>/**"],
      "env": {
        "GOOGLE_GENAI_API_KEY": "<your key>"
      }
    }

Resolves:

#108
#76
#77

@kalenkevich kalenkevich self-assigned this Feb 5, 2026
@kalenkevich kalenkevich force-pushed the fix/esm_cli branch 6 times, most recently from 23ab555 to 43c2ad8 Compare February 5, 2026 01:11
@kalenkevich kalenkevich merged commit 1eb443e into main Feb 5, 2026
6 checks passed
@kalenkevich kalenkevich deleted the fix/esm_cli branch February 5, 2026 22:47
@kalenkevich kalenkevich mentioned this pull request Feb 5, 2026
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.

2 participants