---
name: agent-builder
description: Build and configure Indemn AI agents — create agents, set prompts, add functions/tools, manage knowledge bases, and test via chat. Use when creating, configuring, or testing agents.
---

# Agent Builder

You build and configure AI agents using the `indemn` CLI. This skill covers the full lifecycle: create an agent, set its prompt, attach functions and knowledge bases, and test via chat.

**Prerequisite:** The `indemn` CLI must be installed and authenticated. Run `indemn whoami` to verify.

---

## Workflow

Create agent -> Set prompt & model -> Add functions -> Add knowledge bases -> Link KBs -> Test via chat -> Iterate.

---

## Step 1: Create the Agent

Before creating, determine: name/purpose, channels (WEB, WHATSAPP, etc.), persona, functions needed, knowledge sources, and model (`indemn models [--json]`).

```bash
indemn agents create --name "Acme Insurance Assistant" --channels "WEB,WHATSAPP"
```

- `--channels` defaults to `"WEB"` if omitted. Comma-separated for multiple.
- Save the returned agent ID -- every subsequent command needs it.

### Other Agent Operations

```bash
indemn agents list [--json] [--limit 20] [--page 2]
indemn agents get <agent-id> [--json]
indemn agents update <agent-id> --name "New Name" --description "Updated description"
indemn agents update <agent-id> --webhook-url "https://example.com/webhook"
indemn agents clone <agent-id>
indemn agents delete <agent-id>           # requires confirmation
indemn agents card <agent-id> --output ./agent-card.pdf   # branded PDF
```

---

## Step 2: Set the System Prompt and Model

### Inline prompt

```bash
indemn config set <agent-id> --prompt "You are an insurance assistant for Acme Corp..."
```

### Prompt from file (preferred for long prompts)

```bash
indemn config set <agent-id> --prompt-file ./prompts/acme-assistant.txt
```

If both `--prompt` and `--prompt-file` are provided, `--prompt-file` takes precedence.

### Set the model

This controls which LLM the agent uses to generate responses — in conversations and during evaluations. The provider is auto-detected from the model name (claude -> anthropic, gemini -> google, default -> openai). This is NOT the evaluation judge model — that is set per-run via `eval run --eval-model`.

```bash
indemn config set <agent-id> --model "claude-sonnet-4-20250514"
```

Combine prompt and model in one call:

```bash
indemn config set <agent-id> --prompt-file ./prompts/acme.txt --model "claude-sonnet-4-20250514"
```

### Read current configuration

```bash
indemn config get <agent-id> [--json]
indemn config get <agent-id> --field prompt
indemn config get <agent-id> --field model
indemn config get <agent-id> --field greeting
```

---

## Step 3: Add Functions (Tools)

Functions are tools the agent can invoke during conversation (e.g., generate a quote, transfer to a human, look up policy details).

### Create a function

```bash
indemn functions create <agent-id> --type ACTION --name "get_quote" --description "Generate an insurance quote"
```

### Add parameters to a function

```bash
indemn functions params add <agent-id> <func-id> \
  --name "state" --type string --description "US state abbreviation" --required

indemn functions params add <agent-id> <func-id> \
  --name "coverage_amount" --type number --description "Coverage amount in dollars"

indemn functions params add <agent-id> <func-id> \
  --name "has_claims" --type boolean --description "Whether applicant has prior claims"
```

Parameter types: `string`, `number`, `boolean`. Use `--required` for mandatory params.

### Manage parameters

```bash
indemn functions params list <agent-id> <func-id> [--json]
indemn functions params update <agent-id> <func-id> <param-id> --description "Updated desc" --required
indemn functions params delete <agent-id> <func-id> <param-id>
```

### Import functions from an OpenAPI spec

```bash
indemn functions import <agent-id> --url "https://api.example.com/openapi.json"
```

This parses the spec and creates functions with parameters automatically.

### Other function operations

```bash
indemn functions list <agent-id> [--json] [--limit 10] [--page 1]
indemn functions update <agent-id> <func-id> --name "updated_name" --description "New desc"
indemn functions test <agent-id> <func-id> [--json]
indemn functions export <agent-id> [--json]
indemn functions delete <agent-id> <func-id>       # requires confirmation
indemn functions master-list [--json]               # available function templates
```

---

## Step 4: Create and Link Knowledge Bases

Knowledge bases provide the agent with reference information. Three data source types: QNA pairs, URLs, and files.

### Create a knowledge base

```bash
indemn kb create --name "Acme FAQ" --type QNA
indemn kb create --name "Product Pages" --type URL
indemn kb create --name "Policy Documents" --type FILE
```

Type defaults to `QNA` if omitted. Must be uppercased: `QNA`, `URL`, or `FILE`.

### Add data -- QNA pairs

```bash
indemn kb data add <kb-id> --question "What is the deductible?" --answer "The standard deductible is $500."
```

### Add data -- URL scraping

```bash
indemn kb data add <kb-id> --source-url "https://acme.com/faq"
```

Scrapes the URL and ingests the content.

### Add data -- File upload

```bash
indemn kb data add <kb-id> --file ./documents/policy-handbook.pdf
```

Uploads the file and polls until processing is complete.

### Bulk import QNA pairs from a file

```bash
indemn kb import <kb-id> --file ./qna-pairs.json
```

