# google/adk-js architecture

> Architecture diagram of the GitHub repository google/adk-js, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/google/adk-js
- Repository: https://github.com/google/adk-js

## Overview

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: [`core/src/agents`](https://github.com/google/adk-js/tree/main/core/src/agents) (Agents), [`core/src/tools`](https://github.com/google/adk-js/tree/main/core/src/tools) (Tools), [`core/src/index.ts`](https://github.com/google/adk-js/blob/main/core/src/index.ts) (Public API), [`core/src/a2a`](https://github.com/google/adk-js/tree/main/core/src/a2a) (A2A)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core SDK"]
  node_core_index["Public API<br/>entrypoints<br/>[index.ts]"]
  node_core_agents["Agents<br/>orchestration"]
  node_core_processors["Processors<br/>request pipeline"]
  node_core_models["Models<br/>llm abstraction"]
  node_core_tools["Tools<br/>tooling"]
  node_core_context["Context<br/>memory shaping"]
  node_core_sessions["Sessions<br/>session state"]
  node_core_memory[("Memory<br/>persistent state")]
  node_core_artifacts[("Artifacts<br/>output storage")]
  node_core_auth["Auth<br/>credentials"]
  node_core_a2a["A2A<br/>protocol bridge"]
  node_core_plugins["Plugins<br/>extensions"]
  node_core_telemetry["Telemetry<br/>observability"]
  node_core_runner["Runner<br/>execution host"]
end

subgraph group_dev["Dev Tools"]
  node_dev_cli["CLI<br/>developer commands"]
  node_dev_server["Dev Server<br/>local api"]
  node_dev_browser["Browser UI<br/>local ui"]
  node_dev_integration["Integration Harness<br/>test runner"]
end

subgraph group_tests["Validation"]
  node_tests_cross["Cross-language<br/>compatibility"]
  node_tests_integration["Integration<br/>system tests"]
  node_tests_e2e["E2E<br/>runtime scenarios"]
end

node_core_index -->|"exports"| node_core_agents
node_core_index -->|"exports"| node_core_models
node_core_index -->|"exports"| node_core_tools
node_core_index -->|"exports"| node_core_sessions
node_core_index -->|"exports"| node_core_artifacts
node_core_agents -->|"calls"| node_core_models
node_core_agents -->|"uses"| node_core_processors
node_core_agents -->|"invokes"| node_core_tools
node_core_agents -->|"compacts"| node_core_context
node_core_agents -->|"loads state"| node_core_sessions
node_core_agents -->|"hydrates"| node_core_memory
node_core_agents -->|"writes outputs"| node_core_artifacts
node_core_agents -->|"driven by"| node_core_runner
node_core_processors -->|"preprocesses"| node_core_auth
node_core_tools -->|"secures"| node_core_auth
node_core_tools -->|"loads/stores"| node_core_artifacts
node_core_tools -->|"reads"| node_core_memory
node_core_a2a -->|"wraps"| node_core_agents
node_core_a2a -->|"bridges"| node_core_models
node_core_plugins -->|"wraps"| node_core_runner
node_core_telemetry -->|"observes"| node_core_runner
node_dev_cli -->|"uses SDK"| node_core_index
node_dev_server -->|"inspects"| node_core_agents
node_dev_server -->|"serves"| node_dev_browser
node_dev_integration -->|"tests"| node_core_a2a
node_tests_cross -->|"verifies"| node_core_a2a
node_tests_integration -->|"verifies"| node_core_agents
node_tests_integration -->|"verifies"| node_core_tools
node_tests_integration -->|"verifies"| node_core_models
node_tests_e2e -->|"verifies"| node_core_context
node_tests_e2e -->|"verifies"| node_core_tools

click node_core_index "https://github.com/google/adk-js/blob/main/core/src/index.ts"
click node_core_agents "https://github.com/google/adk-js/tree/main/core/src/agents"
click node_core_processors "https://github.com/google/adk-js/tree/main/core/src/agents/processors"
click node_core_models "https://github.com/google/adk-js/tree/main/core/src/models"
click node_core_tools "https://github.com/google/adk-js/tree/main/core/src/tools"
click node_core_context "https://github.com/google/adk-js/tree/main/core/src/context"
click node_core_sessions "https://github.com/google/adk-js/tree/main/core/src/sessions"
click node_core_memory "https://github.com/google/adk-js/tree/main/core/src/memory"
click node_core_artifacts "https://github.com/google/adk-js/tree/main/core/src/artifacts"
click node_core_auth "https://github.com/google/adk-js/tree/main/core/src/auth"
click node_core_a2a "https://github.com/google/adk-js/tree/main/core/src/a2a"
click node_core_plugins "https://github.com/google/adk-js/tree/main/core/src/plugins"
click node_core_telemetry "https://github.com/google/adk-js/tree/main/core/src/telemetry"
click node_core_runner "https://github.com/google/adk-js/tree/main/core/src/runner"
click node_dev_cli "https://github.com/google/adk-js/tree/main/dev/src/cli"
click node_dev_server "https://github.com/google/adk-js/tree/main/dev/src/server"
click node_dev_browser "https://github.com/google/adk-js/tree/main/dev/src/browser"
click node_dev_integration "https://github.com/google/adk-js/tree/main/dev/src/integration"
click node_tests_cross "https://github.com/google/adk-js/tree/main/tests/cross_language/a2a"
click node_tests_integration "https://github.com/google/adk-js/tree/main/tests/integration"
click node_tests_e2e "https://github.com/google/adk-js/tree/main/tests/e2e"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_core_index,node_core_agents,node_core_processors,node_core_models,node_core_tools,node_core_context,node_core_sessions,node_core_memory,node_core_artifacts,node_core_auth,node_core_a2a,node_core_plugins,node_core_telemetry,node_core_runner toneBlue
class node_dev_cli,node_dev_server,node_dev_browser,node_dev_integration toneAmber
class node_tests_cross,node_tests_integration,node_tests_e2e toneMint
```

## Components

### Core SDK

Reusable agent runtime, models, state, tools, and extension points.

- [Public API](https://github.com/google/adk-js/blob/main/core/src/index.ts): entrypoints · Primary package exports for Node and web runtimes. · `core/src/index.ts`
- [Agents](https://github.com/google/adk-js/tree/main/core/src/agents): orchestration · Execution model for single and composite agents. · `core/src/agents`
- [Processors](https://github.com/google/adk-js/tree/main/core/src/agents/processors): request pipeline · Mutates LLM requests between agent logic and model calls. · `core/src/agents/processors`
- [Models](https://github.com/google/adk-js/tree/main/core/src/models): llm abstraction · Provider-neutral LLM interfaces, routing, and adapters. · `core/src/models`
- [Tools](https://github.com/google/adk-js/tree/main/core/src/tools): tooling · Invokeable actions, toolsets, and confirmation boundaries. · `core/src/tools`
- [Context](https://github.com/google/adk-js/tree/main/core/src/context): memory shaping · Context compactors and summarizers for prompt growth control. · `core/src/context`
- [Sessions](https://github.com/google/adk-js/tree/main/core/src/sessions): session state · Turn-level session storage with in-memory and database-backed services. · `core/src/sessions`
- [Memory](https://github.com/google/adk-js/tree/main/core/src/memory): persistent state · Reusable facts and prior outputs that can be loaded into context. · `core/src/memory`
- [Artifacts](https://github.com/google/adk-js/tree/main/core/src/artifacts): output storage · Storage boundary for generated files and structured outputs. · `core/src/artifacts`
- [Auth](https://github.com/google/adk-js/tree/main/core/src/auth): credentials · Credential handling, OAuth2 flows, and auth preprocessing for services. · `core/src/auth`
- [A2A](https://github.com/google/adk-js/tree/main/core/src/a2a): protocol bridge · Remote-agent interoperability layer for A2A event and metadata semantics. · `core/src/a2a`
- [Plugins](https://github.com/google/adk-js/tree/main/core/src/plugins): extensions · Logging and security extension points managed around runtime execution. · `core/src/plugins`
- [Telemetry](https://github.com/google/adk-js/tree/main/core/src/telemetry): observability · Tracing and cloud telemetry setup for runtime observability. · `core/src/telemetry`
- [Runner](https://github.com/google/adk-js/tree/main/core/src/runner): execution host · 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](https://github.com/google/adk-js/tree/main/dev/src/cli): developer commands · Create, run, and deploy commands for local developer workflows. · `dev/src/cli`
- [Dev Server](https://github.com/google/adk-js/tree/main/dev/src/server): local api · Local API server and client for inspecting and driving agent graphs. · `dev/src/server`
- [Browser UI](https://github.com/google/adk-js/tree/main/dev/src/browser): local ui · Built browser assets for the development experience. · `dev/src/browser`
- [Integration Harness](https://github.com/google/adk-js/tree/main/dev/src/integration): test runner · 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](https://github.com/google/adk-js/tree/main/tests/cross_language/a2a): compatibility · TypeScript and Go A2A interoperability checks. · `tests/cross_language/a2a`
- [Integration](https://github.com/google/adk-js/tree/main/tests/integration): system tests · SDK behavior across agents, tools, routing, A2A, and build setups. · `tests/integration`
- [E2E](https://github.com/google/adk-js/tree/main/tests/e2e): runtime scenarios · End-to-end scenarios for routing, tools, and context compaction. · `tests/e2e`

## Connections

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