Skip to main content

Conversations Tutorial

This tutorial demonstrates how to have multi-turn conversations with Knowledge Discovery agents. Unlike single-shot questions, conversations maintain context across multiple questions and answers, allowing for more natural dialogue.

Prerequisites​

  • Valid access token (see Authentication)
  • At least one configured agent with data sources
  • Discovery User role or higher
ECE-powered Knowledge Discovery

Conversation endpoints are available with ECE-powered Knowledge Discovery. Use Hxp-App: cin-ece-kd for every Conversation API request. Request the hxp token scope; iam.jti-capture is not required with this application key.

warning

If your HTTP client doesn't add the User-Agent header by default, make sure to include it in all requests below (e.g., User-Agent: PostmanRuntime/7.28.4) to avoid receiving a 403 Forbidden response.

Tutorial Overview​

In this tutorial, you'll learn to:

  1. Start a new conversation with an agent
  2. Ask follow-up questions within a conversation
  3. Use streaming endpoints to receive incremental responses via SSE
  4. List and retrieve conversation messages
  5. Provide feedback on conversation messages
  6. Manage conversations (list, update metadata)
Response time

Conversation API calls are synchronous and may take up to 480 seconds for complex GraphRAG queries. Ensure your HTTP client is configured with a timeout of at least 480 seconds to avoid premature disconnects.

Part 1: Start a Conversation​

To start a new conversation, send the first question using the conversation endpoint. The response returns both the new conversationId and the first message (question and answer).

POST {{baseUrl}}/qna/agents/{{agentId}}/conversations
Authorization: Bearer {{accessToken}}
Hxp-Environment: {{environmentKey}}
Hxp-App: cin-ece-kd
Content-Type: application/json

{
"question": "What is the status of the project?",
"contextObjectIds": null,
"dynamicFilter": null
}

Start Conversation Request Parameters​

FieldRequiredDescription
questionYesInitial natural language question for the conversation
dynamicFilterNoRuntime filter expression to narrow search results
enableCitationsNoWhen true, the agent includes inline citation references in the answer text. Defaults to false when not provided.

Response Structure​

{
"conversation": {
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"lastModified": "2025-12-02T10:30:00Z"
},
"message": {
"id": "f1e2d3c4-b5a6-7890-1234-567890abcdef",
"answer": "Based on the documents, the project is currently in progress.",
"documentReferences": [
{
"documentId": "doc001",
"references": [
{
"referenceId": "ref001",
"rankScore": 0.95,
"rank": 1
}
]
}
],
"question": "What is the status of the project?",
"feedback": null,
"staticFilter": null,
"dynamicFilter": null,
"dateCreated": "2025-12-02T10:30:00Z",
"dateAnswered": "2025-12-02T10:30:05Z",
"agentVersion": 1,
"status": "Answered"
},
"provenance": {
"origin": "ai-generated",
"fields": ["/answer"]
}
}
Graph RAG vs Standard RAG Responses

The response structure shown above applies to standard RAG agents. If you're using a Graph RAG agent (see Managing Agents Tutorial - Graph RAG), the response will include graphReferences instead of (or in addition to) documentReferences. Graph references provide entity and relationship information from the knowledge graph domain.

Understanding the Response​

FieldTypeDescription
conversation.idUUIDUnique identifier for the conversation
conversation.lastModifieddatetimeTimestamp of the last update
message.idUUIDUnique identifier for this message
message.questionstringThe question text
message.answerstringThe generated answer
message.documentReferencesarraySource documents and chunks used for the answer
message.dateCreateddatetimeWhen the question was submitted
message.dateAnswereddatetimeWhen the answer was generated
message.agentVersionintegerVersion of the agent used
message.statusenumMessage status: Unspecified, Submitted, Answered, Error, Blocked

AI Provenance​

Optional provenance identifies AI-generated answers and follow-up prompts in synchronous RAG and Graph RAG responses and Graph RAG streams:

{
"provenance": {
"origin": "ai-generated",
"fields": ["/answer", "/followUpPrompts"]
}
}

fields contains JSON Pointers relative to the message, including /answer and /followUpPrompts. provenance sits at the response or event root, or on each data item in message lists; nested start/stream messages omit it. Array paths cover all elements. Unlisted fields have unspecified origin, and provenance does not verify accuracy.

Except for the initial streaming declaration, paths cover only generated content returned. Fixed refusals, empty output, and errors without generated content omit provenance. Clients must accept missing provenance and unknown response members.

