# Agents

> What an AI agent is in Lumen, how to build one once in the Agents area and reuse it in flows, and the settings that shape what it does, what it may call and how much it may spend.

Source: https://docs.go-lumen.ai/ai/agents

An agent is the one AI step in Lumen. You tell it what to do, which steps it may call as tools and what to hand back, and it decides how to get there. Build one in the Agents area to reuse it in many flows, or set one up directly on a flow's canvas.

-   Uses credits
-   Admins build, everyone can view

## Two ways to have an agent

Both are the same step, **AI agent** ([`chat-agent`](https://docs.go-lumen.ai/reference/steps/chat-agent.md)). They differ in where the settings live.

|  | Saved agent | AI agent step in a flow |
| --- | --- | --- |
| Where | **Agents** in the console, or a `Step` resource | On the flow's canvas, or in the flow's YAML |
| Reuse | Any number of flows use it | That one node |
| Changes | Each save is a numbered revision. A flow pins a revision and keeps running it until you move it | Change the flow, change the agent |
| Memory | Long-term notes belong to the saved agent, shared by every flow that uses it | Notes belong to that node of that flow |
| Delete | Refused while a flow pins it | Delete the node |

Pick a saved agent when several flows need the same worker, or when you want a review step for changes. Pick a node when the agent belongs to one flow. For the common case of pulling details out of a document, the node is enough: see [Find details in documents](https://docs.go-lumen.ai/ai/find-details.md).

## What an agent is set up with

| Setting | What it does |
| --- | --- |
| Instructions | What the agent is for and how it answers, up to 8,000 characters. Placeholders such as `{message}` or `{details.supplier}` are filled from the document. |
| Fields | The details it answers in. Each becomes an output of the step. See [Find details in documents](https://docs.go-lumen.ai/ai/find-details.md). |
| Files | How it reads the document's files: `attach` (the default), `text`, `none` or `ifNoText`, with limits on files, pages and bytes. |
| Tools | Catalog steps it may call, up to 16, plus tools of connected MCP servers. See [Tools and MCP servers](https://docs.go-lumen.ai/ai/tools-and-mcp.md). |
| Model | The model it runs on. Left empty, it uses your workspace default. See [Models and cost](https://docs.go-lumen.ai/ai/models-and-cost.md). |
| Memory | How many earlier turns of a conversation it reads (`memory.window`, 1 to 50). Separate from long-term notes: see [Memory](https://docs.go-lumen.ai/ai/memory.md). |
| Long-term memory | Whether it keeps notes across runs, how many it recalls at the start (`autoRecall`, 0 to 10, default 3) and when notes expire (`retentionDays`). |
| Knowledge | Lighthouse collections it may read, and whether it follows the workspace rules (`rules: false` turns them off, for an agent that talks to customers). See [Lighthouse knowledge](https://docs.go-lumen.ai/ai/lighthouse.md) and [Keep the rules away from an agent](https://docs.go-lumen.ai/ai/lighthouse.md#rules-off). |
| Guardrails | Rules it must follow, limits on what its tools may do, and kinds of text masked in its answer. |
| Limits | Safety caps per run, below. |

The plain **AI agent** step has these defaults: it answers helpfully and briefly in the language the person wrote in, remembers the last 10 turns, and stops after 8 model turns or when it has spent $0.50 of model usage in the run.

### Limits

| Limit | Meaning |
| --- | --- |
| `maxTurns` | The most model turns in one run of the step, 1 to 100. The AI agent step ships with 8. |
| `maxTokens` | The most tokens, input and output, the agent may use. 1 to 100,000,000. |
| `maxMinutes` | The most time the agent works, 1 to 1,440. |
| `maxCostUSD` | The most model spend in one run, set by the step definition (0.50 for the AI agent step). |
| `maxToolCredits` | The most its tool calls may be charged in one run, in credits. The call that would pass it is not made and the agent stops. Unset, tool calls are bounded by `maxTurns` only. Set by the step definition. |
| `memory.window` | Earlier turns read back, 1 to 50. Not a safety cap, but listed under **Limits** in the console. |

A cap that is reached stops the agent and fails the step with the reason, so a flow's [failure handling](https://docs.go-lumen.ai/build/when-a-run-fails.md) takes over.

## Build a saved agent in the console

## Open the Agents area

1.  In the console, open **Agents**. The list shows each agent, what it is **Built on**, its **Revision**, its **Cost** in credits plus AI usage, and which flows use it.
2.  Click **Create an agent**. Only workspace admins see the button. Everyone else sees **View** instead of the edit icon.

![The Agents page. A table with the columns Agent, Built on, Revision, Cost, Used by and an actions column. The first row is Invoice reader, built on AI agent, Revision 3, costing 3 credits plus AI usage, used by 1 flow. The second row is an agent with a Hebrew name, Revision 1. A Create an agent button sits above the table.](https://docs.go-lumen.ai/img/ai/agents-01-list.png)

*Agents lists reusable AI workers, the revision in force and the flows that use each.*

## Choose the loadout

1.  Give the agent a **Name** and a **Description**. The description is shown to anyone choosing the agent for a flow.
2.  The editor shows the agent as a wheel with eight segments, clockwise from the top: **Instructions**, **Tools**, **Memory**, **Model**, **Output**, **Limits**, **Examples** and **Guardrails**. Each segment says what is set. Click one to open it, and **Back** returns to the wheel.
3.  A segment reads **Not set** when empty and **Not offered** when this kind of agent has no such setting. **Examples** is marked **Coming soon** and does not open.

![The agent wheel for Invoice reader, revision 3. The center shows the name, Try it and Save buttons and an Advanced link. The ring has Instructions (set by each flow), Tools (4 tools), Memory (4 memories), Model (not set), Output (not set), Limits (not set), Examples (coming soon, locked) and Guardrails (not offered).](https://docs.go-lumen.ai/img/ai/agents-02-wheel.png)

*The wheel. Check marks show what is set; dashed segments are empty or not available.*

-   **Instructions**: what the agent does. Turn on the per-flow option to let every flow write its own instructions, and the instructions here are not saved.
-   **Tools**: the steps it may call. The agent decides when. Only catalog steps can be tools, not other saved steps.
-   **Model**: pick one. Left empty, the agent uses your default.
-   **Output**: the fields it hands back to the flow, each with a name, a type and a hint.
-   **Limits**: the earlier turns it remembers and its safety caps.
-   **Memory**: see [Memory](https://docs.go-lumen.ai/ai/memory.md).
-   **Guardrails**: rules in sentences, limits per tool (for example, send only to `*@acme.example`), and kinds of text to mask in the answer (card number, Israeli ID, email address, phone number).

![The Tools panel of the agent. A multi-select titled Steps it may call holds four chips: Read the text with a credit cost of 1, Rename the file with 0.5, Recall what I remember and Remember something. Below it the hint reads: The agent decides when to use them. Only catalog steps can be tools.](https://docs.go-lumen.ai/img/ai/agents-03-tools.png)

*Tools. Each chip shows what a call of that step costs.*

## Try it, then save

1.  Click **Try it**, choose **This form, unsaved** or **A saved revision**, add a sample text or file, and run it. A try is charged like a normal run. It shows the result, the tools it called and the tokens it used. Try it never changes the agent's memory.
2.  Add a **Note for the history** if you like, and click **Save as revision N**. Saving creates a new revision. Flows on older revisions keep running them until you update them.

## Use it in a flow

1.  In a flow, click **+**, choose **Action** and pick the agent from the step picker.
2.  The node pins the agent's current revision and says **Saved agent, revision N**. Its settings are locked to that revision, except the parts the agent leaves open.
3.  When a newer revision exists the node offers **Update to revision N**, with a comparison of the settings. The agent's list shows each flow and the revision it pins; one that is behind is marked **older revision**.

To go the other way, open an AI agent step that is not saved and choose **Save as agent**: the setup becomes a saved agent and this node uses it from then on.

## The same agent as YAML

A saved agent is a [`Step`](https://docs.go-lumen.ai/reference/resources/step.md) that configures the `chat-agent` catalog step. `with` holds its settings, which a flow cannot change. `open` lists settings a flow may set for itself.

**YAML:**

```yaml title="invoice-reader.yaml"
apiVersion: lumen.ai/v1alpha1
kind: Step
metadata:
  name: invoice-reader
  namespace: tenant-acme
spec:
  displayName: Invoice reader
  description: Reads an invoice and names the supplier, the date and the total.
  from:
    clusterStep: chat-agent
  with:
    instructions: Find these details in the invoice.
    fields:
      - {name: supplier}
      - {name: date, type: date}
      - {name: total, hint: "Amount due", type: money}
    files: {mode: ifNoText}
    limits: {maxTurns: 4, maxMinutes: 5}
  open: []
```

A flow node then pins a revision:

```yaml title="excerpt of a flow"
nodes:
  - id: details
    stepRef: {kind: Step, name: invoice-reader, revision: 1}
    next: [rename]
```

**Console:**

Follow [Build a saved agent in the console](#build). Revision numbers are the same in both places.

## An agent in a flow, and chatting with it

A flow that starts with the **A chat message arrives** trigger ([`chat-message`](https://docs.go-lumen.ai/reference/triggers/chat-message.md)) is a chat: the person's message is the run's input, and the agent's `reply` is what they read back. The trigger hands the first step two fields, `sessionId` and `message`. Messages with the same `sessionId` are one conversation, and the agent reads the last `memory.window` turns of it before it answers.

In the console, a flow with this trigger has a **Chat** tab and a **Chat with this flow** button. Every message starts a run and uses credits, and the flow must be switched on.

```yaml title="agents-support-chat.yaml"
apiVersion: lumen.ai/v1alpha1
kind: Flow
metadata:
  name: agents-support-chat
  namespace: tenant-acme
spec:
  displayName: Support chat
  triggers:
    - id: chat
      ref: {name: chat-message}
      config: {greeting: "Hi! Ask me about your order."}
      next: [bot]
  nodes:
    - id: bot
      stepRef: {name: chat-agent}
      config:
        instructions: >-
          You answer customers of a small shop. Be brief and polite, and answer
          in the language the customer wrote in.
        memory: {window: 10}
        tools: [recall, remember]
        limits: {maxTurns: 6, maxMinutes: 2}
```

## What an agent is charged

An AI agent step weighs 3 credits when it succeeds (1 when it only fills fields and has no tools). On top, model tokens are charged at the model's rate, and each successful tool call costs the weight of that tool. Tokens on a model with your own key cost no credits. See [Models and cost](https://docs.go-lumen.ai/ai/models-and-cost.md) and [Credits and budgets](https://docs.go-lumen.ai/concepts/credits-and-budgets.md).

> **Agents that need an installation capability:**
> 
> Browser and code tools exist but are off until an installation enables them. See [Tools and MCP servers](https://docs.go-lumen.ai/ai/tools-and-mcp.md).

## Next steps

[Tools and MCP serversWhat an agent may call, and how each call is charged.](https://docs.go-lumen.ai/ai/tools-and-mcp.md)[MemoryNotes an agent keeps across runs, and the conversation it reads back.](https://docs.go-lumen.ai/ai/memory.md)[Models and costChoose the model and see the estimate.](https://docs.go-lumen.ai/ai/models-and-cost.md)[Test and evaluateCheck an agent before you rely on it.](https://docs.go-lumen.ai/build/test-and-evaluate.md)
