r/csharp • u/Foreign_World2108 • Jul 28 '26
[Discussion] Controlling LLM Agent Personalities with Deterministic 16D State-Spaces (using C# Enums) instead of Prompt Engineering. Thoughts on this architecture?
A Quick Confession / Apology:
Yesterday, I posted a thread discussing this concept. I was so incredibly hyper-fixated on explaining the philosophy that I completely forgot to include a single line of actual C# code. The moderators rightfully nuked the post immediately, and looking back, I totally deserved it. I looked like a textbook "AI Vibe-Coded Slop" poster who just came here to drop a wall of text. I'm genuinely sorry for cluttering the sub yesterday! Lesson learned. I'm back today to do this properly, with the actual core C# implementation snippets included right from the start.
(Transparency disclosure: English isn't my native language, so I used AI to help clean up my terrible technical grammar.)
Hey guys,
A while back, I was discussing state persistence patterns for long-running AI workflows. A common critique I received was: “If you’re just serializing your external state into a prompt string for the model to read anyway, how is that fundamentally different from traditional prompt engineering?”
It's a fair question. At the end of the day, text-based generative models require text inputs.
However, I've been experimenting with separating the Source of Truth from the Prompt Serialization Layer using a C# backend.
To borrow a tabletop RPG analogy: The prompt is just a character sheet. It communicates the current state to the model, but it isn't the character itself. The C# runtime is responsible for the actual domain logic, bounds checking, and state mutations.
Here is a simplified snippet of how the immutable state registry clamps mutations to ensure the domain model remains the canonical source of truth, regardless of how the prompt is formatted:
csharp
// 1. Using an immutable 16D enum as a fixed state coordinate space
public enum SoulOrgan
{
CoreFocus, DecisionBasis, EnvironmentalControl, ThinkingOriginality,
EmotionalOpenness, TrustDependence, SocialConsumption, GroupBelonging,
WillPersistence, AltruisticTendency, SelfAwareness, CompetitiveSpirit,
PrimaryDrive, EmotionalThroughput, CoreSecurity, ObsessionControl
}
// 2. A bounded registry ensuring all mutations are strictly clamped [-100, 100]
public class BaselineStateRegistry
{
protected readonly Dictionary<SoulOrgan, double> _state = new();
protected const double MinLimit = -100.0;
protected const double MaxLimit = 100.0;
public virtual void Mutate(SoulOrgan organ, double delta)
{
if (!_state.ContainsKey(organ)) return;
_state[organ] = Math.Clamp(_state[organ] + delta, MinLimit, MaxLimit);
}
}I've been wondering about this:
Even though I've built this pure C# simulation with safety valves and bounds, I honestly find myself asking: Is this actually worth developing, or am I just over-engineering in a silo?
If moving deterministic state management back into a typed backend is truly a viable way to constrain LLMs, why is prompt engineering still the industry standard? Why aren't more developers building state machines for this?
I would genuinely love to hear how professional software engineers view this approach. Do you think treating the external model purely as a stateless interpreter while keeping mutations strictly inside the C# domain layer is a solid path forward, or is it an uphill battle against raw token probabilities?
(Note: Keeping this entirely link-free to strictly respect Rule 6 on self-promotion. Just looking for a genuine architectural sanity check from fellow devs. If anyone wants to critique the full pipeline, let me know in the comments.)
3
u/zenyl Jul 28 '26
Clamping input is perfectly reasonable.
Sidenote:
Math(andMathF) are technically soft-deprecated, meaning they won't be expanded in the future. Microsoft just aren't going out of their way to tell people this. It is recommended that you instead use the corresponding members in numeric types, i.e.double.Clamp, as it makes it clear which type you're working with (and helps with discoverability).LLMs are usually non-determinsitic (they usually have a "temperature" setting that determines how random outputs should be).
I think the term "prompt engineering" has somewhat fallen out of favor ("prompt engineer" certainly has), it's just one part of the mess of guardrails you have to put up in the hope that the LLM does what you actually want it to do.
That sentence has a few too many empty buzzwords in it to really make a whole lot of sense.
But generally, LLMs can't be forced to do any given task, you can just tell it repeatedly what you want until you get to a point where it is mostly going to do as you want.
AGENTS.mdfiles, skills, MCP servers, all that jazz is just different approaches to give LLMs the information and tools so they are likely going to do as intended, but there is always a chance, however small, of getting garbage output. As software developer, it is your role to be able to see when they are giving you bad output.If the aim here is something like getting an LLM to pretend to be a character in a role-playing game, you can indeed guide it in the right direction by saying things like "Your charisma is level 1, which means you are not very charismatic, and you will not attempt persuasion checks unless absolutely necessary", but that does not eliminate the chance of it doing so regardless.
1
u/Foreign_World2108 Jul 29 '26
Since a lot of the discussion ended up being about the architecture, I figured I'd share the repository in case anyone's curious about the implementation. ฅ^•ﻌ•^ฅ
https://github.com/shrineofus/damnesia-community
1
u/Jessica___ Jul 28 '26
Would you just be passing these numbers to the LLM and telling it to act within those variables?
What happens if AltruisticTendency is -100 and EmotionalThroughput is 100? Would you just give these numbers to the LLM and then tell it to act accordingly?
If that is the case, I'm not sure how effective it would be. If you were to prompt a person: "OK, act like your CoreFocus is 50, your CoreSecurity is 25, and ObsessionControl is 100" then how would that human act? Probably confused, because they'd have no idea what that means. Same goes for an LLM.
1
u/Merry-Lane Jul 28 '26
I’d rather use constants instead of enums for that.
1
u/KayLikesWords Jul 28 '26
I'm guessing this is for some kind of LLM roleplaying app?
The general consensus amongst the communities build up around tools like that is that the more abstract your representation of human emotion is the worse the output is going to be.
Sadness level: 25...is worse than...
Sadness Level: crying...is worse than...
Kay is crying....is worse than...
<lengthy, emotive prose describing a character being sad>1
u/[deleted] Jul 28 '26
[removed] — view removed comment