Message-list projections retain matching provenance for answer and followUpPrompts; ID-only projections omit it. Truncation preserves attribution.

GET /qna/agents/{agentId}/feedback/{feedbackId} declares /answer only when the snapshot exactly matches its source message with status Answered. Unverifiable snapshots, user-written feedback, submissions, lists, and metrics omit provenance.

Starting a Conversation with Dynamic Filter​

You can apply dynamic filters when starting a conversation to narrow the search scope for all messages in that conversation. This is useful when you want to focus the conversation on specific documents, date ranges, or categories.

POST {{baseUrl}}/qna/agents/{{agentId}}/conversations
Authorization: Bearer {{accessToken}}
Hxp-Environment: {{environmentKey}}
Hxp-App: cin-ece-kd
Content-Type: application/json

{
"question": "What are the latest security policies?",
"dynamicFilter": {
"logicalOperator": "And",
"conditions": [
{
"field": "DocumentType",
"type": "Text",
"operator": "Equals",
"value": "Policy"
},
{
"field": "Department",
"type": "Text",
"operator": "Equals",
"value": "Security"
},
{
"field": "LastModified",
"type": "Date",
"operator": "GreaterThan",
"value": "2024-01-01"
}
]
}
}
tip

Dynamic filters can also be provided when asking follow-up questions (see Part 2). Each message can have its own filter, or you can omit it to use the agent's default behavior. For more details on filter syntax, see the Single-Shot Questions Tutorial.

Dynamic Filter Template Matching​

The dynamicFilter you provide at runtime must match the structure defined in the agent's dynamicFilterTemplate, which is configured during agent creation or update. The template defines which fields can be filtered and their types, while the runtime filter provides the actual values.

Example: Agent Configuration with Dynamic Filter Template

When creating or updating an agent, you define which fields users can filter by:

{
"name": "Document Search Agent",
"description": "Agent that allows users to filter by department, document type, and date",
"modelName": "amazon.nova-micro-v1:0",
"sourceIds": ["your-source-id"],
"dynamicFilterTemplate": {
"logicalOperator": "And",
"conditions": [
{
"field": "Department",
"type": "Text"
},
{
"field": "DocumentType",
"type": "Text"
},
{
"field": "LastModified",
"type": "Date"
}
]
}
}

Corresponding Runtime Dynamic Filter

When starting a conversation or asking questions, provide the operator and value for the fields defined in the template:

{
"dynamicFilter": {
"logicalOperator": "And",
"conditions": [
{
"field": "Department",
"type": "Text",
"operator": "Equals",
"value": "Security"
},
{
"field": "DocumentType",
"type": "Text",
"operator": "Equals",
"value": "Policy"
},
{
"field": "LastModified",
"type": "Date",
"operator": "GreaterThan",
"value": "2024-01-01"
}
]
}
}
note

The fields in your runtime dynamicFilter must match those defined in the agent's dynamicFilterTemplate. You can provide values for all or a subset of the template fields. For more information on configuring agents with dynamic filter templates, see the Managing Agents Tutorial.

Starting a Conversation with Citations​

Set enableCitations to true to receive inline citation markers in the answer text, indicating which source documents support each part of the response.

POST {{baseUrl}}/qna/agents/{{agentId}}/conversations
Authorization: Bearer {{accessToken}}
Hxp-Environment: {{environmentKey}}
Hxp-App: cin-ece-kd
Content-Type: application/json

{
"question": "What is the company's leave policy?",
"enableCitations": true
}

enableCitations can also be combined with dynamicFilter and contextObjectIds in the same request. When omitted or set to false, citation markers are not included in the answer.

Part 2: Ask Follow-Up Questions​

Once you have a conversationId, you can continue the conversation by sending follow-up questions. The agent will use previous messages in the conversation as context.

POST {{baseUrl}}/qna/agents/{{agentId}}/conversations/{{conversationId}}/messages
Authorization: Bearer {{accessToken}}
Hxp-Environment: {{environmentKey}}
Hxp-App: cin-ece-kd
Content-Type: application/json

{
"question": "Can you provide more details about the timeline?",
"contextObjectIds": null,
"dynamicFilter": null
}

Response​

The response contains a ConversationMessageDto with the new question and answer, similar to the initial message:

