Portal Community

Role in the Data Model

A conversation in Octopus is a bounded interaction session. When a user opens a chat window and sends messages, all those message turns belong to a single conversation. The Octopus_Conversations table acts as the container record — it holds session identity, timing, status, and the link to the agent that handled it.

Every row in Octopus_Episodes is a child of a row in Octopus_Conversations via the SessionId foreign key. To retrieve a full conversation history, you query episodes filtered by SessionId.

Column Reference

ColumnTypeConstraintsDescription
SessionIduniqueidentifierPK, NOT NULLGUID primary key. Returned to the client on session creation and used in all subsequent episode writes.
AgentIduniqueidentifierFK, NOT NULLReferences the agent that handled this conversation. Indexed for agent-level session reporting.
TenantIdintNOT NULL, IXMulti-tenancy discriminator. Always in the WHERE clause.
UserIdnvarchar(200)NULLThe identity of the initiating user. Can be an internal user GUID, an email, or an anonymous session token. Null for system-initiated conversations.
StartedAtdatetime2NOT NULLUTC timestamp when the session was created. Used for duration calculations and time-based filtering.
EndedAtdatetime2NULLUTC timestamp when the session was explicitly closed. Null means the session is still active (or abandoned).
Statusnvarchar(50)NOT NULLSession lifecycle status. See status values below.
Metadatanvarchar(max)NULLCaller-supplied JSON context attached at session creation. Useful for tracking channel, UI context, referrer, campaign ID, etc.

Session Status Values

StatusMeaningEndedAt
ActiveSession is open and accepting new messagesNULL
EndedSession was explicitly closed by the user or applicationSet
TimedOutSession exceeded the inactivity timeout configured for the agentSet (by retention job)
ErrorSession ended due to an unrecoverable error in the agent pipelineSet

Metadata JSON Pattern

The Metadata column accepts any valid JSON object. Common patterns used by BizFirstGO applications:

{
  "channel": "web-chat",
  "referrer": "pricing-page",
  "campaignId": "Q2-2026-trial",
  "uiSessionId": "abc123",
  "clientIp": "203.0.113.5",
  "customTags": ["vip", "trial"]
}

This metadata is never interpreted by the Octopus framework itself — it is purely for application-layer reporting and filtering.

Session Lifecycle Flow

1

Session Creation

A new row is inserted with Status = 'Active', StartedAt = UTC_NOW(), and EndedAt = NULL. The generated SessionId is returned to the caller.

2

Message Turns

Each user message and agent response creates episode rows in Octopus_Episodes linked to this SessionId. The conversation row itself is not updated during messaging.

3

Session Close

When the user ends the session (or the timeout job fires), Status is updated and EndedAt is set. No further episodes can be written to a closed session.

Common Queries

-- All active sessions for an agent
SELECT SessionId, UserId, StartedAt,
       DATEDIFF(MINUTE, StartedAt, GETUTCDATE()) AS DurationMinutes
FROM Octopus_Conversations
WHERE TenantId = @tenantId
  AND AgentId = @agentId
  AND Status = 'Active'
ORDER BY StartedAt DESC;

-- Session history for a specific user
SELECT SessionId, AgentId, StartedAt, EndedAt, Status
FROM Octopus_Conversations
WHERE TenantId = @tenantId
  AND UserId = @userId
ORDER BY StartedAt DESC;

-- Average session duration per agent (last 30 days)
SELECT AgentId,
       COUNT(*) AS SessionCount,
       AVG(DATEDIFF(SECOND, StartedAt, EndedAt)) AS AvgDurationSecs
FROM Octopus_Conversations
WHERE TenantId = @tenantId
  AND Status = 'Ended'
  AND StartedAt >= DATEADD(DAY, -30, GETUTCDATE())
GROUP BY AgentId;
Abandoned Sessions

Sessions where the user closed the browser without explicitly ending the conversation will remain Active with a null EndedAt indefinitely unless the MemoryRetentionJob times them out. Configure the SessionInactivityTimeoutMinutes setting in your Octopus agent config to control how long inactive sessions are kept open before being automatically set to TimedOut.