Gate4 Conversation Contract
Objective
Define one conversation contract shared by CLI, Web, and OpenClaw, with additive /v2 API semantics.
Endpoints
POST /v2/conversations/sessionsGET /v2/conversations/sessions/{sessionId}POST /v2/conversations/sessions/{sessionId}/turns
Core Semantics
- Session creation requires explicit
channelvalue. - Channel enum is normalized:
cli | web | openclaw. - Turn creation appends immutable turn records and updates session timestamps.
- Missing session IDs return canonical
ErrorResponsewith404. - Conversation contract is additive under
/v2;/v1remains unchanged.
Context Memory Semantics (CONV-02)
- Memory is scoped per
tenant_id:user_idand reused across that user's conversation sessions. - Each turn updates bounded context memory:
- recent messages (bounded by retention policy),
- inferred intent (
deploy | backtest | order | risk | portfolio), - linked trading artifacts (
strat-*,dep-*,ord-*,portfolio-*,bt-*,dataset-*), - symbol references (for example
BTCUSDT).
- Session metadata exposes current memory under
contextMemory. - Turn metadata includes
contextMemorySnapshotso clients can render deterministic multi-turn context. - Memory is isolated by user identity and does not leak across users.
Proactive Suggestions and Notifications (CONV-03)
- Turn processing emits proactive suggestions based on message intent and context-memory state.
- Notification delivery is controlled by session-level opt-in (
metadata.notificationsOptIn). - Opted-in sessions receive structured notification payloads in turn metadata.
- Every emitted notification writes an audit record with session/turn identity and severity/category metadata.
- Opted-out sessions still receive suggestions but no notification emission.
Sequence: Multi-Turn Contract Flow
sequenceDiagram
participant C as "Client (CLI/Web/OpenClaw)"
participant API as "Platform API /v2/conversations"
participant SVC as "ConversationService"
participant MEM as "Context Memory"
participant AUD as "Notification Audit"
C->>API: POST /sessions (channel, topic, metadata)
API->>SVC: create_session()
SVC->>MEM: initialize/load per-user memory
SVC-->>C: session(id, metadata.contextMemory)
C->>API: POST /sessions/{id}/turns (message)
API->>SVC: create_turn()
SVC->>MEM: update memory (intent, artifacts, symbols, retention)
SVC->>SVC: derive suggestions + proactive notifications
alt notificationsOptIn=true
SVC->>AUD: persist notification records
end
SVC-->>C: turn(suggestions, metadata.contextMemorySnapshot, metadata.notifications)
Failure and Fallback Behavior
| Condition | Expected Response | Client Handling |
|---|---|---|
| Unknown session ID | 404 CONVERSATION_SESSION_NOT_FOUND | Surface error with requestId; do not synthesize a replacement session |
| Invalid turn payload | 422 validation error | Prompt user to correct payload; keep existing session state |
| Notification opt-out | notifications=[] and no audit writes | Continue with suggestions-only UX |
| Internal error | canonical ErrorResponse with requestId | Preserve correlation ID and retry through same Platform API route only |
Client Compatibility Notes
- OpenClaw must create sessions with
channel=openclaw. - CLI/Web/OpenClaw all consume identical
/v2/conversations/*schemas. - Clients should treat
contextMemoryandcontextMemorySnapshotas additive metadata fields. - Clients should not assume notification presence; respect opt-in behavior.
Boundary Alignment
- Conversation is a public contract concern, not a provider integration.
- Conversation routes remain inside Platform API.
- Provider boundaries are unchanged: adapter-only integrations.
Traceability
- OpenAPI:
/docs/architecture/specs/platform-api.openapi.yaml - Interface definition:
/docs/architecture/INTERFACES.md - Parent epics:
#80,#106,#81 - Gate4 docs issue:
#137