{
"id": "b2c3d4e5-f6a7-8901-2345-678901abcdef",
"answer": "The latest update shows the project timeline is on track with an expected completion date of Q2 2026.",
"documentReferences": [
{
"documentId": "doc002",
"references": [
{
"referenceId": "ref002",
"rankScore": 0.92,
"rank": 1
}
]
}
],
"question": "Can you provide more details about the timeline?",
"feedback": null,
"staticFilter": null,
"dynamicFilter": null,
"dateCreated": "2025-12-02T10:35:00Z",
"dateAnswered": "2025-12-02T10:35:03Z",
"agentVersion": 1,
"status": "Answered",
"provenance": {
"origin": "ai-generated",
"fields": ["/answer"]
}
}
Context Awareness

The agent understands that "the timeline" refers to the project mentioned in the first question, demonstrating context retention across the conversation.

note

Follow-up messages also accept enableCitations (optional boolean). Set it to true on individual messages to request citations for that specific response, independently of whether citations were enabled for the conversation's first message.

Part 3: Streaming Conversations​

Instead of waiting for a complete answer, you can observe the agent's progress as a Server-Sent Events (SSE) stream. This reduces perceived latency and allows you to display incremental text and tool-call activity.

ECE Feature Flag

Streaming endpoints require the ECE feature flag to be enabled for your environment. GraphRag agents (those using the cin-ece-kd application key) bypass this requirement and always have access to streaming, regardless of whether the ECE feature flag is enabled.

Start a Conversation with Streaming​

POST {{baseUrl}}/qna/agents/{{agentId}}/conversations/stream
Authorization: Bearer {{accessToken}}
Hxp-Environment: {{environmentKey}}
Hxp-App: cin-ece-kd
Content-Type: application/json
Accept: text/event-stream

{
"question": "What is the status of the project?"
}

Continue a Conversation with Streaming​

POST {{baseUrl}}/qna/agents/{{agentId}}/conversations/{{conversationId}}/messages/stream
Authorization: Bearer {{accessToken}}
Hxp-Environment: {{environmentKey}}
Hxp-App: cin-ece-kd
Content-Type: application/json
Accept: text/event-stream

{
"question": "When is the new deadline?"
}

SSE Event Reference​

Each SSE event contains a JSON payload in the format data: <json>\n\n. The type field in the JSON payload identifies the event type:

Event typeDescription
response.createdEmitted once at the start of the stream. Contains the upstream response object and the conversationId added by Knowledge Discovery.
response.output_text.deltaIncremental text in delta, with id identifying the upstream response and role set to assistant.
response.function_call_arguments.doneContains id (upstream response ID), itemId (tool-call ID), name, and arguments as a JSON-encoded string.
response.completedFinal event when the full answer is ready. Contains the complete message object and, for new conversations, a conversation object.
response.incompleteFinal event when a guardrail blocks the answer or an upstream failure interrupts the response. Guardrail blocks contain a message with status: "Blocked" and a fixed refusal answer, plus a conversation for new conversations. Other incomplete responses contain responseId and incompleteDetails.
response.errorEmitted if an error occurs. Contains error (description) and optional code (for example, 401).

response.created includes provenance before the first answer delta, declaring both /answer and /followUpPrompts, even when follow-up prompts are disabled. This describes supported output and does not guarantee either field is generated. Deltas inherit the declaration for their stream.

Completed and incomplete events include provenance only for generated content carried in that terminal payload. Status-only incomplete events and fixed refusals omit it. Upstream incomplete events retain their existing payload structure; provenance does not introduce a message wrapper. An interruption does not guarantee a terminal event and does not revoke attribution of text already received. The server does not replay prior deltas or add a terminal event to deliver provenance.

The message ID is available in the HTTP response's X-Correlation-Id header and later as message.id in response.completed. The upstream response.id and delta or tool-call id identify the agent response, not the Knowledge Discovery message. response.created does not contain messageId.

Example Stream Output:

data: {"type":"response.created","response":{"id":"resp_001","model":"amazon.nova-micro-v1:0","object":"response","createdAt":1764671400,"output":null,"customOutputs":null},"conversationId":"a1b2c3d4-e5f6-7890-abcd-ef1234567890","provenance":{"origin":"ai-generated","fields":["/answer","/followUpPrompts"]}}

data: {"type":"response.function_call_arguments.done","id":"resp_001","itemId":"call_001","name":"search_vector_db","arguments":"{\"natural_language_question\": \"What is the status of the project?\"}"}

data: {"type":"response.output_text.delta","id":"resp_001","role":"assistant","delta":"Based on the documents, the project is currently in progress.","customOutputs":null}

