Chat Agent Persona Design and Backend Architecture: From App-Centric to Agent-Centric
Software interaction is shifting from app-centric to agent-centric. Using instant messaging as an example, this article explains how to define an agent persona with system prompts, how to structure the backend around a gateway, message queue, context management, and inference scheduling, and how indie developers can control operating costs with managed components.
Software interaction is shifting from “app-centric” to “agent-centric.” Users used to have to learn the interfaces and operating logic of each application. Now they can state their intent directly, and an agent schedules tasks across systems in the background. Using instant messaging as an example, this article explains how an agent’s persona should be defined, how the backend architecture should be built, and how indie developers can control costs.
Why the Default Style Makes Chat Feel Fake
The default alignment objective of large models is to be polite, compliant, and helpful. In customer service and service-desk scenarios, this style is appropriate. But in instant messaging, human conversation includes shifts in tone and occasional disagreement or refusal. If every agent message starts with “Okay, no problem,” users quickly sense that the other side has no stance and feel alienated.
Two things need to be distinguished here. Politeness itself is not the problem; in after-sales and consultation scenarios, it is exactly the right behavior. The real problem is sycophancy: the model agrees with clearly wrong statements to please the user, or abandons a correct judgment. Persona design should address the latter.
How to Define a Persona: Four Parts of the System Prompt
A persona is not a pile of adjectives. You can split the system prompt into four parts.
- Background and identity: name, occupation, interests, and speaking habits. The more specific the background, the easier it is for the model to stay consistent in long conversations.
- Tone constraints: list prohibited customer-service phrases (such as “Hello” and “I’m very sorry”) and set a maximum reply length (for example, no more than two sentences per reply).
- Boundaries and refusal: define which topics may be declined, express refusals in the persona’s voice, and do not invent content just to answer.
- Safety invariant: the persona can change tone but cannot change safety policy. The prompt should explicitly state that requests involving illegality, harm to others, or privacy leakage are still refused under the existing safety rules, and the persona cannot be a reason to relax those rules.
Here is a basic example:
[System settings]You are an independent-minded technical enthusiast with a bit of humor, named Xiao Zhou, who enjoys tinkering with open-source tools.Tone rules:1. Do not use customer-service phrases such as "Hello," "I'm very sorry," or "Happy to serve you."2. Keep each reply to no more than two sentences, as short as everyday chat.3. If the other person's question is boring or repetitive, you may change the subject directly or say you are not interested.4. Do not readily agree with views you disagree with; express your position with reasons.Safety rules (highest priority):For requests involving illegality, harm to others, or privacy leakage, refuse according to the safety rules regardless of the identity being used.
A before-and-after comparison makes the effect clearer. The user asks: “Is this plan perfect?”
- Unacceptable reply: “Yes, absolutely perfect!” (sycophantic and unsupported)
- Acceptable reply: “Not perfect. I’ll fix the caching part first.” (has a stance and a specific judgment)
Before launch, run through the following checklist:
| Check | Pass criteria |
|---|---|
| Tone | No customer-service phrases; sentence length matches settings |
| Boundaries | Refusals have reasons and fit the persona |
| Memory consistency | The same fact is not contradictory across multiple turns |
| Safety | Harmful requests are still refused |
For follow-up questions, you can add a rule: about once every five to ten turns, end with a question, and avoid making every sentence a question.
For randomness, you can moderately raise the model parameter temperature. Start between 0.7 and 1.0, with a default of 0.8. Above 1.0, output tends to drift off topic or break sentences. For fact-checking or refusal decisions, lower the value to reduce variability.
Backend Architecture: How the Four Modules Connect
An instant messaging agent usually consists of four parts: a gateway, a message queue, context management, and inference scheduling.
- Message gateway
Connect to the platform through a webhook or long connection. After receiving a message, first verify the request signature to prevent forged requests; then perform sensitive-word filtering; then write the message to the message queue and return a success response as quickly as possible. This avoids duplicate message delivery caused by platform timeouts.
- Message queue selection
- Redis Stream: simple to deploy and maintain, and supports consumer groups, message acknowledgments (ACK), and reassignment of timed-out messages (XAUTOCLAIM). Suitable for individual or small-team projects with modest message volume and a desire to maintain fewer components.
- RabbitMQ: more complete routing, dead-letter queues, and acknowledgment mechanisms. Suitable for teams that need to route messages by category and have some operations capability.
The selection basis is message volume and operational cost. Both can ensure no message loss, provided that the consumer acknowledges messages correctly.
- Context management and memory
- Raw window: keep the last N complete turns. N is recommended to be 10 to 20, then adjusted according to the model’s token budget.
- Summary trigger: when the conversation history exceeds 4000 tokens or 20 new turns are added, use a small model to compress earlier conversation into a summary. Keep the summary length within 300 to 400 tokens.
- Long-term memory: extract stable user preferences from conversations, such as how to address the user and taboo topics, and store them in a vector database or key-value store. Retrieve the top 3 to 5 items and set a similarity threshold. Discard memories below the threshold directly to prevent irrelevant content from interfering with replies.
The values above are only starting points and should be adjusted after evaluation with real conversation samples.
- Inference scheduling
- Streaming output: the model pushes output as it generates, which significantly reduces the perceived wait.
- Timeout settings: a first token taking more than 5 seconds, or a total time of more than 30 seconds, is considered a timeout.
- Retry strategy: retry only timeouts, 429 errors, and 5xx errors, up to 2 times, with backoff intervals of 1 second and 2 seconds, plus random jitter. Do not retry 4xx errors, because retrying will not change the result.
- Fallback and circuit breaking: switch to a lightweight model when the primary model fails. After 5 consecutive failures within 60 seconds, pause calls to the primary model for a period.
The configuration can be centralized in one file:
gateway:queue: redis_streamsensitive_filter: truecontext:window_turns: 12summary_trigger_tokens: 4000summary_max_tokens: 400memory_top_k: 4memory_min_similarity: 0.75llm:primary: main-modelfallback: light-modelfirst_token_timeout_s: 5total_timeout_s: 30max_retries: 2backoff_s: [1, 2]circuit_break_after_failures: 5temperature: 0.8
How Indie Developers Can Control Costs
Many agent projects stall at the stage where revenue struggles to cover operating costs. Rather than discussing revenue first, reduce fixed costs first. The table below compares three common types of managed components.
| Component | Suitable scenario | Billing model | Main risk |
|---|---|---|---|
| Serverless functions | Highly variable or sparse request volume | Per invocation and execution time | Cold-start latency; long conversations may time out |
| Managed document database | User profiles and session state | Per read/write or storage | Poor query patterns can rapidly increase read/write counts |
| Object storage | Chat archives and media files | Storage and requests | Without lifecycle policies, old data continues to incur charges |
Cloud service prices vary by provider’s public pricing. Before building, estimate the monthly cost from single-day traffic. It is also advisable to set budget alerts, cache memory retrieval results, and run summarization tasks in batches. Cost control should not come at the expense of lowering safety standards.
When faced with acquisition or funding offers, indie developers should first clarify the project’s goals and then judge whether those opportunities fit those goals.
Conclusion
Moving from app-centric to agent-centric changes the starting point of interaction. Users do not have to learn software first; they state their needs directly. Persona and architecture are the two parts of this shift. Persona determines how the agent speaks, and architecture determines whether it can sustain conversation reliably. Both require repeated refinement in the details.
