> ## Documentation Index
> Fetch the complete documentation index at: https://docs.poly.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Topics

> Define knowledge-base topics that the agent can retrieve and act on through RAG.

Topics are the agent's knowledge base. They are queried through retrieval-augmented generation (RAG), and when a user's input matches a topic, the agent retrieves its content and follows its actions.

Topics are how you teach the agent facts and guidance about specific subject areas without putting everything into flows or rules.

## Location

Topics live in the `topics/` directory.

Each topic is stored as its own YAML file:

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
topics/{Topic Name}.yaml
```

The filename is derived from the topic's `name` field, cleaned to lowercase snake\_case — a topic named `Opening Hours & Locations` is stored as `topics/opening_hours_locations.yaml`.

## What a topic contains

Each topic has five main fields, plus optional tags:

| Field | Description |
| - | - |
| `name` | The display name of the topic. This is the canonical name — the filename is derived from it. Can contain spaces, punctuation, and mixed case. |
| `enabled` | Whether the topic is active. Default: `true`. |
| `tags` | Optional labels for grouping and filtering topics in Agent Studio. See [Tags](#tags). |
| `example_queries` | Example user inputs that should retrieve the topic. |
| `content` | Factual information retrieved by RAG. |
| `actions` | Behavioral instructions the agent should follow when the topic is matched. |

## Example

```yaml theme={"theme":{"light":"github-light","dark":"github-dark"}}
name: Opening Hours & Locations
enabled: true
tags:
  - hours
  - locations
example_queries:
  - What are your opening hours?
  - When are you open?
  - Are you open on weekends?
  - What time do you close?
content: |-
  The office is open Monday to Friday from 9am to 5pm.
  Weekend hours are Saturday 10am to 2pm. Closed on Sundays.
actions: |-
  Tell the user the opening hours from the content above.

  ## If the user asks about a specific location
  Check the location using {{attr:office_location}} and provide the hours for that location.

  ## If the user wants to speak to someone
  Use {{fn:transfer_to_agent}} to connect them with a representative.
```

## How topics work

A topic combines two kinds of information:

> [card] Content
>
> The factual material that the agent retrieves through RAG.

> [card] Actions
>
> The behavioral instructions that tell the agent what to do with that content.

This split is important: content is for facts, actions are for behavior.

## Example queries

`example_queries` help the system understand when a topic should be retrieved.

### Good example queries should:

* cover different ways a user might ask about the same subject
* reflect realistic user phrasing
* stay focused on one subject area

### Limits and guidance

* use no more than **20** example queries
* cover meaningful variation, not every minor wording change

## Tags

`tags` is an optional list of labels for grouping and filtering topics in Agent Studio. Tags don't change how the agent behaves.

* `poly pull` writes `tags` only for topics that have tags.
* A topic file without a `tags` key has no tags, so deleting the key clears them when you push.
* Each tag must be non-empty and unique within the topic. Tags are case-sensitive.

## Content

The `content` field contains factual information only.

This is the material that gets retrieved via RAG and made available to the agent when the topic is matched.

### Content rules

* keep it factual
* do not trigger behavior from content — no [`{{fn:...}}`](https://docs.poly.ai/adk/reference/resources/functions)/[`{{ft:...}}`](https://docs.poly.ai/adk/reference/resources/functions) function calls, no [`{{twilio_sms:...}}`](https://docs.poly.ai/adk/reference/resources/sms) sends, no [`{{ho:...}}`](https://docs.poly.ai/adk/reference/resources/handoffs) handoffs
* references to factual resources are fine — [`{{attr:...}}`](https://docs.poly.ai/adk/reference/resources/variants), [`{{tn:...}}`](https://docs.poly.ai/adk/reference/resources/translations), and [`{{vrbl:...}}`/`$variable`](https://docs.poly.ai/adk/reference/resources/variables) just substitute a value, so they're safe to use in content
* use multi-line YAML (`|-`) for longer content

## Actions

The `actions` field tells the agent how to behave when the topic is matched.

This is the only place inside a topic where you should use references and behavior-oriented instructions.

### Supported references in actions

| Syntax | Meaning |
| - | - |
| `{{fn:function_name}}` | Call a [global function](https://docs.poly.ai/adk/reference/resources/functions.md) |
| `{{fn:function_name}}('arg')` | Call a [global function](https://docs.poly.ai/adk/reference/resources/functions.md) with an argument |
| `{{attr:attribute_name}}` | Read a [variant attribute](https://docs.poly.ai/adk/reference/resources/variants.md) |
| `{{twilio_sms:template_name}}` | Reference an [SMS template](https://docs.poly.ai/adk/reference/resources/sms.md) |
| `{{ho:handoff_name}}` | Reference a [handoff](https://docs.poly.ai/adk/reference/resources/handoffs.md) |
| `{{tn:translation_key}}` | Reference a [translation](https://docs.poly.ai/adk/reference/resources/translations.md) |
| `$variable` | Reference a [state variable](https://docs.poly.ai/adk/reference/resources/variables.md) |

### Writing good actions

Actions should be:

* clear
* scannable
* structured
* behavior-oriented

Use markdown headers like `##` and `###` to break up branches or conditions.

### Prefer

* structured conditional sections
* plain instructions like “Tell the user that...”
* clear points where a function should be called

### Avoid

* dense paragraphs mixing facts and behavior
* `"Say: '...'"` phrasing
* putting factual content into actions

## Validation

* The filename must match the cleaned version of `name` — a mismatch raises a validation error on `pull` or `push`.
* `name` cannot start with `Guardrail - `, which is reserved for guardrails.
* An example query cannot be empty or contain `|`.

## Best practices

* keep content and actions separate
* use one topic per subject area
* split large topics when they become too broad
* prefer structured `##` branches in actions
* disable topics with `enabled: false` during development instead of deleting them

> [!TIP]
>
> **Tell, don't script**
>
> Prefer instructions like "Tell the user that ..." over hard-coded dialog such as `Say: '...'`. This lets the agent vary phrasing naturally, especially across languages.

## Related pages

> [card] [Functions](https://docs.poly.ai/adk/reference/resources/functions.md)
>
> Learn how global functions referenced in topic actions are defined.

> [card] [Flows](https://docs.poly.ai/adk/reference/resources/flows.md)
>
> See how topics hand off to structured processes using `conv.goto_flow`.

> [card] [Variants](https://docs.poly.ai/adk/reference/resources/variants.md)
>
> See how variant attributes can be referenced from topic actions.

> [card] [Managed Topics (platform)](https://docs.poly.ai/managed-topics/introduction.md)
>
> How topics are retrieved, ranked, and injected — RAG mechanics, topic types, and retrieval tuning.
