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

# Carry the state

> Keep each conversation's state, send it back on every call, and start again when it is refused.

Kviria keeps no conversation between calls. Your agent keeps it, as the
`state` string of the last response.
[Conversation state](https://docs.kviria.com/concepts/state.md) explains what the string holds.

## Keep one state per conversation

1. On the first call, send an empty string as `state`.
2. After each response, keep its `state` in place of the old one.
3. On the next call, send that `state`, copied exactly. Send that field
   only, never the whole response.
4. To start a new conversation, send an empty string again.

In code, one state per conversation is enough:

```python theme={null}
states = {}  # the last state of each conversation


def turn(conversation_id, request, position=None):
    """request: the fields your agent's model wrote, such as {"request": "search", "kind": "cafe"}."""
    body = {**request, "state": states.get(conversation_id, "")}
    if position is not None:
        body["anchor"] = position
    data = call_kviria(body)  # POST /v1/agent, with your Kviria key
    states[conversation_id] = data.get("state", body["state"])
    return data
```

On the [MCP server](https://docs.kviria.com/api/mcp.md), `state` is an ordinary argument of the
tool. Copy it from the last result into the next call.

## After an error

* `400 invalid_state`: the state was altered. The body carries an empty
  `state`. Keep it, and the conversation starts again.
* `400` with `invalid_body`, `invalid_request`, `unsupported_field`,
  `transcript_removed` or `anchor_required`: the body carries a `state`.
  Keep it and send it on the next call.
* Every other error carries no state. Keep the one you had.

## Send the position

* Send `anchor` on the first call. Kviria keeps it in the state.
* After that, send `anchor` only when the user moves. A call without one
  uses the position in the state.
* Send the user's position exactly as you were given it. Never send the
  coordinate of a place from an answer as the user's position. Kviria
  keeps the earlier position when it sees one, and the evidence says so.

The [Quickstart](https://docs.kviria.com/quickstart.md) carries one conversation from the first call
to a settled place.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.