The file must be a JSON array of `{question, answer}` objects:

```json
[
  {"question": "What is a deductible?", "answer": "The amount you pay before coverage kicks in."},
  {"question": "What is a premium?", "answer": "The amount you pay for your insurance policy."}
]
```

Each pair is added individually. Progress is shown during import.

### Link knowledge bases to an agent

```bash
indemn kb link <agent-id> <kb-id>
indemn kb link <agent-id> <kb-id-1> <kb-id-2> <kb-id-3>    # link multiple at once
```

The link command is variadic -- pass multiple KB IDs to link them all in one call.

### Unlink a knowledge base

```bash
indemn kb unlink <agent-id> <kb-id>
```

### Other KB operations

```bash
indemn kb list [--json] [--limit 20] [--page 1]
indemn kb get <kb-id> [--json]
indemn kb update <kb-id> --name "Updated Name"
indemn kb delete <kb-id>                                     # requires confirmation
indemn kb data list <kb-id> [--json] [--limit 20] [--page 1] # shows Total, Page X of Y
indemn kb data update <kb-id> <source-id> --question "New Q" --answer "New A"
indemn kb data update <kb-id> <source-id> --source-url "https://new-url.com"
indemn kb data update <kb-id> <source-id> --content "Replacement content"
indemn kb data delete <kb-id> <source-id>                    # requires confirmation
indemn kb export <kb-id> --format csv                        # or xlsx
indemn kb import <kb-id> --file ./qna-pairs.json             # bulk import QNA pairs
```

---

## Step 5: Test via Chat

### Interactive mode

```bash
indemn chat <agent-id>
```

Opens a live chat session. Type messages, see responses in real time. Ctrl+C to exit.

### Single message (scripting / quick check)

```bash
indemn chat <agent-id> --message "What types of insurance do you offer?"
```

Sends one message, prints the response, exits.

### Resume a previous session

```bash
indemn chat <agent-id> --session <session-id>
```

Continues an existing conversation thread with its history intact.

---

## Step 6: Iterate

After testing, refine: update the prompt (`config set --prompt-file`), add functions (`functions create`), add/update KB data (`kb data add` / `kb data update`), or switch models (`config set --model`). Repeat steps 2-5 until the agent performs correctly.

## Complete Build Example

```bash
# 1. Create agent
indemn agents create --name "Acme Wedding Insurance" --channels "WEB"
# -> agent_id: abc123

# 2. Set prompt and model
indemn config set abc123 --prompt-file ./prompts/wedding.txt --model "claude-sonnet-4-20250514"

# 3. Add functions
indemn functions create abc123 --type ACTION --name "get_quote" --description "Generate a wedding insurance quote"
# -> func_id: func456
indemn functions params add abc123 func456 --name "event_date" --type string --description "Wedding date" --required
indemn functions params add abc123 func456 --name "guest_count" --type number --description "Number of guests" --required
indemn functions params add abc123 func456 --name "venue_cost" --type number --description "Total venue cost in dollars"

# 4. Create and populate knowledge base
indemn kb create --name "Wedding FAQ" --type QNA
# -> kb_id: kb789
indemn kb data add kb789 --question "What does wedding insurance cover?" --answer "Coverage includes venue damage, vendor no-shows, severe weather, and illness."
indemn kb data add kb789 --source-url "https://acme.com/wedding-insurance/faq"

# 5. Link KB to agent
indemn kb link abc123 kb789

# 6. Test
indemn chat abc123 --message "Hi, I'm getting married in June and want to protect my investment."
indemn chat abc123    # interactive session for deeper testing
```

---

## CLI Quick Reference

| Group | Command | Purpose |
|-------|---------|---------|
| **Agents** | `agents list / get / create / update / delete` | CRUD operations |
| | `agents clone <id>` | Duplicate an agent |
| | `agents card <id> [--output <path>]` | Generate branded PDF |
| **Config** | `config get <id> [--field prompt\|model\|greeting]` | Read configuration |
| | `config set <id> [--prompt\|--prompt-file\|--model]` | Write configuration |
| **Functions** | `functions list / create / update / delete` | CRUD operations |
| | `functions test <id> <func-id>` | Test a function |
| | `functions export <id>` | Export all functions |
| | `functions import <id> --url "<spec>"` | Import from OpenAPI |
| | `functions master-list` | Available templates |
| | `functions params list / add / update / delete` | Manage parameters |
| **KB** | `kb list / get / create / update / delete` | CRUD operations |
| | `kb data list / add / update / delete` | Manage KB entries |
| | `kb link <agent-id> <kb-id...>` | Link KB(s) to agent |
| | `kb unlink <agent-id> <kb-id>` | Unlink KB from agent |
| | `kb export <kb-id> [--format csv\|xlsx]` | Export KB data |
| | `kb import <kb-id> --file <path>` | Import from JSON |
| **Chat** | `chat <id>` | Interactive session |
| | `chat <id> --message "<text>"` | Single message mode |
| | `chat <id> --session <sid>` | Resume session |
| **Other** | `whoami` | Show authenticated user |
| | `models` | List available LLMs |

All commands accept `--json` for machine-readable output. List commands accept `--limit <n>` and `--page <n>`. Delete commands require confirmation.
