Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 27 additions & 82 deletions docs/get-started/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,56 @@
This guide shows you how to get up and running with Agent Development Kit
for TypeScript. Before you start, make sure you have the following installed:

* Node.js 20.12.7 or later
* Node Package Manager (npm) 9.2.0 or later
* Node.js 24.13.0 or later
* Node Package Manager (npm) 11.8.0 or later

## Create an agent project

Create an agent project with the following files and directory structure:
Create an empty `my-agent` directory for your project:

```none
my-agent/
agent.ts # main agent code
package.json # project configuration
tsconfig.json # TypeScript configuration
.env # API keys or project IDs
```

??? tip "Create this project structure using the command line"

=== "MacOS / Linux"

```bash
mkdir -p my-agent/ && \
touch my-agent/agent.ts \
touch my-agent/package.json \
touch my-agent/.env
mkdir -p my-agent/
```

=== "Windows"

```console
mkdir my-agent\
type nul > my-agent\agent.ts
type nul > my-agent\package.json
type nul > my-agent\.env
mkdir my-agent
```

**Note:** Do not create `tsconfig.json`, you generate that
file in a later step.
### Configure project and dependencies

Use the `npm` tool to install and configure dependencies for your project,
including the package file, ADK TypeScript main
library, and developer tools. Run the following commands from your
`my-agent/` directory to create the `package.json` file and install the
project dependencies:

```console
cd my-agent/
# initialize a project as an ES module
npm init --yes
npm pkg set type="module"
npm pkg set main="agent.ts"
# install ADK libraries
npm install @google/adk
# install dev tools as a dev dependency
npm install -D @google/adk-devtools
```

### Define the agent code

Create the code for a basic agent, including a simple implementation of an ADK
[Function Tool](/adk-docs/tools/function-tools/), called `getCurrentTime`.
Add the following code to the `agent.ts` file in your project
directory:
Create an `agent.ts` file in your project directory and add the following code:

```typescript title="my-agent/agent.ts"
import {FunctionTool, LlmAgent} from '@google/adk';
Expand Down Expand Up @@ -74,67 +80,6 @@ export const rootAgent = new LlmAgent({
});
```

### Configure project and dependencies

Use the `npm` tool to install and configure dependencies for your project,
including the package file, TypeScript configuration, ADK TypeScript main
library and developer tools. Run the following commands from your
`my-agent/` directory:

```console
cd my-agent/
# initialize a project with default values
npm init --yes
# configure TypeScript
npm install -D typescript
npx tsc --init
# install ADK libraries
npm install @google/adk
npm install @google/adk-devtools
```

After completing these installation and configuration steps, open
the `package.json` project file and verify that the `main:` value
is set to `agent.ts`, that the TypeScript dependency is set, as
well as the ADK library dependencies, as shown in this example:

```json title="my-agent/package.json"
{
"name": "my-agent",
"version": "1.0.0",
"description": "My ADK Agent",
"main": "agent.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"typescript": "^5.9.3"
},
"dependencies": {
"@google/adk": "^0.2.0",
"@google/adk-devtools": "^0.2.0"
}
}
```

For development convenience, in the `tsconfig.json` file, update the
setting for `verbatimModuleSyntax` to `false` to allow simpler syntax
when adding modules:

```json title="my-agent/tsconfig.json"
// set to false to allow CommonJS module syntax:
"verbatimModuleSyntax": false,
```

### Compile the project

After completing the project setup, compile the project to prepare for
running your ADK agent:

```console
npx tsc
```

### Set your API key

This project uses the Gemini API, which requires an API key. If you
Expand Down Expand Up @@ -166,7 +111,7 @@ Run your agent with the ADK TypeScript command-line interface tool
using the following command:

```console
npx @google/adk-devtools run agent.ts
npx adk run agent.ts
```

![adk-run.png](/adk-docs/assets/adk-run.png)
Expand All @@ -176,7 +121,7 @@ npx @google/adk-devtools run agent.ts
Run your agent with the ADK web interface using the following command:

```console
npx @google/adk-devtools web
npx adk web
```

This command starts a web server with a chat interface for your agent. You can
Expand Down