# mdkamranalam/global-syndicate-taskforce architecture

> Architecture diagram of the GitHub repository mdkamranalam/global-syndicate-taskforce, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mdkamranalam/global-syndicate-taskforce
- Repository: https://github.com/mdkamranalam/global-syndicate-taskforce

## Overview

#### Purpose and Entry Points
Global Syndicate Taskforce is a partially observable OpenEnv simulator for training and evaluating financial-compliance agents with verifiable, step-based rewards. The primary service entry point is the FastAPI/OpenEnv server at `server/app.py`; its environment implementation is `server/global_syndicate_taskforce_env_environment.py`. Consumers use the client wrapper in `client.py`, while local training runs through `train_grpo_unsloth.py` or `train_grpo_mac.py`.

#### API and Environment Boundary
The server exposes the reset/step lifecycle expected by OpenEnv. Requests carry typed auditor actions; responses return an observation, reward, and terminal status. Shared action/observation schemas are defined in `models.py`, separating the public protocol from environment-state implementation in `server/global_syndicate_taskforce_env_environment.py`. The root `app.py` is likely a deployment-facing application entry point, while `server/app.py` is the explicit Uvicorn target.

#### Episode State Machine and Blackboard
`server/global_syndicate_taskforce_env_environment.py` owns episode initialization, hidden scenario selection, step count, transaction metadata, verified facts, alerts, reward accumulation, and completion state. Each reset creates a case whose hidden truth is not directly exposed. The observation acts as the centralized case-file/blackboard: agents can see accumulated verified facts but must acquire them through allowed transitions.

#### Gatekeeper Stages
The environment routes actions among three deterministic roles:
- Triage via the unreliable Tier 1 Analyst, which may emit probabilistic false reports.
- Verification via the Bank Liaison, which releases hidden ground truth only with the matching policy mandate.
- Termination via the Legal Officer, which evaluates the submitted evidence chain against the hidden truth.
These role-specific state transitions and reward effects belong in `server/global_syndicate_taskforce_env_environment.py`; task-level scenario/action orchestration may be split into `server/tasks.py`.

#### Reward and Safety Control Flow
Every nonterminal interaction incurs an efficiency penalty. A successful liaison mandate adds a verification bonus; a correct legal ruling yields terminal success; unsupported or hallucinated rulings trigger severe terminal failure. A step limit forces timeout termination. This reward engine makes verified facts—not analyst output—the important trust boundary, preventing agents from receiving success merely by guessing a plausible fraud label.

#### Client, Training, and Runtime Integration
`client.py` provides the remote environment interface used by inference and training code. `train_grpo_unsloth.py` integrates the environment with Unsloth and Hugging Face TRL GRPO for GPU-efficient RL training; `train_grpo_mac.py` is an alternate training path. The project targets Python, runs the API under Uvicorn/FastAPI, and packages deployment in Docker through `server/Dockerfile`. `openenv.yaml` defines OpenEnv-facing project metadata, and the deployed external target is a Hugging Face Space.

#### Deployment Topology
The agent/trainer and environment server are intentionally separable processes: training or inference sends standardized actions over HTTP, while the server retains authoritative hidden scenario data and applies mutations/rewards. This prevents the model-side runtime from directly accessing ground truth. Container dependencies are scoped under `server/requirements.txt`, with the server exposed on port 8000.

Main entry points: [`server/global_syndicate_taskforce_env_environment.py`](https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/server/global_syndicate_taskforce_env_environment.py) (Environment state machine), [`server/app.py`](https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/server/app.py) (OpenEnv API), [`client.py`](https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/client.py) (Remote client), [`server/Dockerfile`](https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/server/Dockerfile) (Server container)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_agent["Agent &amp; Training"]
  node_client["Remote client<br/>OpenEnv client<br/>[client.py]"]
  node_grpo_unsloth["GPU GRPO training<br/>training runner"]
  node_grpo_mac["Mac training<br/>training runner<br/>[train_grpo_mac.py]"]
  node_openenv_metadata["OpenEnv metadata<br/>project manifest<br/>[openenv.yaml]"]
end

subgraph group_api["Environment Server"]
  node_server_app["OpenEnv API<br/>FastAPI / Uvicorn<br/>[app.py]"]
  node_protocol["Action &amp; observation schema<br/>public protocol<br/>[models.py]"]
  node_root_app["Deployment app<br/>application entry<br/>[app.py]"]
end

subgraph group_episode["Episode Authority"]
  node_environment["Environment state machine<br/>OpenEnv environment"]
  node_tasks["Scenario orchestration<br/>task module<br/>[tasks.py]"]
  node_case_state[("Hidden case state<br/>episode state")]
  node_case_file["Case-file observation<br/>agent-visible blackboard"]
  node_gatekeepers["Triage, liaison &amp; legal<br/>deterministic role stages"]
  node_reward_engine["Reward &amp; safety engine<br/>reward control"]
end

subgraph group_deploy["Deployment"]
  node_docker["Server container<br/>Docker image"]
  node_requirements["Server dependencies<br/>Python requirements<br/>[requirements.txt]"]
  node_hf_space{{"Hugging Face Space<br/>external deployment"}}
end

