# Worker statefulness

Toolhouse workers are stateful by default. They automatically maintain persistent conversation context across multiple interactions without requiring external database configuration. Each conversation is assigned a unique run ID that preserves the complete interaction history, including user messages, agent responses, and MCP server calls.

### Overview

By default, all Toolhouse workers are stateful and start with a clear context. New POST agent call to `https://agents.toolhouse.ai/{YOUR_AGENT_ID}` will start a new interaction between the agent and the user. Each call will return an `X-Toolhouse-Run-ID` header that will identify the state ID. You can of this `X-Toolhouse-Run-ID` as a session ID:

```bash
curl -H "Authorization: Bearer $API_KEY" -v -XPOST https://agents.toolhouse.ai/{YOUR_AGENT_ID}
... curl output ...
< x-toolhouse-run-id: 92fa77db-507e-4c16-9a6d-06fb69eb1caf

¿Sobre qué tema te gustaría hablar hoy?
```

From now on, you can reference the Run ID in a PUT call to keep adding user messages to the conversation:

```bash
curl -H "Authorization: Bearer $API_KEY" -XPUT https://agents.toolhouse.ai/{YOUR_AGENT_ID}/{RUN_ID} \
  --json '{ "message": "no sé, puedes escoger tu un tema para esta conversación?" }'
  
¿Hablamos de inteligencia artificial?
```

At any point, you can get the full history of the conversation through a GET request:

```bash
curl -H "Authorization: Bearer $API_KEY" https://agents.toolhouse.ai/{YOUR_AGENT_ID}/{RUN_ID}
[
  { "role": "user", "content": "Hola" },
  { "role": "assistant", "content": "¿Sobre qué tema te gustaría hablar hoy?" },
  { "role": "user", "content": "no sé, puedes escoger tu un tema para esta conversación?" },
  { "role": "assistant", "content": "¿Hablamos de inteligencia artificial?" }
]
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.toolhouse.ai/toolhouse/developers/worker-statefulness.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
