Developer Guide
This guide provides an overview of the Style Suggestions feature for developers integrating or maintaining Deepdesk's agent assist capabilities. It includes the full backend documentation and a short overview of how the frontend integrates.
Purposeβ
Style Suggestions help agents improve communication by detecting specific keywords or phrases in their messages and providing actionable guidance. The system supports both real-time feedback and analytics for compliance monitoring.
Architecture Overviewβ
- Backend exposes a REST API (
POST /style-suggestions) for keyword detection. - Frontend displays eventual style suggestions to agents and sends a "style suggested" event
- When agent sends a message, the ingestion pipeline detects eventual style breaks and sends a
style breaks foundevent.
Overviewβ
Style Suggestions provide guidance to agents based on keyword triggers present in messages. The backend supports two main capabilities:
- Synchronous detection via API:
POST /style-suggestionsreturns detected keyword matches for a givenprofile_codeandmessage. - Asynchronous analytics in ingestion: when agent messages are ingested, the system detects style breaks and emits analytics events to BigQuery and ClickHouse.
The source of truth for suggestions is the Admin (Django) database. The backend reads those records via a repository.
Data model (Pydantic)β
File: backend/domains/style_suggestions/models/style_suggestion.py
class StyleSuggestion(BaseModel):
id: int
title: str
message: str
keywords: list[str]
The backend receives Django ORM rows and maps them to this Pydantic model (see Repository below).
APIβ
File: backend/domains/style_suggestions/api/routes.py
Endpoint: POST /style-suggestions
- Security:
jwt_or_oauth, requires scopeconversations:read. - Body:
StyleSuggestionRequest. - Response:
StyleSuggestionResponse.
Example:
POST /style-suggestions
Authorization: Bearer <token-with-conversations:read>
Content-Type: application/json
{
"profile_code": "retail-en",
"message": "We can't process this kind of request right now."
}
Response:
{
"keyword_matches": [
{"keyword": "can't", "title": "Avoid negative phrasing", "suggestion": "Try phrasing in positive terms ..."}
]
}
Schemasβ
File: backend/domains/style_suggestions/api/schemas.py
class StyleSuggestionRequest(BaseModel):
profile_code: str
message: str
class KeywordMatch(BaseModel):
keyword: str
title: str
suggestion: str
class StyleSuggestionResponse(BaseModel):
keyword_matches: list[KeywordMatch]
Repositoryβ
File: backend/domains/style_suggestions/repositories/style_suggestion.py
Responsibilities:
- Query the Admin (Django) ORM for
StyleSuggestionobjects associated with a Profilecode. - Map ORM instances to Pydantic
StyleSuggestionmodels. - Provide both sync (
get_by_profile_code) and async (aget_by_profile_code) variants.
Serviceβ
File: backend/domains/style_suggestions/services/style_suggestion_service.py
Responsibilities:
- For a
profile_codeandmessage, load suggestions via the repository. - Run detection using
StyleDetector. - Return a list of
KeywordMatch.
Detecting style breaksβ
File: backend/tasks.py β function publish_style_break_events
Flow:
- Validate the
Conversationobject hasprofile_code; return early if absent. - Load style suggestions for that
profile_codevia the repository. - Filter to agent-authored messages.
- Run detection with
StyleDetectorfor each agent message. - If matches exist, emit a
BigQueryStyleBreakEventper affected message.
Detection logicβ
File: backend/domains/style_suggestions/services/style_detector.py
Summary of behavior:
- Case-insensitive regex search.
- Enforces non-word boundaries so partial words do not trigger (e.g.,
canwonβt match insidecandy). - Multi-word keywords are supported; spaces in the keyword are matched with
\s+so flexible whitespace is allowed. - Quote characters in keywords are relaxed to match similar quote styles.
- Occurrences wrapped in curly braces
{ ... }are ignored via negative lookbehind/lookahead (to avoid matching templated placeholders).
Output is a list of KeywordMatch { keyword, title, suggestion } where keyword is the matched substring from the message.
Analyticsβ
For reporting we track style suggestion usage and compliance. When the backend detects style breaks in agent messages, it emits the style breaks found event to the analytics pipeline. These events help monitor the detection of style issues and the delivery of guidance to agents.
Destinations:
- BigQuery dataset/table:
{PROJECT}.{ACCOUNT_CODE}_analytics_dataset.events_v2viagoogle.cloud.bigquery.Client.insert_rows_json. - ClickHouse
eventstable viainsert_rows_into_clickhouse.delay(...).
Deprecated We are in the process of migrating to a ClickHouse-based analytics pipeline, so the BigQuery destination is still used for now.
Event payload:
- Model:
BigQueryStyleBreakEventinbackend/tasks.py. - Fields:
event_id,conversation_id,profile_code,platform_session_id,platform,agent_*fields,time_utc(ISO 8601), anddataJSON string containing{"style_breaks": [{"title", "trigger"}]}.
Info The event payload contains the external agent ID, as received from the CX platform.
Operational notesβ
- Only suggestions that are ENABLED and associated to the relevant Profiles (configured in Studio) will be effective.
- Curate keyword lists to minimize false positives; prefer specific phrases where possible.
- For dynamic placeholders in templates, wrap them in
{}to avoid matching as style breaks. - See tests under
backend/tests/domains/style_suggestions/for examples and edge cases.