data: {"type":"response.completed","message":{"id":"f1e2d3c4-b5a6-7890-1234-567890abcdef","answer":"Based on the documents, the project is currently in progress.","documentReferences":[{"documentId":"doc001","references":[{"referenceId":"ref001","rankScore":0.95,"rank":1}]}],"question":"What is the status of the project?","feedback":null,"staticFilter":null,"dynamicFilter":null,"dateCreated":"2025-12-02T10:30:00Z","dateAnswered":"2025-12-02T10:30:05Z","agentVersion":1,"status":"Answered"},"conversation":{"id":"a1b2c3d4-e5f6-7890-abcd-ef1234567890","name":"Project status","description":null,"lastModified":"2025-12-02T10:30:00Z"},"provenance":{"origin":"ai-generated","fields":["/answer"]}}
tip

Use the response.completed event to retrieve the full structured response including documentReferences. The conversation field in response.completed is only populated for the first message (start conversation); it is null for follow-up messages.

If the agent's guardrail blocks the response, you receive response.incomplete instead of response.completed. In that case, message.status is "Blocked" and message.answer contains a fixed refusal. Blocked messages are saved to question history.

For other incomplete responses, the event is forwarded with responseId and incompleteDetails instead of a message object. Inspect incompleteDetails.reason and incompleteDetails.message for the cause. An upstream failure, such as a missing knowledge graph, is not saved to question history. The failed attempt leaves no record in Part 4: List Conversation Messages, and no response.error or response.completed event follows it.

The answer is extracted from the last assistant message in the completed response output. If the model produces multiple output items, only the final assistant message is used to populate the answer.

Part 4: List Conversation Messages​

You can retrieve the history of messages within a conversation using cursor-based pagination.

GET {{baseUrl}}/qna/agents/{{agentId}}/conversations/{{conversationId}}/messages?pageSize=50&maxContentLength=500
Authorization: Bearer {{accessToken}}
Hxp-Environment: {{environmentKey}}
Hxp-App: cin-ece-kd

Query Parameters​

ParameterRequiredDefaultDescription
cursorNonullCursor token for fetching the next page
pageSizeNo100Number of items per page (1-100)
maxContentLengthNonullMaximum length of question/answer content (10-1000)
fieldsNonullComma-separated list of fields to include in response

Response Structure​

{
"data": [
{
"id": "f1e2d3c4-b5a6-7890-1234-567890abcdef",
"answer": "Based on the documents, the project is currently in progress.",
"documentReferences": [
{
"documentId": "doc001",
"references": [
{
"referenceId": "ref001",
"rankScore": 0.95,
"rank": 1
}
]
}
],
"question": "What is the status of the project?",
"feedback": "Good",
"staticFilter": null,
"dynamicFilter": null,
"dateCreated": "2025-12-02T10:30:00Z",
"dateAnswered": "2025-12-02T10:30:05Z",
"agentVersion": 1,
"status": "Answered",
"provenance": {
"origin": "ai-generated",
"fields": ["/answer"]
}
},
{
"id": "b2c3d4e5-f6a7-8901-2345-678901abcdef",
"answer": "The latest update shows the project timeline is on track...",
"documentReferences": [
{
"documentId": "doc002",
"references": [
{
"referenceId": "ref002",
"rankScore": 0.92,
"rank": 1
}
]
}
],
"question": "Can you provide more details about the timeline?",
"feedback": null,
"staticFilter": null,
"dynamicFilter": null,
"dateCreated": "2025-12-02T10:35:00Z",
"dateAnswered": "2025-12-02T10:35:03Z",
"agentVersion": 1,
"status": "Answered",
"provenance": {
"origin": "ai-generated",
"fields": ["/answer"]
}
}
],
"pagination": {
"nextCursor": null,
"hasMore": false
}
}

Understanding Cursor Pagination​

Unlike page-based pagination (used in single-shot question history), conversation messages use cursor-based pagination:

FieldTypeDescription
pagination.nextCursorstring (nullable)Token to fetch the next page; null if no more pages
pagination.hasMorebooleanIndicates whether more messages are available

To fetch the next page, pass the nextCursor value as the cursor query parameter.

Part 5: Get a Single Message​

To retrieve a specific message (for example, when a user opens a detailed view), use the message ID.

GET {{baseUrl}}/qna/agents/{{agentId}}/conversations/{{conversationId}}/messages/{{messageId}}
Authorization: Bearer {{accessToken}}
Hxp-Environment: {{environmentKey}}
Hxp-App: cin-ece-kd

The response is a single ConversationMessageDto object with full details about the message.

