π ARCHITECTURE.md β System Design & Component Architecture
π§ Overview
This document defines the system architecture for the AI Community Moderation Environment.
The system is designed to:
- comply with OpenEnv specification
- support multi-step agent interaction
- provide deterministic evaluation
- be easily deployable via FastAPI + Docker
ποΈ High-Level Architecture
πΉ Updated β Agent layer added
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Agent Layer β
β β
β ββββββββββββββββββββββββ ββββββββββββββββββββββββββββββββ β
β β Gemini 2.5 Flash β β Rule-based Baseline Agent β β
β β (agent/gemini_ β β (baseline/agent.py) β β
β β agent.py) β β β β
β ββββββββββββ¬ββββββββββββ βββββββββββββββ¬βββββββββββββββββ β
β β /reset /step /agent/run β /baseline β
ββββββββββββββββΌβββββββββββββββββββββββββββββββΌββββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β FastAPI API (api/app.py) β
β /reset /step /state /tasks /grader /baseline /agent/run β
ββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββΌβββββββββββββββββββββ
β Environment Core (env/) β
βββββββββ¬ββββββββββββββββββ¬ββββββββββββββββ
β β
βββββββββββΌβββββββ βββββββββΌββββββββ
β State Manager β β Reward Engine β
βββββββββββ¬βββββββ βββββββββββββββββ
β
βββββββββββΌβββββββββββ
β Policy Engine β
βββββββββββ¬βββββββββββ
β
βββββββββββΌβββββββββββ
β Data Generator β
βββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββ
β Grader Engine β
βββββββββββββββββββββββββββββββββββββββ
π¦ Core Modules
1. π§ Environment Core (env/)
Responsibility
Implements OpenEnv interface:
reset()step(action)state()
Key File
env/moderation_env.py
Responsibilities
- orchestrates entire flow
- maintains episode lifecycle
- integrates all sub-components
2. π State Manager (env/state_manager.py)
Responsibility
Handles:
- current state representation
- updates after each action
State Includes
- post content
- user history
- reports
- geo
- context
3. π§Ύ Policy Engine (env/policy_engine.py)
Responsibility
implements rules from
POLICY.mdcomputes:
- violation type
- severity
- expected action
Key Function
def evaluate_policy(state) -> dict:
return {
"violation_type": ...,
"severity": ...,
"expected_action": ...
}
4. 𧬠Data Generator (env/data_generator.py)
Responsibility
- generates synthetic moderation scenarios
- ensures deterministic outputs
Features
- template-based post generation
- context simulation (history, reports, geo)
- seed-controlled reproducibility
5. π Reward Engine (env/reward_engine.py)
Responsibility
- computes step-wise rewards
- aligns with
REWARD.md
Input
- current state
- action
- ground truth
6. π§ͺ Grader Engine (graders/)
Responsibility
- computes final episode score
- aligns with
GRADERS.md
Key File
graders/grader.py
7. π API Layer (api/)
Framework
- FastAPI
Responsibilities
Expose endpoints:
| Endpoint | Function |
|---|---|
/reset |
start new episode |
/step |
take action |
/state |
current state |
/tasks |
list tasks |
/grader |
compute score |
/baseline |
run rule-based baseline agent |
/agent/run |
run Gemini 2.5 Flash agent πΉ |
/health |
liveness check |
8. π€ Baseline Agent (baseline/)
Responsibility
- runs simple rule-based heuristic agent
- produces reproducible benchmark without any LLM dependency
9. π§ Gemini Agent (agent/) β πΉ Added
Responsibility
- LLM-driven agent using Gemini 2.5 Flash (google-genai SDK)
- interacts with the environment via the same
/resetand/stepAPI - uses multi-turn chat with a structured system prompt
- parses JSON action responses; falls back to
escalateon parse failure
Key Files
agent/gemini_agent.py β GeminiAgent class
agent/prompts.py β SYSTEM_PROMPT + build_turn_prompt()
Design Constraint
The LLM is only the decision-making layer. Policy evaluation, reward computation, and grading remain fully deterministic in the environment.
π Data Flow
1. Reset
API β Environment.reset()
β DataGenerator
β StateManager
β Initial State returned
2. Step
Agent Action β API
β Environment.step()
β StateManager update
β PolicyEngine evaluate
β RewardEngine compute
β New State returned
3. Grading
Episode complete β GraderEngine
β Score computed
β Returned via API
π§ Internal Interaction Flow
Action
β
State Update
β
Policy Evaluation
β
Reward Calculation
β
Next State
π§© Component Dependencies
| Component | Depends On |
|---|---|
| Environment | State, Policy, Reward |
| State Manager | Data Generator |
| Reward Engine | Policy Engine |
| Grader | Policy + Trajectory |
| API | Environment |
βοΈ Execution Model
- single-threaded environment (MVP)
- stateless API with session tracking (in-memory)
- reproducible seeds for all scenarios
π³ Deployment Architecture
Docker Container
βββ FastAPI Server
βββ Environment Core
βββ Graders
βββ Baseline Agent
Runs on:
- Hugging Face Spaces
- local Docker
π§ Design Principles
1. Modularity
Each component is isolated and testable
2. Determinism
All outputs reproducible
3. Simplicity
Avoid unnecessary abstraction
4. Spec Compliance
Strict adherence to OpenEnv interface
π§ One-Line Summary
A modular, deterministic system where an environment core orchestrates policy evaluation, reward computation, and grading through well-defined components exposed via a FastAPI interface.