CoolFace
Apppublic

Prit-Sudo/Organizational-Simulation-Environment

sourceHugging Facegpl-3.0updated 5mo agoView on Hugging Face
0likes
App README

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference

AAOS: Autonomous AI Organization Simulator

OpenEnv Hackathon Submission

  • β€”πŸš€ Hugging Face Space: [Insert Space URL here]
  • β€”πŸ“ Blog Post / Writeup: https://huggingface.co/spaces/Prit-Sudo/Organizational-Simulation-Environment/blob/main/BLOG.md
  • β€”πŸ“ Training Logs: https://huggingface.co/spaces/Prit-Sudo/Organizational-Simulation-Environment/blob/main/training_logs.md

1. The Problem: Why It Matters

The Capability Gap: While LLMs excel at conversational tasks, they struggle as autonomous agents in complex, multi-stakeholder organizational environments. Real-world business operations require agents to not only execute tasks but to prioritize resources, coordinate with other specialized roles, and manage compounding risks (like failing infrastructure or policy violations).

The Target Domain: Organizational decision-making is a high-impact engineering task that is severely underexplored in RL/LLM training. Existing benchmarks often rely on static QA or simple games (grid-worlds, chess). AAOS exists to teach LLMs how to navigate the messy reality of a modern tech organizationβ€”balancing immediate sprint goals against long-term system stability and compliance.

2. The Environment: What the Agent Experiences

AAOS is a deterministic, partially observable multi-agent simulation. The model plays the role of 6 specialized agents (Product Manager, Engineer, Data Analyst, Risk/Compliance, Operations, Oversight).

  • β€”What the Agent Sees: A structured JSON observation representing a slice of the global state (e.g., the Engineer sees error rates and compute resources, while Compliance sees risk registries and policies).
  • β€”What the Agent Does: Submits structured JSON actions via a typed API (e.g., delegate_task, approve_resource, raise_risk_flag, resolve_incident, update_policy).
  • β€”What the Agent is Rewarded For: A rigorous, hard-to-game reward signal clamped between 0.0 and 1.0. The reward is a weighted composite of:
  • β€”Business Success (25%): Task completion and deadlines.
  • β€”Collaboration (20%): Cross-agent coordination.
  • β€”Risk Management (20%): Incident resolution and policy compliance.
  • β€”Efficiency (15%): Resource and cost management.
  • β€”Adaptability (20%): Recovering from injected scenario shocks.

Motivation

Real organizational decision-making is a high-impact engineering task, but it is hard to evaluate with unstructured prompts alone. This project provides:

  • β€”deterministic scenarios
  • β€”typed API contracts
  • β€”explicit tasks
  • β€”deterministic graders
  • β€”normalized scores in the range 0.0 to 1.0

That allows fair comparison between different models or agent policies.

3. Final Project Structure

