> For the complete documentation index, see [llms.txt](https://docs.concurrence.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.concurrence.com/developer-guide/classic-api/core-api/conversations/conversations-lifecycle.md). Agents can also search and read this documentation through its [MCP server](https://docs.concurrence.com/~gitbook/mcp).

# Lifecycle & Finish

Manage conversation states, finish sessions manually or automatically, and handle dangling conversations.

Understand conversation states and how to finish or resume sessions.

{% hint style="info" %}
**REST vs WebSocket**

Concurrence provides two ways to interact with conversations:

* **REST API** (documented here): HTTP POST requests with NDJSON streaming responses. Best for server-to-server integrations.
* **WebSocket API**: real-time bidirectional communication with support for voice activity detection (VAD). Best for interactive client applications. See [Conversations: Realtime](https://docs.concurrence.com/developer-guide/classic-api/core-api/conversations/conversations-realtime.md) for WebSocket details.
  {% endhint %}

## Conversation Management Lifecycle

The typical lifecycle uses HTTP requests with NDJSON event streams for both creation and each interaction.

1. Create a conversation with the intended service and version set.
2. Retain `conversation_id` from the opening stream.
3. Send text or voice interactions and consume each NDJSON stream through `interaction-complete`.
4. Finish the conversation when the workflow ends, and retain its final evidence.

## API Endpoints

The create and interact endpoints have dedicated pages. The finish endpoint is documented in [Finish a Conversation](#finish-a-conversation) below.

{% content-ref url="/pages/dQSRSiEACAn2dGIOEJ0m" %}
[Create](https://docs.concurrence.com/developer-guide/classic-api/core-api/conversations/conversations-create.md)
{% endcontent-ref %}

{% content-ref url="/pages/6e6etPhkf0J4ALAFoU0S" %}
[Interact](https://docs.concurrence.com/developer-guide/classic-api/core-api/conversations/conversations-interact.md)
{% endcontent-ref %}

## States

* **Started**: active and can receive interactions.
* **Finished**: ended and cannot receive further interactions.

| State    | Meaning                                                             |
| -------- | ------------------------------------------------------------------- |
| Started  | The conversation can receive interactions.                          |
| Finished | The conversation has ended and cannot receive further interactions. |

Explicit finish and automatic completion both lead to the finished state.

## Automatic vs Manual Finish

Conversations may finish automatically based on service logic, or manually through the finish API (for example, on a timeout or user action).

For a manual finish, your application calls the finish operation. For automatic completion, inspect `conversation_completed: true` on `interaction-complete`. Do not treat every completed interaction as a finished conversation.

## Finish a Conversation

{% tabs %}
{% tab title="cURL" %}

```bash
curl --request POST \
     --url 'https://api.amigo.ai/v1/<YOUR-ORG-ID>/conversation/<CONVERSATION-ID>/finish/' \
     --header 'Authorization: Bearer <AUTH-TOKEN-OF-USER>' \
     --header 'accept: application/json'
```

{% endtab %}

{% tab title="Python SDK" %}

```python
from amigo_sdk import AmigoClient

with AmigoClient() as client:
    client.conversation.finish_conversation(conversation_id)
```

{% endtab %}

{% tab title="TypeScript SDK" %}

```typescript
import { AmigoClient } from "@amigo-ai/sdk";

const client = new AmigoClient({ /* config */ });
await client.conversations.finishConversation(conversationId);
```

{% endtab %}
{% endtabs %}

{% openapi src="<https://api.amigo.ai/v1/openapi.json>" path="/v1/{organization}/conversation/{conversation\_id}/finish/" method="post" %}
<https://api.amigo.ai/v1/openapi.json>
{% endopenapi %}

## Managing Inactive ("Dangling") Conversations

Conversations do not time out automatically. Common patterns:

* **Timeout**: track the last interaction and call finish after a period. This may end active sessions unexpectedly.
* **Resume (recommended)**: offer resume or start new, finishing the existing conversation if needed.
* **On conflict when creating a new conversation**: prompt the user to resume or end the existing one.

When a conversation finishes, post-conversation analysis (memories, user model updates, metrics) runs asynchronously.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.concurrence.com/developer-guide/classic-api/core-api/conversations/conversations-lifecycle.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
