Mission Control
Autonomous Agents: From FSMs to Hierarchical Trees.
Project Synopsis
Behavior-Bot is an exploration into hierarchical AI architectures. While Project 01 focused on the "Nervous System" (Sockets), Project 02 focuses on the "Cortex" (Decision Making).
The goal is to build a robust Behavior Tree framework from scratch in C#, contrasting it against a traditional Finite State Machine (FSM), and utilizing Python to analyze the efficiency of decision paths.
Why This Matters
FSMs become spaghetti code as complexity grows (O(N2) transitions). Behavior Trees offer modularity and scalability, the industry standard for AA/AAA NPC logic.
Tech Stack
Project Checkpoints
- Phase 1: The Finite State Machine (Basics)
- Phase 2: The Behavior Tree (Architecture)
- Phase 3: The Hybrid Brain (Analysis)
- Phase 4: Creative Polish (Visuals)
Field Notes & Learnings
Key engineering concepts for Autonomous Agents.
1. The Scalability Problem (FSM vs BT)
Concept: In an FSM, every state must know about every potential transition. Adding one state (e.g., "Reload") might require updating "Idle", "Attack", and "Run".
Solution: Behavior Trees decouple logic. A "Reload" Sequence is a self-contained branch that can be plugged anywhere without breaking the rest of the tree.
2. The "Running" State
Concept: Actions in games take time (e.g., "Walk to Door"). Code cannot block execution.
Solution: BT Nodes return three states: SUCCESS, FAILURE, or RUNNING. If RUNNING, the tree pauses that branch and resumes next frame, enabling multi-frame actions without coroutine hell.
3. Heuristic Offloading
Concept: Optimizing AI is hard when you can't see why it made a choice.
Solution: We stream the Decision Path (List of active nodes) to Python via Sockets. Python analyzes time-in-node and efficiency, acting as a real-time debugger for the AI's "thought process".
4. Composite Nodes
The building blocks of logic:
- SELECTOR (?): The "OR" gate. Tries children until one succeeds. (e.g., Fight OR Run).
- SEQUENCE (→): The "AND" gate. Runs children in order; fails if any fail. (e.g., Open Door -> Walk In).
Implementation
Step-by-step Execution Plan.
Phase 1: The FSM (Week 1)
- State Logic: Define `IDLE`, `PATROL`, `CHASE`.
- Transitions: Script conditions (e.g., PlayerInSight).
- Debug: Draw Vision Cone with `Debug.DrawLine`.
Phase 2: The Behavior Tree (Week 2)
- Architecture: Base classes for `Composite`, `Decorator`, `Leaf`.
- Logic Nodes: Implement `Selector` and `Sequence`.
- Tasks: Create leafs `MoveToTarget`, `Wait`, `IsTargetInRange`.
Phase 3: The Hybrid Brain (Week 3)
- Data Export: Stream "Decision Path" via Sockets to Python.
- Analysis: Python script to measure "Time to reach goal".
- Tuning: Send dynamic parameter weights back to Unity.
Phase 4: Creative Polish (Week 4)
- Visuals: Blender "Bot" with state-color indicator.
- DevLog: Side-by-side video (FSM vs BT) in DaVinci Resolve.
Dev Logs
Engineering notes & daily updates.
Entry 000 Planning
Date: Feb 3, 2026
Project 02 queued for March. Goal is to implement a custom Behavior Tree system to replace the rigid FSM from early prototypes.