node_grpo_unsloth -->|"uses"| node_client
node_grpo_mac -->|"uses"| node_client
node_openenv_metadata -.->|"declares project interface"| node_server_app
node_client -->|"HTTP reset / step actions"| node_server_app
node_server_app -->|"validates protocol"| node_protocol
node_server_app -->|"dispatches lifecycle"| node_environment
node_root_app -.->|"deployment-facing route"| node_server_app
node_environment -.->|"selects scenarios / actions"| node_tasks
node_environment -->|"initializes and mutates"| node_case_state
node_environment -->|"routes auditor actions"| node_gatekeepers
node_gatekeepers -->|"reads hidden truth and mandates"| node_case_state
node_gatekeepers -->|"releases verified facts"| node_case_file
node_environment -->|"returns observation"| node_case_file
node_environment -->|"evaluates each transition"| node_reward_engine
node_reward_engine -->|"updates reward and terminal state"| node_case_state
node_environment -->|"produces observation, reward, done"| node_protocol
node_server_app -->|"packaged by"| node_docker
node_requirements -->|"installed in"| node_docker
node_docker -->|"deployed as API service"| node_hf_space

click node_client "https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/client.py"
click node_grpo_unsloth "https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/train_grpo_unsloth.py"
click node_grpo_mac "https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/train_grpo_mac.py"
click node_openenv_metadata "https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/openenv.yaml"
click node_server_app "https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/server/app.py"
click node_protocol "https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/models.py"
click node_root_app "https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/app.py"
click node_environment "https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/server/global_syndicate_taskforce_env_environment.py"
click node_tasks "https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/server/tasks.py"
click node_gatekeepers "https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/server/global_syndicate_taskforce_env_environment.py"
click node_reward_engine "https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/server/global_syndicate_taskforce_env_environment.py"
click node_docker "https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/server/Dockerfile"
click node_requirements "https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/server/requirements.txt"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client,node_grpo_unsloth,node_grpo_mac,node_openenv_metadata toneBlue
class node_server_app,node_protocol,node_root_app toneAmber
class node_environment,node_tasks,node_case_state,node_case_file,node_gatekeepers,node_reward_engine toneMint
class node_docker,node_requirements,node_hf_space toneRose
```

## Components

### Agent & Training

- [Remote client](https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/client.py): OpenEnv client · Sends standardized lifecycle actions to the server. · `client.py`
- [GPU GRPO training](https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/train_grpo_unsloth.py): training runner · Unsloth and TRL GRPO training path. · `train_grpo_unsloth.py`
- [Mac training](https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/train_grpo_mac.py): training runner · Alternate local training path. · `train_grpo_mac.py`
- [OpenEnv metadata](https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/openenv.yaml): project manifest · `openenv.yaml`

### Environment Server

- [OpenEnv API](https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/server/app.py): FastAPI / Uvicorn · Explicit server entry point exposing reset and step. · `server/app.py`
- [Action & observation schema](https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/models.py): public protocol · Typed boundary shared by clients and environment responses. · `models.py`
- [Deployment app](https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/app.py): application entry · Likely deployment-facing application entry point. · `app.py`

### Episode Authority

Server-owned state keeps hidden truth outside the agent runtime.

- [Environment state machine](https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/server/global_syndicate_taskforce_env_environment.py): OpenEnv environment · Authoritative episode lifecycle, mutations, and role transitions. · `server/global_syndicate_taskforce_env_environment.py`
- [Scenario orchestration](https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/server/tasks.py): task module · May hold scenario and action orchestration. · `server/tasks.py`
- **Hidden case state**: episode state · Scenario truth, transaction metadata, alerts, steps, and completion state.
- **Case-file observation**: agent-visible blackboard · Accumulates only facts acquired through permitted transitions.
- [Triage, liaison & legal](https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/server/global_syndicate_taskforce_env_environment.py): deterministic role stages · Triage may be unreliable; liaison verifies mandates; legal evaluates evidence. · `server/global_syndicate_taskforce_env_environment.py`
- [Reward & safety engine](https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/server/global_syndicate_taskforce_env_environment.py): reward control · Penalizes steps, rewards verified mandates, and terminates success, failure, or timeout. · `server/global_syndicate_taskforce_env_environment.py`

### Deployment

- [Server container](https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/server/Dockerfile): Docker image · Packages the API service exposed on port 8000. · `server/Dockerfile`
- [Server dependencies](https://github.com/mdkamranalam/global-syndicate-taskforce/blob/main/server/requirements.txt): Python requirements · `server/requirements.txt`
- **Hugging Face Space**: external deployment · Deployed external server target.

## Connections

- GPU GRPO training → Remote client: uses
- Mac training → Remote client: uses
- OpenEnv metadata → OpenEnv API: declares project interface
- Remote client → OpenEnv API: HTTP reset / step actions
- OpenEnv API → Action & observation schema: validates protocol
- OpenEnv API → Environment state machine: dispatches lifecycle
- Deployment app → OpenEnv API: deployment-facing route
- Environment state machine → Scenario orchestration: selects scenarios / actions
- Environment state machine → Hidden case state: initializes and mutates
- Environment state machine → Triage, liaison & legal: routes auditor actions
- Triage, liaison & legal → Hidden case state: reads hidden truth and mandates
- Triage, liaison & legal → Case-file observation: releases verified facts
- Environment state machine → Case-file observation: returns observation
- Environment state machine → Reward & safety engine: evaluates each transition
- Reward & safety engine → Hidden case state: updates reward and terminal state
- Environment state machine → Action & observation schema: produces observation, reward, done
- OpenEnv API → Server container: packaged by
- Server dependencies → Server container: installed in
- Server container → Hugging Face Space: deployed as API service