Part 6: Provide Feedback on Messages​

Feedback on conversation answers is recorded per message, similar to single-shot questions.

POST {{baseUrl}}/qna/agents/{{agentId}}/conversations/{{conversationId}}/messages/{{messageId}}/feedback
Authorization: Bearer {{accessToken}}
Hxp-Environment: {{environmentKey}}
Hxp-App: cin-ece-kd
Content-Type: application/json

{
"feedback": "Good"
}

feedback (enum)​

ValueMeaning
GoodAnswer was helpful and accurate
BadAnswer was not helpful or contained errors
RetryRequest to regenerate the answer
Trust Loop feedback

When the trustLoopFeedback feature flag is enabled for your environment, you can submit structured feedback with categories and free-text details using PUT on the same endpoint instead of POST:

PUT {{baseUrl}}/qna/agents/{{agentId}}/conversations/{{conversationId}}/messages/{{messageId}}/feedback
Authorization: ******
Hxp-Environment: {{environmentKey}}
Hxp-App: cin-ece-kd
Content-Type: application/json

{
"feedbackType": "Bad",
"feedbackCategories": ["Incorrect", "Outdated"],
"userFeedbackDetails": "The answer references a deprecated policy."
}

The request returns 200 OK with the updated MessageFeedbackDto if feedback already exists for the message, or 201 Created with the new MessageFeedbackDto otherwise. feedbackCategories must be valid for the selected feedbackType (see the FeedbackCategory schema in the API Reference), must not contain duplicates, and Bad feedback requires at least one category. userFeedbackDetails is required when Other is included in feedbackCategories and is limited to 500 characters.

Use GET on the same endpoint to retrieve the recorded Trust Loop feedback, and DELETE to remove it. Agent managers can review aggregated Trust Loop feedback for an agent using GET /agents/{agentId}/feedback (list), GET /agents/{agentId}/feedback/metrics (aggregated metrics), and GET /agents/{agentId}/feedback/{feedbackId} (full submission details including the original question, answer, and references). See the API Reference for the complete request and response schemas.

Part 7: Manage Conversations​

List All Conversations for an Agent​

Retrieve all conversations associated with an agent.

GET {{baseUrl}}/qna/agents/{{agentId}}/conversations?pageSize=20
Authorization: Bearer {{accessToken}}
Hxp-Environment: {{environmentKey}}
Hxp-App: cin-ece-kd

Query Parameters​

ParameterRequiredDefaultDescription
cursorNonullCursor token for fetching the next page
pageSizeNo20Number of items per page (1-100)

Response​

{
"data": [
{
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"name": "Project Status Discussion",
"description": "Conversation about current project status",
"lastModified": "2025-12-02T10:35:00Z"
},
{
"id": "b2c3d4e5-f6a7-8901-bcde-f12345678901",
"name": null,
"description": null,
"lastModified": "2025-12-01T15:20:00Z"
}
],
"pagination": {
"nextCursor": "eyJsYXN0SWQiOiJiMmMzZDRlNS1mNmE3LTg5MDEtYmNkZS1mMTIzNDU2Nzg5MDEiLCJsYXN0TW9kaWZpZWQiOiIyMDI1LTEyLTAxVDE1OjIwOjAwWiJ9",
"hasMore": true
}
}

Get Conversation Details​

Retrieve metadata for a specific conversation.

GET {{baseUrl}}/qna/agents/{{agentId}}/conversations/{{conversationId}}
Authorization: Bearer {{accessToken}}
Hxp-Environment: {{environmentKey}}
Hxp-App: cin-ece-kd

Update Conversation Metadata​

Update the name and description of a conversation for better organization.

PUT {{baseUrl}}/qna/agents/{{agentId}}/conversations/{{conversationId}}
Authorization: Bearer {{accessToken}}
Hxp-Environment: {{environmentKey}}
Hxp-App: cin-ece-kd
Content-Type: application/json

{
"name": "Project Status Q2 2025",
"description": "Discussion about project timeline and deliverables for Q2"
}

Update Request Parameters​

FieldRequiredDescription
nameYesConversation name (for display/organization)
descriptionNoOptional longer description of the conversation purpose

Summary​

In this tutorial, you learned how to:

✅ Start multi-turn conversations with agents
✅ Ask follow-up questions that use previous context
✅ Receive incremental responses using SSE streaming endpoints
✅ List and retrieve conversation messages
✅ Provide feedback on conversation messages
✅ Manage conversation metadata (list, view, update)

Next Steps​