How caleb-andersen/hackerrank-orchestrate-august26 works
Purpose and Entry Points
This is a Python-based WhatsApp message-notification router. It classifies each incoming message as notify, digest, or mute, assigns a message type, rationale, confidence, and historical evidence IDs. Production starts at code/main.py; local scoring starts at code/evaluation/main.py. Input is CSV data and local image/audio media under dataset/; output is the required dataset/output.csv.
Orchestration Pipeline
code/main.py coordinates the end-to-end batch run: load source rows, construct per-message context, obtain a decision, apply safety/validation controls, and write order-preserving predictions. Tunables are centralized in code/config.py, allowing routing behavior and provider settings to be changed without redesigning the pipeline.
Data Model and Context Dossier
code/data/loader.py reads the message stream and supporting user, group, business, historical-message, interaction, and media CSVs. code/data/schema.py defines frozen row schemas at this boundary. The context layer builds a structured dossier for each incoming message:
• code/context/index.py indexes cross-table relationships and history.
• code/context/features.py derives behavioral and notification-relevance signals.
• code/context/retrieval.py selects relevant historical messages as evidence.
This isolates raw dataset shape from decision logic.
Multimodal Interpretation
Text, images, and voice notes are normalized before reasoning. code/context/text.py handles textual content, while code/context/media.py resolves media references and extracts/represents image and audio content. code/context/scanners.py and code/context/timewindow.py contribute content and recency/time-window signals. Media files are local artifacts referenced through dataset/images.csv and dataset/voice_notes.csv.
Agentic Decision Layer
The routing decision can be generated through a tool-using model loop:
• code/agent/loop.py controls provider interaction and tool calls.
• code/agent/prompts.py defines the decision prompt and contextual instructions.
• code/agent/tools.py exposes constrained dossier/retrieval capabilities.
• code/agent/client.py encapsulates the external model-provider API boundary.
code/probe_providers.py supports provider connectivity/capability probing. Secrets are expected from environment variables, not source control.
Guarded Decision and Repair
Model output is not written directly. code/guards/injection.py detects prompt-injection risk in untrusted message/media content. code/guards/safety_gate.py and code/guards/decision.py impose deterministic safety and policy constraints over proposed actions. code/guards/validate.py checks required fields and allowed values; code/guards/reason_repair.py repairs unsuitable explanations. This boundary protects output correctness and prevents untrusted content from controlling the agent.
Output, Recovery, and Evaluation
code/output/writer.py emits the submission schema in the dataset’s required/shuffled key order, while code/output/checkpoint.py supports resumable batch processing. Evaluation remains separate from production routing: code/evaluation/main.py runs labeled-sample scoring, output validation, and full-set consistency checks; code/evaluation/judge.py is the model-backed reason-quality assessment. Gold-label access is confined to the evaluation package rather than the production path.
Main entry points: loop.py Tool-Using Decision Loop · main.py Batch Router · loader.py Dataset Loader · index.py Relationship Index
Components 21
Production Pipeline
- Batch Router · Coordinates order-preserving production routing.
code/main.py - Routing Config
code/config.py - Source CSVs & Media · Messages, relationship data, and local image/audio artifacts.
- Batch Checkpoints · Supports resumable processing.
code/output/checkpoint.py - Submission Writer · Writes required schema in shuffled dataset key order.
code/output/writer.py - Output CSV
dataset/output.csv
Context Dossier
- Dataset Loader
code/data/loader.py - Frozen Row Schemas
code/data/schema.py - Relationship Index · Links messages, entities, interactions, and history.
code/context/index.py - Behavioral Features
code/context/features.py - History Retrieval
code/context/retrieval.py - Content Normalization · Normalizes text and resolves image and voice-note content.
code/context/media.py
Decision Agent
- Tool-Using Decision Loop · Produces a proposed route, type, rationale, confidence, and evidence IDs.
code/agent/loop.py - Decision Prompts
code/agent/prompts.py - Dossier Tools · Exposes dossier and retrieval capabilities to the model.
code/agent/tools.py - Model Provider Client · Uses provider credentials from environment variables.
code/agent/client.py
Guarded Decision
- Injection Detection · Treats message and media content as untrusted.
code/guards/injection.py - Safety & Policy Gate
code/guards/safety_gate.py - Decision Validation & Repair · Enforces allowed fields and repairs unsuitable explanations.
code/guards/validate.py
Evaluation
- Evaluation Runner · Runs labeled scoring, output validation, and consistency checks outside production.
code/evaluation/main.py - Reason Quality Judge
code/evaluation/judge.py
Connections 24
- Batch Router → Routing Config: loads tunables
- Batch Router → Dataset Loader: loads batch
- Source CSVs & Media → Dataset Loader: CSV rows
- Frozen Row Schemas → Dataset Loader: parses into
- Dataset Loader → Relationship Index: source records
- Relationship Index → Behavioral Features: linked context
- Relationship Index → History Retrieval: history
- Source CSVs & Media → Content Normalization: media references
- Batch Router → Content Normalization: message content
- Behavioral Features → Tool-Using Decision Loop: dossier signals
- History Retrieval → Tool-Using Decision Loop: evidence
- Content Normalization → Tool-Using Decision Loop: normalized content
- Decision Prompts → Tool-Using Decision Loop: instructions
- Dossier Tools → Tool-Using Decision Loop: tool calls
- Model Provider Client → Tool-Using Decision Loop: model responses
- Batch Router → Injection Detection: untrusted content
- Tool-Using Decision Loop → Safety & Policy Gate: proposed decision
- Injection Detection → Safety & Policy Gate: risk signal
- Safety & Policy Gate → Decision Validation & Repair: constrained decision
- Decision Validation & Repair → Submission Writer: validated prediction
- Batch Router → Batch Checkpoints: progress
- Submission Writer → Output CSV: writes
- Evaluation Runner → Output CSV: checks output
- Reason Quality Judge → Evaluation Runner: assesses rationales