di35117/msme-linguistic-decoding-env
๐ง Linguistic Decoding RL
A reinforcement learning environment for long-horizon hidden state inference โ teaching an LLM agent to decode what entities actually mean, not just what they say.
The Core Problem
Language models are remarkably good at face value. Ask them what a message means and they will tell you what the words say. Ask them what the speaker intends, what they are concealing, or how their story has shifted over three conversations โ and they fail. They anchor to the surface.
This is a fundamental gap. In the real world, the most important information is rarely stated directly:
- A borrower who says "collections have been a bit slow but we're managing" may be three months from default.
- A founder who says "we're being strategic about burn" may have six weeks of runway.
- The truth lives not in the words but in the pattern across time โ the drift in tone, the gaps in documentation, the meetings that keep getting cancelled.
Linguistic decoding is the skill of inferring latent intent, hidden state, and real motive from what is said, how it is said, what is avoided, and how all of that changes across a temporal sequence. Teaching this to an AI system is a vast, open research problem. There is no clean dataset, no obvious loss function, and no single domain where it is fully solved.
Scope โ What We Built for This Hackathon
Linguistic decoding as a general problem is enormous. Narrowing it to something tractable within a hackathon timeline โ while still producing real, meaningful results โ required a deliberate choice of domain.
We chose Indian MSMEs and startups for a specific reason: both are high-stakes, information-asymmetric contexts where the cost of misreading intent is concrete and measurable. A lender or investor who takes language at face value in these settings does not just make a bad prediction โ they make a bad financial decision with real consequences. The problem is also structurally interesting because the two populations have opposite communication biases: MSME borrowers in India systematically understate distress (cultural and social pressure to appear in control), while startup founders systematically overstate health (investor signalling incentives). An agent that can navigate both โ learning to condition its interpretation on who is speaking before deciding what they mean โ is doing something genuinely non-trivial.
This is the slice we modelled, trained on, and evaluated. The environment, the world generator, the message templates, the behavioral profiles, and the reward structure are all calibrated to this specific context. The results are real within this scope. Generalizing the framework to other domains โ legal negotiation, medical disclosure, conflict resolution, political communication โ is the natural next step, but that is future work.
Why RL for This
Supervised learning teaches an agent to match outputs to labels. It cannot teach an agent to reason under uncertainty across time โ to hold a hypothesis about a speaker's true state, update it as new signals arrive, and commit to an action whose consequences only materialize steps later.
This is a long-horizon planning problem. The right intervention at step 30 depends on what happened at steps 1 through 29. A premature escalation on a healthy entity is as damaging as inaction on a failing one. The agent must learn not just what to infer but when to act on it โ and how much weight to give a single message versus an accumulated pattern.
GRPO-based training over multi-step episodes with delayed episode rewards makes this tractable โ rewarding the agent for the quality of its full trajectory, not just individual decisions.
What the Agent Learns
At each step, the agent:
- Receives a biased natural language message from the entity
- Observes behavioral proxies โ response latency, document completion rate, meeting cancellations, escalation avoidance
- Maintains a running estimate of the hidden stress level across the episode:
healthy โ watch โ substandard โ doubtful โ loss - Selects a policy action from the intervention menu
- Receives a step reward for action appropriateness and an inference bonus for correctly identifying the hidden state
- Refines its policy across episodes via GRPO
The ground truth is never revealed during the episode. The agent must earn its estimate from accumulated evidence โ exactly as a real analyst would.
World Modelling
The environment generates a fully synthetic but internally consistent world for each episode. Every episode is a new entity โ new hidden state, new financial profile, new behavioral disposition, new speaker bias. The world is not static; it evolves as the agent acts on it.
Each entity is characterized by:
- A true stress level drawn from a calibrated distribution per domain โ invisible to the agent
- A financial snapshot โ revenue growth, cash runway, debt service coverage, receivables overdue, burn rate โ consistent with the stress level but not directly observable
- A behavioral profile โ response latency, document completion, meeting cancellations, escalation avoidance โ which drifts as the entity's condition changes across steps
- A speaker bias โ the systematic tendency to understate (MSME) or overstate (startup) true condition, injected into every generated message
The world evolves across steps. A well-timed field visit slows deterioration. Inaction accelerates it. Messages and behavioral signals update each step to reflect the new underlying state. The agent is not reading a static transcript โ it is navigating a living system that responds to its choices.
The world modelling is what prevents the agent from memorizing patterns. It must generalize a reasoning process that works across varied entities, bias levels, financial conditions, and deterioration trajectories.
Environment Design
Domains
Training across both domains is intentional โ opposite bias directions force the agent to condition on who is speaking before interpreting what they say.
Stress Levels (Hidden State)
healthy โ watch โ substandard โ doubtful โ lossIntervention Actions
| Action | Best Used When | @@ -109,10 +101,10 @@ Each level maps to calibrated financial snapshots, behavioral profiles, and mess
Reward Structure
- Step reward โ action appropriateness against true stress level (
-1.0 โ +1.0) - Inference bonus โ
+0.4for correctly naming the hidden stress level; partial credit for adjacent estimates - Critical miss penalty โ
-0.5fordo_nothingorschedule_follow_upondoubtfulorlossentities - Episode reward โ trajectory bonus for net stress reduction; terminal penalty for entities that end worse than they started
@@ -133,8 +125,8 @@ Domain Adapter Registry domains/_init.py โผ MSME + Startup Adapter domains/msmestartup/adapter.py โ โโโโถ worldgenerator.py โ hidden state + financial + behavioral synthesis โโโโถ messagegenerator.py โ biased NL message generation per step โโโโถ reward.py โ step + episode reward logic โโโโถ network.py โ peer entity contagion effects โโโโถ memory.py โ cross-step state accumulation @@ -144,9 +136,7 @@ MSME + Startup Adapter domains/msme_startup/adapter.py
Training Results
We trained for 30 episodes with each episode capped at 90 steps, fine-tuning a Qwen 1.5B model with GRPO on this reinforcement learning task. Both numbers reflect resource constraints, not design ceilings โ the environment is built for trajectories of 300โ500 steps where the long-horizon dynamics are fully expressed. Within these limits, the goal was proof of concept: does the reward signal improve, does the policy stabilize, does the agent develop domain-differentiated strategies across MSME and startup profiles.
The answer to all three is yes.
@@ -157,13 +147,13 @@ The answer to all three is yes. | | | | Mean episode reward across 30 training iterations | Policy loss and KL divergence across training |
Reward climbs through the first 15 episodes driven primarily by the agent unlearning high-penalty defaults โ particularly do_nothing when behavioral signals are deteriorating. KL divergence stays bounded throughout, indicating stable updates without policy collapse.
Baseline vs. Trained Distribution
The untrained baseline defaults to low-commitment actions regardless of signal. After training, the reward distribution shifts toward +0.3 โ +0.8. The negative tail shrinks but persists โ heavily biased loss-level entities remain the hardest case, as expected.
Training Metrics Dashboard
@@ -181,33 +171,24 @@ This view isolates the reward trend with a moving average, making it easier to s
Training & Evaluation Workflow
# Baseline
py -3 scripts/run_baseline_eval.py --episodes 30 --output artifacts/baseline_rewards.json
# Train
py -3 train_grpo.py --episodes 30 --max_steps 90 --output_dir msme_rl_checkpoints
# Judge artifacts
py -3 scripts/generate_judge_artifacts.py \
--training_json msme_rl_checkpoints/reward_curve.json \
--baseline_json artifacts/baseline_rewards.json \
--output_dir artifacts
# Deterministic eval
py -3 scripts/run_deterministic_eval.py --seed 123 --episodes 5 \
--output artifacts/deterministic_eval.json
# Pre-submission check
py -3 scripts/pre_submit_check.py@@ -221,19 +202,19 @@ msmeEnv/ โโโ openenv.yaml โโโ pyproject.toml โโโ _init.py โโโ traingrpo.py โโโ worldgenerator.py โโโ reward.py โโโ network.py โโโ memory.py โโโ messagegenerator.py โโโ server/ โ โโโ app.py โ โโโ msmeEnvenvironment.py โโโ domains/ โ โโโ init.py โ โโโ msmestartup/ โ โโโ adapter.py โโโ scripts/ โโโ runbaselineeval.py โโโ eval.py @@ -244,20 +225,14 @@ msmeEnv/
What Comes Next
The 90-step cap was a resource limitation, not a ceiling. At 300โ500 steps, the long-horizon dynamics become fully visible โ entities that appear healthy at step 20 but deteriorate by step 80, requiring the agent to hold and update its hypothesis across a much longer evidence window. That is where the real test of linguistic decoding lives.
Beyond longer trajectories, the framework extends naturally to other high-stakes, information-asymmetric domains โ legal negotiation, medical disclosure, HR conflict, political communication โ anywhere that what is said and what is meant systematically diverge. The Indian MSME and startup context was the right scope for a hackathon. The architecture is built to go further.
Tags
openenv ยท reinforcement-learning ยท linguistic-decoding ยท long-horizon-planning ยท hidden-state-inference ยท world-modelling ยท grpo ยท credit-risk ยท llm-agent ยท latent-intent ยท india ยท msme ยท startup
