---
question: Does an agent remember earlier messages in the same thread?
kind: task
via_web: available
via_cli: na
via_python: available
via_api: available
via_config: na
ref_web: Chat
ref_python: AgentProxy.invoke
ref_api: POST /api/chat/stream
prereq: A module that publishes an agent, running with `abi dev up` or `abi start` (see the [Quickstart](/capabilities/get-started/quickstart)).
next:
  - /capabilities/build/agents/test-an-agent
  - /capabilities/build/agents/enable-in-a-workspace
  - /capabilities/build/agents/edit-prompt-and-model
---

# Chat with an agent

Every agent a module publishes can be reached from the Nexus chat, from another module in Python, and through the Nexus chat API. A conversation is a thread: the agent remembers the earlier messages of the same thread.

## Web UI

### Turn the agent on

In the workspace, open Settings › Agents and check **Enabled** on the agent's row. The chat only offers enabled agents. See [Enable in a workspace](/capabilities/build/agents/enable-in-a-workspace).

### Start a conversation

Open **Chat** in the sidebar and click **New Chat** (Ctrl+I), or use File › New Chat.

### Pick the agent

Open the agent picker in the message box. With **Auto** on, the message goes to the workspace's default agent. Picking an agent turns **Auto** off: the default agent is under **Agents**, the others under **Custom**. An agent that can run several models lists them under its name; pick one.

![Chat with the agent picker open](/abi/Screenshot_Agent_Picker.png)

*The agent picker in the message box: Auto, the default agent under Agents, and the workspace's other agents under Custom.*

### Send a message

Type in **Send a message...** and press Enter. Shift+Enter adds a line. The answer streams in, and the tools the agent calls show as it calls them.

:::tip Skills
Type `/skills` to list the workspace's skills, and `/<slug>` to run one. See [Skills](/capabilities/build/skills/overview).
:::

## CLI

Not applicable. `abi chat` opens the agents the engine loads itself, not the agents of your modules. Use Nexus or the REST API on this page, or follow the module's log with `abi dev logs <name>`.

## Python

### Declare the module

Another module reaches the agent through discovery. Name the module that publishes it in the caller's dependencies:

```python title="src/caller/__init__.py"
dependencies = ModuleDependencies(
    services=("model_registry", "document", "triple_store"),  # the scaffold's services
    modules=("my_project.research",),
)
```

### Send messages

Call the agent from a job, a workflow or another method of the module, once it runs. Not from `on_initialized`: that hook runs before the module is `READY`, so a slow answer there holds back the module's own agents, apps and jobs, and an agent that is down stops it from starting.

```python title="src/caller/__init__.py"
from datetime import timedelta

from naas_abi_sdk.jobs import Cron, JobContext, job


class ABIModule(BaseModule[CallerConfiguration]):
    ...

    @job(triggers=(Cron("0 0 9 * * mon-fri", time_zone="UTC"),), timeout=timedelta(minutes=15))
    async def review_digest(self, ctx: JobContext) -> dict:
        reviewer = await self.engine.modules["my_project.research"].get_agent("Reviewer")
        summary = await reviewer.invoke("Summarize the open review comments.")
        grouped = await reviewer.invoke("Now group them by author.")  # same thread
        return {"summary": summary, "by_author": grouped}
```

Each run gets its own proxy, so its own thread. `reviewer.duplicate()` starts another thread from the same proxy.

`get_agent` returns an `AgentProxy`. Its `invoke(prompt)` returns the final answer as a string, on the proxy's thread: the agent remembers the earlier prompts of that thread. `stream_invoke(prompt)` yields the agent's events as it works. Each call has a 300 second deadline unless you pass `timeout`.

## REST API

### Find the agent's id

```http
GET /api/agents/?workspace_id=<id>
```

A module agent's record carries its module id in `module_path`.

### Send a message

The Nexus chat calls `POST /api/chat/stream`, and `POST /api/chat/complete` returns the whole answer. Both take a Nexus session. The body holds `workspace_id`, `message` and `agent`, the agent's id. The answer carries a `conversation_id`: send it back to continue the thread. With `stream`, an agent that is off in that workspace, or not in it, is replaced by the workspace's default agent.

A module agent has no route of its own on the API: these calls go through Nexus, which runs the turn on the module over NATS.

## Config

Not applicable. `config.yaml` sends no message: it names the default agent and [which agents a workspace offers](/capabilities/build/agents/enable-in-a-workspace?via=config).