aaos-env/
|-- .env
|-- .dockerignore
|-- .gitignore
|-- Dockerfile
|-- README.md
|-- client.py
|-- inference.py
|-- models.py
|-- openenv.yaml
|-- requirements.txt
|-- test_smoke.py
`-- server/
    |-- __init__.py
    |-- app.py
    |-- environment.py
    |-- tasks.py
    |-- scenarios.py
    |-- oversight.py
    `-- graders/
        |-- __init__.py
        |-- utils.py
        |-- business_grader.py
        |-- collaboration_grader.py
        `-- risk_grader.py

Core Components

server/app.py

FastAPI entrypoint. It exposes:

  • β€”GET /health
  • β€”POST /reset
  • β€”POST /step
  • β€”GET /state

server/environment.py

This is the main environment engine. It:

  • β€”picks a scenario
  • β€”resets state
  • β€”executes multi-agent actions
  • β€”updates reward
  • β€”decides when a task is complete

server/tasks.py

Defines the available tasks:

  • β€”org_simulation
  • β€”crisis_management
  • β€”full_episode

server/scenarios.py

Contains deterministic organizational scenario datasets:

  • β€”product_launch_failure
  • β€”resource_conflict
  • β€”silent_data_drift
  • β€”policy_change_shock

Each scenario includes:

  • β€”tasks with deadlines and effort requirements
  • β€”resource pools (compute, budget, personnel)
  • β€”risks with severity and visibility rules
  • β€”system metrics (latency, error_rate, uptime, cost)
  • β€”deterministic events injected at specific timesteps
  • β€”scenario flags tracking progression

server/graders/

Contains the deterministic scoring functions:

  • β€”business grader (task completion + efficiency)
  • β€”collaboration grader (coordination + adaptability)
  • β€”risk grader (risk management + safety)

server/oversight.py

Safety auditing and penalty system. Audits every action for:

  • β€”approve_resource without prior risk check
  • β€”ignoring critical risks for 3+ steps
  • β€”policy violations (resource threshold)
  • β€”repeat offender escalation (3+ violations)

models.py

Defines typed Pydantic models for:

  • β€”actions (AgentAction)
  • β€”observations (Observation)
  • β€”rewards
  • β€”step/reset requests and responses
  • β€”full environment state

inference.py

This is the baseline inference script used by evaluation. It:

  • β€”calls /reset
  • β€”reads the observation
  • β€”chooses actions for all 6 agents
  • β€”calls /step
  • β€”prints structured logs in [START], [STEP], and [END] format

Tasks

1. org_simulation

Goal:

Run basic multi-agent organizational collaboration β€” propose plans, delegate tasks, coordinate across agents.

Difficulty:

easy

Completion:

Finishes when all tasks are delegated or in-progress/completed.

2. crisis_management

Goal:

Handle crisis scenarios β€” identify risks, resolve incidents, and coordinate crisis response across agents.

Difficulty:

medium

Completion:

Finishes when all detected risks are mitigated and all incidents are resolved.

3. full_episode

Goal:

Complete a full episode β€” collaborate, manage risks, resolve incidents, apply remediation, and adapt to dynamic events.

Difficulty:

hard

Completion:

Finishes when max_steps reached (always runs the full episode).

Observation Space

Each API step returns an Observation object with:

  • β€”task
  • β€”step_count
  • β€”max_steps
  • β€”scenario_id
  • β€”scenario_title
  • β€”agent_observations (per-agent partial observations with role-based visibility)
  • β€”system_metrics
  • β€”resources
  • β€”active_risks
  • β€”active_incidents
  • β€”scenario_events
  • β€”partial_scores
  • β€”hints
  • β€”degraded

This observation is the actual input the agent reasons over.

Partial Observability

Each of the 6 agents sees a DIFFERENT slice of the global state:

AgentSeesDoes Not See
Product ManagerTasks, plans, high-level metricsRisks, budgets
EngineerAssigned tasks, error rates, computeBudget details
Data AnalystData quality metrics, anomaliesResource allocation
Risk/ComplianceRisk registry, audit logs, policiesTask details
OperationsAll metrics, resources, incidentsProduct strategy
OversightAudit logs, violations, all metricsβ€”

Action Space

The environment supports thirteen actions.

propose_plan Payload:

json
{"plan": "Sprint plan for step 0: prioritize critical tasks"}

accept_plan Payload:

json
{"plan_id": "plan_0_product_manager"}

reject_plan Payload:

json
{"plan_id": "plan_0_product_manager"}

delegate_task Payload:

json
{"task_id": "task_frontend", "to": "engineer"}

request_resource Payload:

json
{"amount": 15, "resource_type": "compute"}

approve_resource Payload:

json
{"amount": 15, "resource_type": "compute"}

query_metrics Payload:

json
{}

raise_risk_flag Payload:

json
{"risk_id": "risk_scaling", "description": "scaling_bottleneck"}

report_anomaly Payload:

json
{"description": "Data quality dropped to 0.65", "severity": "high"}

resolve_incident Payload:

json
{"incident_id": "incident_step8"}

audit_agent Payload:

json
{"target_agent": "engineer"}

update_policy Payload:

json
{"policy": "Safety review required at step 7"}

no_op Payload:

json
{}

Reward Logic

The reward is deterministic and clamped to 0.0 to 1.0.

Formula:

total =
  0.25 * business_success  +
  0.20 * collaboration     +
  0.20 * risk_management   +
  0.15 * efficiency        +
  0.20 * adaptability

Reward parts:

  • β€”business_success: task completion quality and deadline adherence
  • β€”collaboration: inter-agent coordination and communication
  • β€”risk_management: risk detection, incident resolution, policy compliance
  • β€”efficiency: resource utilization, cost management, latency performance
  • β€”adaptability: response to scenario events, recovery, policy adaptation

Reward delivery:

  • β€”60% immediate (returned on the step)
  • β€”40% delayed (released every 5 steps + episode end)
  • β€”Oversight penalties push reward toward 0 (never negative)

OpenEnv Metadata

The root openenv.yaml contains:

  • β€”environment name and version
  • β€”app entrypoint
  • β€”HTTP runtime type
  • β€”task metadata with difficulty

Current task metadata:

  • β€”org_simulation
  • β€”crisis_management
  • β€”full_episode

Actual Input to the System

The system input is not a single plain English prompt. The real input is the structured observation returned by /reset or /step.

Example observation:

json
{
  "task": "full_episode",
  "step_count": 0,
  "max_steps": 50,
  "scenario_id": "product_launch_failure",
  "scenario_title": "Aggressive deadline with hidden scaling issues",
  "agent_observations": {
    "product_manager": {
      "role": "product_manager",
      "step": 0,
      "visible_tasks": [
        {"id": "task_frontend", "name": "frontend_polish", "status": "pending", "priority": "high", "deadline_step": 10, "quality": 0.0, "effort_remaining": 4}
      ],
      "system_metrics": {"latency": 200, "uptime": 0.999},
      "resources": "hidden",
      "risks": "hidden"
    },
    "engineer": {
      "role": "engineer",
      "step": 0,
      "visible_tasks": [
        {"id": "task_backend", "name": "backend_scaling", "status": "pending", "priority": "critical"}
      ],
      "system_metrics": {"latency": 200, "error_rate": 0.02},
      "resources": {"compute": 80},
      "risks": []
    }
  },
  "system_metrics": {"latency": 200, "error_rate": 0.02, "uptime": 0.999, "cost": 0.0},
  "resources": {"compute": 80, "budget": 50, "personnel": 5},
  "active_risks": [],
  "active_incidents": [],
  "scenario_events": [],
  "partial_scores": {
    "business": 0.0,
    "collaboration": 0.0,
    "risk": 0.0,
    "efficiency": 1.0,
    "adaptability": 0.0
  },
  "hints": ["Complete all objectives: collaborate, manage risks, resolve incidents, and adapt to events."],
  "degraded": false
}

Actual Output from the System

The system output is a sequence of actions and scores.

Example actions (multi-agent, one per agent per step):

json
{
  "product_manager": {"action_type": "propose_plan", "payload": {"plan": "Sprint plan for step 0: prioritize critical tasks"}},
  "engineer": {"action_type": "delegate_task", "payload": {"task_id": "task_backend", "to": "operations"}},
  "data_analyst": {"action_type": "query_metrics", "payload": {}},
  "risk_compliance": {"action_type": "query_metrics", "payload": {}},
  "operations": {"action_type": "approve_resource", "payload": {"amount": 15, "resource_type": "compute"}},
  "oversight": {"action_type": "audit_agent", "payload": {"target_agent": "engineer"}}
}

Final terminal output format:

[START] task=full_episode env=aaos-env model=Qwen/Qwen2.5-72B-Instruct backend=https://router.huggingface.co/v1 seed=42
[STEP] step=1 action={"action_type": "propose_plan", "payload": {"plan": "Sprint plan..."}} reward=0.3210 done=False error=None
...
[END] success=True steps=25 score=0.7281 rewards=[...]

This format is important because the evaluation pipeline expects strict [START], [STEP], and [END] lines.

Baseline Behavior

The baseline inference script runs all 3 tasks sequentially:

  1. 1.org_simulation
  2. 2.crisis_management
  3. 3.full_episode

4. Results: Untrained Baseline vs. Trained Agent

We evaluated the performance of an untrained heuristic/zero-shot baseline against our agent trained using a two-stage pipeline: Supervised Fine-Tuning (SFT) via Unsloth, followed by Group Relative Policy Optimization (GRPO) using trl.

Quantitative Comparison

Task DifficultyUntrained Baseline ScoreGRPO Trained Agent ScoreImprovement
Org Simulation (Easy)~0.25~0.85+240%
Crisis Management (Medium)~0.50~0.92+84%
Full Episode (Hard)~0.70~0.95+35%

Training Evidence

The plots below demonstrate the end-to-end learning process connecting the environment to the training loop.

Loss Curves (SFT + GRPO)

[image] Figure 1: SFT loss drops significantly in the first epoch. GRPO RL training maintains a stable, low loss (~0.01-0.04) while exploring policy improvements.

Reward Curves (GRPO Phase)

[image] Figure 2: Total reward (top) climbs from an initial 1.73 to converge at ~4.00 (out of 5.0 max). The per-component breakdown (bottom) shows the agent rapidly mastering formatting, action validity, and safety, while environment-specific strategic rewards (Env Score) represent the hardest capability gap.

Qualitative Improvements

After training, the agent stopped proposing empty or cyclical plans. Instead of merely reacting to incidents, the trained agent proactively queried metrics, raised risk flags before systems failed, and correctly routed compute approvals to the Operations role.

5. Training Pipeline

The project includes an end-to-end training pipeline combining Supervised Fine-Tuning (SFT) and Reinforcement Learning via GRPO.

1. Dataset Collection

Run the environment with a strong teacher model to collect raw execution episodes:

bash
python collect_training_data.py --episodes 4 --steps 10 --model-id Qwen/Qwen2.5-7B-Instruct --token <YOUR_HF_TOKEN>

Outputs to: `training_data/raw_episodes.jsonl`

2. SFT Dataset Preparation

Format and filter the raw episodes, keeping only high-reward actions to train the SFT baseline:

bash
python prepare_sft_dataset.py

Outputs to: `training_data/sft_dataset.jsonl`

3. Supervised Fine-Tuning (SFT)

Train the initial policy using Unsloth for fast, memory-efficient LoRA tuning:

bash
python -m train_unsloth_sft \
   --dataset training_data/sft_dataset.jsonl \
   --output fine_tuned_model \
   --epochs 1 \
   --batch-size 1 \
   --grad-accum 8 \
   --max-seq-len 1024 \
   --lora-rank 8

Outputs to: `fine_tuned_model/`

4. Reinforcement Learning (GRPO)

Optimize the SFT model further using Group Relative Policy Optimization (GRPO) to align with environment rewards:

bash
python -m train_grpo_rl \
    --base-model fine_tuned_model \
    --epochs 1 \
    --batch-size 1 \
    --num-generations 2 \
    --max-prompts 150

Outputs to: `aaos_grpo_model/`

You can find more detailed logs and intermediate steps from the reference training run in post_training.md.

6. Setup and Run

From the repository root:

bash
python -m venv .venv
.venv\Scripts\Activate.ps1
pip install -r requirements.txt

Start the server:

bash
uvicorn server.app:app --host 0.0.0.0 --port 7860

Run inference:

bash
python inference.py

Run tests:

bash
python -m unittest test_smoke -v

7. Required Environment Variables

The project supports:

  • β€”API_BASE_URL
  • β€”MODEL_NAME
  • β€”HF_TOKEN
  • β€”ENV_BASE_URL
  • β€”RUN_SEED
  • β€”MAX_STEPS
  • β€”SUCCESS_THRESHOLD

Validation Status

The project is structured for OpenEnv-style evaluation and includes:

  • β€”typed models
  • β€”root inference.py
  • β€”root openenv.yaml
  • β€”root Dockerfile
  • β€”3 tasks
  • β€”graders
  • β€”deterministic scoring
  • β€”structured logs

This makes the project ready for final validation and submission.