# Technical Document Extraction: Language Model Task Episode Flow
This document describes a technical flow diagram illustrating the lifecycle of a task episode involving a Language Model (LM). The process is iterative, beginning with initial prompts and continuing through multiple turns until specific termination criteria are met.
## 1. Termination Criteria (Header Region)
Located at the top left of the diagram, marked with a red octagonal stop icon, are the conditions under which the process **Terminates**:
1. Action is `submit`, or
2. Cost limit is exceeded, or
3. 2+ Consecutive Format Errors
---
## 2. Initial Input Phase (Left Region)
The process begins at the bottom left with the label **"Task Episode Begins"**. This leads into a stacked block titled **"Initial Messages"**, which contains three components:
* **(1) System**: (Grey background) The base system prompt.
* **(2) Demonstration**: (Light blue background) Examples provided to the model.
* **(3) Instance**: (Purple background) The specific task or problem to be solved.
---
## 3. Core Processing Loop (Main Chart Region)
The diagram follows a linear flow from left to right, which then loops back.
### Turn #1
The **Initial Messages** are fed into the first stage:
* **Component**: Language Model Inference (represented by a brain icon).
* **Output**: The model produces a **"Thought & Action"**.
### Execution
The "Thought & Action" output moves to the next stage:
* **Component**: Execute Action in Env. (represented by a gear icon).
* **Function**: The environment processes the model's requested action.
### Outcome Branches
Following execution, the flow branches into one of three possible states:
1. **Next Step** (Grey box): "Show output of model's action + prompt for next action."
2. **Next Step (No Output)** (Grey box): "Show custom message stating action succeeded quietly."
3. **Format Error** (Light orange box): "Indicate prior action could not be parsed, model must retry."
---
## 4. Iteration Logic (Feedback Loop)
A feedback line labeled **"Turns #2 - #N (Till `submit` action)"** originates from the right side of the outcome boxes.
* **Direction**: The line moves from the right side of the outcome branches, across the top of the diagram, and points back down into the **Language Model Inference** component.
* **Logic**: This indicates that the results of the previous turn (whether a success, a quiet success, or an error) are fed back into the model to generate the next "Thought & Action."
* **Termination Check**: The loop continues until one of the termination criteria (listed in Section 1) is triggered, specifically highlighting the `submit` action in the loop label.
---
## Summary of Components and Flow
| Component | Description |
| :--- | :--- |
| **Inputs** | System, Demonstration, and Instance messages. |
| **Inference** | The Language Model generates a reasoning chain and a specific command. |
| **Environment** | The system where the action is performed. |
| **Feedback** | The environment's response is returned to the model for subsequent turns. |
| **Exit Conditions** | Submission, budget exhaustion, or repeated formatting failures. |