How google/adk-js works
1. Repository shape
- This is a TypeScript monorepo centered on an AI agent SDK.
- The main product code lives in core/, while dev/ contains developer tooling, a local development UI, CLI commands, and integration harnesses.
- The root also contains end-to-end, integration, and cross-language tests that validate the SDK as both a library and a protocol implementation.
2. Core runtime: agent orchestration
- The heart of the system is core/src/agents/, which defines the agent execution model.
- It includes single-agent and composite orchestration patterns such as LlmAgent, LoopAgent, SequentialAgent, ParallelAgent, and RoutedAgent.
- InvocationContext, RunConfig, and LiveRequestQueue form the execution boundary for a turn: they carry runtime state, control flow, and request handling through the agent pipeline.
3. LLM abstraction layer
- core/src/models/ isolates model access behind a provider-neutral interface.
- BaseLLM, BaseLLMConnection, LLMRequest, and LLMResponse are the key interfaces/data contracts.
- Concrete adapters like GoogleLLM, GeminiLLMConnection, and ApigeeLLM show that the SDK can route to different backends while preserving a consistent agent API.
- RoutedLLM and the model registry support model selection and fallback behavior.
4. Request processing pipeline
- The core/src/agents/processors/ folder is the main mutation layer between an agent and the model call.
- Processors handle instruction injection, content shaping, tool filtering, request confirmation, context compaction, identity handling, code execution, and agent transfer.
- This is where higher-level agent behavior is assembled without hard-coding it into the agent classes themselves.
5. Tools and external actions
- core/src/tools/ is the tool abstraction layer for anything the model can invoke.
- It includes generic function tools, agent-as-tool composition, Google Search, exit-loop control, memory/artifact loaders, long-running tools, and MCP integration.
- Tool confirmation and toolset abstractions indicate an important boundary: model-generated actions are separated from side effects and can be gated or filtered before execution.
6. Context, memory, and session state
- Conversation state is split across core/src/context/, core/src/memory/, and core/src/sessions/.
- Context compactors and summarizers manage prompt growth, while memory services persist reusable facts or prior outputs.
- Session services manage turn-level state, including an in-memory option and a database-backed option with explicit DB schema/operations.
- The flow is: session state and memory are loaded into agent context, compacted or summarized as needed, then updated after each turn.
7. Artifacts and code execution
- core/src/artifacts/ provides a storage boundary for generated files and other outputs, with in-memory, filesystem, and Google Cloud Storage implementations.
- core/src/code_executors/ handles execution of code generated or requested by agents, including a built-in executor and utilities for execution context.
- These subsystems are important for agents that create files, run code, or persist structured outputs beyond the chat transcript.
8. Authentication and authorization
- core/src/auth/ implements credential handling for tools and external services.
- It includes auth handlers, provider registries, credential services, OAuth2 discovery/exchange/refresh logic, and auth preprocessing hooks.
- This creates a clean boundary between agent logic and service authentication, which is critical for tool calls to secured APIs.
9. A2A remote-agent protocol support
- core/src/a2a/ is the interoperability layer for agent-to-agent communication via the A2A protocol.
- It includes agent cards, executors, remote-agent wrappers, event conversion, metadata/part conversion, and run processors.
- Architecturally, this is a protocol boundary: local ADK agents can be exposed or consumed as remote agents while preserving event and metadata semantics.
10. Plugins, telemetry, and observability
- core/src/plugins/ contains extension points such as logging and security plugins managed by a plugin manager.
- core/src/telemetry/ integrates tracing and Google Cloud telemetry setup.
- These modules wrap the runtime rather than driving it, which suggests the SDK is designed for observability and policy enforcement without coupling those concerns into agent logic.
11. Core package boundaries
- core/src/index.ts and core/src/index_web.ts imply multiple public entry points for different runtimes.
- The core package is built as a reusable SDK, not a standalone app, and its registries (models, tools, sessions, artifacts, auth) indicate pluggable runtime components.
12. Developer tooling and local experience
- dev/ is a separate package for developer-facing workflows.
- It includes a CLI (cli_create, cli_run, cli_deploy), a local server/API layer, browser assets for the dev UI, and agent loading utilities.
- The development UI and API server are there to inspect, test, and debug agent graphs and runs, not to define the core runtime itself.
13. Testing and interoperability strategy
- The repo uses unit tests, integration tests, end-to-end tests, and cross-language compatibility tests.
- tests/cross_language/ verifies A2A behavior across TypeScript and Go implementations, showing that protocol compatibility is a first-class architectural requirement.
- tests/integration/build_setup/ also validates packaging/runtime combinations such as CommonJS vs ESM and native-addon handling.
14. Build and distribution model
- The project uses TypeScript with esbuild for producing CommonJS, ESM, and web outputs.
- The build/test matrix is part of the architecture because the SDK is meant to run in multiple environments, not just Node.js.
- The repository is therefore organized around a reusable runtime library plus companion dev tooling and protocol/test infrastructure.
Main entry points: agents Agents · tools Tools · index.ts Public API · a2a A2A
Components 21
Core SDK
Reusable agent runtime, models, state, tools, and extension points.
- Public API · Primary package exports for Node and web runtimes.
core/src/index.ts - Agents · Execution model for single and composite agents.
core/src/agents - Processors · Mutates LLM requests between agent logic and model calls.
core/src/agents/processors - Models · Provider-neutral LLM interfaces, routing, and adapters.
core/src/models - Tools · Invokeable actions, toolsets, and confirmation boundaries.
core/src/tools - Context · Context compactors and summarizers for prompt growth control.
core/src/context - Sessions · Turn-level session storage with in-memory and database-backed services.
core/src/sessions - Memory · Reusable facts and prior outputs that can be loaded into context.
core/src/memory - Artifacts · Storage boundary for generated files and structured outputs.
core/src/artifacts - Auth · Credential handling, OAuth2 flows, and auth preprocessing for services.
core/src/auth - A2A · Remote-agent interoperability layer for A2A event and metadata semantics.
core/src/a2a - Plugins · Logging and security extension points managed around runtime execution.
core/src/plugins - Telemetry · Tracing and cloud telemetry setup for runtime observability.
core/src/telemetry - Runner · In-memory and generic runners that drive agent execution.
core/src/runner
Dev Tools
CLI, local server, browser UI, and integration harnesses for development.
- CLI · Create, run, and deploy commands for local developer workflows.
dev/src/cli - Dev Server · Local API server and client for inspecting and driving agent graphs.
dev/src/server - Browser UI · Built browser assets for the development experience.
dev/src/browser - Integration Harness · Agent registry, dummy LLM, replay plugin, and integration test execution.
dev/src/integration
Validation
Integration, end-to-end, and cross-language compatibility coverage.
- Cross-language · TypeScript and Go A2A interoperability checks.
tests/cross_language/a2a - Integration · SDK behavior across agents, tools, routing, A2A, and build setups.
tests/integration - E2E · End-to-end scenarios for routing, tools, and context compaction.
tests/e2e
Connections 31
- Public API → Agents: exports · Public API surfaces the agent runtime.
- Public API → Models: exports · Public API exposes model abstractions and registries.
- Public API → Tools: exports · Public API exposes tool abstractions and built-ins.
- Public API → Sessions: exports · Public API exposes session services and registry.
- Public API → Artifacts: exports · Public API exposes artifact services and registry.
- Agents → Models: calls · Agents delegate LLM requests through model interfaces.
- Agents → Processors: uses · Processors shape requests and behavior inside agent turns.
- Agents → Tools: invokes · Agents can expose or consume tools during execution.
- Agents → Context: compacts · Agent turns use context compaction and summarization.
- Agents → Sessions: loads state · Session state is merged into agent execution context.
- Agents → Memory: hydrates · Reusable memory is loaded into context when needed.
- Agents → Artifacts: writes outputs · Agents can persist generated files and structured outputs.
- Agents → Runner: driven by · Runners execute agent turns and streaming flows.
- Processors → Auth: preprocesses · Request processing can inject auth-related handling.
- Tools → Auth: secures · Tool calls can use credential services and OAuth2 flows.
- Tools → Artifacts: loads/stores · Tools can expose artifact access to the model.
- Tools → Memory: reads · Tools can surface memory entries to the model.
- A2A → Agents: wraps · Remote-agent wrappers expose local agents as A2A endpoints.
- A2A → Models: bridges · A2A execution still relies on the underlying model runtime.
- Plugins → Runner: wraps · Plugins augment execution with logging and security policies.
- Telemetry → Runner: observes · Telemetry hooks trace runtime execution.
- CLI → Public API: uses SDK · CLI commands are built on the core package.
- Dev Server → Agents: inspects · Server surfaces agent graphs and run state for debugging.
- Dev Server → Browser UI: serves · Local server powers the browser-based developer UI.
- Integration Harness → A2A: tests · Integration harness exercises remote-agent protocol behavior.
- Cross-language → A2A: verifies · Cross-language tests confirm A2A interoperability.
- Integration → Agents: verifies · Integration tests cover orchestration and routing.
- Integration → Tools: verifies · Integration tests cover tool invocation and gating.
- Integration → Models: verifies · Integration tests cover routed and fallback model behavior.
- E2E → Context: verifies · End-to-end tests cover context compaction and shaping.
- E2E → Tools: verifies · End-to-end tests cover tool selection and memory/artifact tools.