# Agentic Chat Example Server

Follow these steps to run the LangGraph agent backend that powers the Agentic Chat example. Commands assume you are in the monorepo root unless noted.

## 1. Build the Monorepo Packages

From the TypeScript workspace root (`AG-Kit/typescript-sdk`):

- `pnpm install`
- `pnpm run build`

## 2. Prepare Server Environment Variables

In this directory (`AG-Kit/typescript-sdk/packages/examples/agents/server`):

- Copy `.env.example` to `.env` (or create `.env` manually)
- Set the required variables:
  - `OPENAI_API_KEY`
  - `OPENAI_MODEL`
  - `OPENAI_BASE_URL`

## 3. Install, Build, and Start the Server

Still inside `AG-Kit/typescript-sdk/packages/examples/agents/server`, run:

- `pnpm install`
- `pnpm run build`
- `pnpm run start`

The server exposes endpoints under `/v1/aibot/bots/` that the web frontend consumes.

## Docker Deployment

### Prerequisites

Before building the Docker image, ensure you have:

1. **Built the entire monorepo locally**
   ```bash
   # From the typescript-sdk root directory
   cd ../../../
   pnpm install
   pnpm build
   ```

2. **Prepared Environment Variables**
   ```bash
   # Copy and configure environment variables
   cp .env.example .env
   # Edit .env and set your OPENAI_API_KEY
   ```

### Building and Running with Docker

1. **Build the Docker Image**
   ```bash
   # From the server directory
   docker build -t ag-kit-server .
   ```

2. **Run the Container**
   ```bash
   # Run with environment variables
   docker run -p 9000:9000 \
     -e OPENAI_API_KEY=your_api_key_here \
     -e NODE_ENV=production \
     ag-kit-server
   
   # Or run with .env file
   docker run -p 9000:9000 --env-file .env ag-kit-server
   ```

3. **Access the Server**
   - Server will be available at `http://localhost:9000`
   - Health check endpoint: `http://localhost:9000/health`

### Docker Features

- **Workspace Support**: Includes all workspace dependencies in the image
- **Pre-built**: All dependencies and built files are included
- **Performance**: Alpine Linux base image for smaller size
- **Simple**: No build process required in container
