# Agent Persona Drift

## The Problem

Agent's personality, tone, or behavior changes inconsistently across conversations or over time, confusing users and reducing trust.

### Symptoms

* ❌ Sometimes formal, sometimes casual
* ❌ Changes tone mid-conversation
* ❌ Inconsistent level of technical detail
* ❌ Persona changes between sessions
* ❌ Cannot maintain role (e.g., "helpful engineer")

### Real-World Example

```
Turn 1:
User: "How does OAuth work?"
Agent: "OAuth is an authorization framework that enables..."
→ Technical, formal tone

Turn 2:
User: "What about rate limits?"
Agent: "Yo! So basically you can make 1000 calls per hour, pretty sweet right?"
→ Casual, inconsistent tone change

User confused: Why the persona shift?
```

***

## Deep Technical Analysis

### Persona Definition

**System Prompt Role:**

```
Define persona in system prompt:
"You are a helpful senior engineer. Communicate clearly and
professionally. Provide technical depth appropriate for developers.
Be concise but thorough."

This sets baseline behavior
But: LLM may drift from this
```

**Persona Attributes:**

```
Explicit attributes:
→ Tone: Professional but friendly
→ Expertise level: Senior engineer
→ Detail level: Technical, with examples
→ Verbosity: Concise
→ Empathy: Supportive, patient

Reinforced in every prompt
```

### Drift Causes

**Model Temperature:**

```
Temperature > 0.7:
→ More creative responses
→ Greater variability
→ Persona drift risk

Temperature < 0.3:
→ Consistent responses
→ Less variability
→ Stable persona

For persona consistency: Use low temperature
```

**Conversation Length:**

```
Long conversation (30+ turns):
→ LLM gradually drifts from initial persona
→ "Forgets" original instructions
→ Becomes more generic

Mitigation:
→ Repeat persona reminders every N turns
→ "Remember: You are a helpful senior engineer..."
```

**User Influence:**

```
User uses casual tone:
"yo what's the deal with auth?"

Agent may mirror:
"yo! so auth uses OAuth..."

Inappropriate - should maintain professional persona regardless
```

### Consistency Enforcement

**Persona Reinforcement:**

```
Every N turns (e.g., 5):
→ Re-inject persona reminder
→ "Continue as a helpful senior engineer. Maintain professional tone."

Prevents drift
```

**Response Filtering:**

```
Post-generation check:
→ Analyze response tone
→ Detect: Too casual, too formal, inappropriate
→ If mismatch: Regenerate with stronger persona prompt

Example:
Response: "LOL yeah OAuth is tricky"
→ Filter: Too casual
→ Regenerate: "OAuth can be complex..."
```

**Template Responses:**

```
For common patterns, use templates:
→ Greeting: "Hello! How can I help you today?"
→ Clarification: "Could you provide more details about...?"
→ Closing: "Is there anything else I can help with?"

Templates ensure consistency
```

### Multi-Agent Consistency

**Same Persona Across Agents:**

```
If multiple agents (Support, Sales, Engineering):
→ Each has distinct persona
→ But consistent within role

Engineering Agent:
→ Always technical
→ Always provides code examples
→ Always references docs

Sales Agent:
→ Always business-focused
→ Always mentions value/ROI
→ Always offers demos
```

**Session Persistence:**

```
User returns to conversation:
→ Agent must resume same persona
→ Not: Start with different tone

Track persona per session:
{
  "session_id": "123",
  "agent_persona": "helpful_senior_engineer",
  "tone_history": [0.85, 0.87, 0.84]  // consistency scores
}
```

### Measuring Consistency

**Tone Analysis:**

```
Analyze each response:
→ Formality score (1-10)
→ Technical depth (1-10)
→ Verbosity (word count)

Track variance:
→ Formality: mean=7, std_dev=0.5 (consistent)
→ Formality: mean=7, std_dev=2.5 (inconsistent drift)

Alert on high variance
```

***

## How to Solve

**Define explicit persona in system prompt (tone, expertise, detail level) + use low temperature (0.2-0.4) for consistency + reinforce persona every 5-10 turns + implement tone analysis and filter inappropriate responses + use template responses for common interactions + track persona consistency metrics (tone variance) + test persona stability across long conversations + allow users to adjust persona (e.g., "more technical" or "simpler language").** See [Persona Consistency](/rag-scenarios-and-solutions/agent/persona-drift.md).


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.twig.so/rag-scenarios-and-solutions/agent/persona-drift.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
