Recipe catalog / game-phase
Classify game phase
Which phase of the game does state describe: opening, midgame, endgame, or game over?
An agent adapts its strategy, prompts, or time budget by game phase and you have a textual state description rather than a structured engine.
Explore this recipe interactively ยท Source and implementation guide
Use game-phase in TypeScript
Install with npm install jev-recipes. Requires Node.js 22.9 or newer and ES modules. Set TYPESAFE_API_KEY in your server environment for live calls, which send input to TypeSafe and use API quota. See the installation guide.
import { gamePhase } from 'jev-recipes/game-phase';
const result = await gamePhase({
"state": "Chess. White: king g1, rook d1, pawns a2, f2, g2. Black: king g8, rook e8, pawns a7, h6. Move 52, White to move. No queens or minor pieces remain. Neither side is in check.",
"rules": "Standard chess. The game ends by checkmate, stalemate, agreed draw, resignation, or the fifty-move and threefold repetition rules.",
"minConfidence": 0.8
});
console.log(result);
Input contract
| Field | Type | Needed |
|---|---|---|
| state | string | Required |
| rules | string | Optional |
| minConfidence | number | Optional |
Full input and result schemas
{
"input": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"state": {
"type": "string"
},
"rules": {
"type": "string"
},
"minConfidence": {
"type": "number",
"minimum": 0,
"maximum": 1
}
},
"required": [
"state"
]
},
"result": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"model": {
"type": "string"
},
"usage": {
"type": "object",
"properties": {
"input_tokens": {
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
},
"output_tokens": {
"type": "integer",
"minimum": 0,
"maximum": 9007199254740991
}
},
"required": [
"input_tokens",
"output_tokens"
],
"additionalProperties": false
},
"status": {
"type": "string",
"enum": [
"ready",
"review"
]
},
"verdict": {
"type": "string",
"enum": [
"opening",
"midgame",
"endgame",
"terminal",
"unclear"
]
},
"confidence": {
"type": "number",
"minimum": 0,
"maximum": 1
},
"probabilities": {
"type": "object",
"propertyNames": {
"type": "string",
"enum": [
"opening",
"midgame",
"endgame",
"terminal",
"unclear"
]
},
"additionalProperties": {
"type": "number",
"minimum": 0,
"maximum": 1
},
"required": [
"opening",
"midgame",
"endgame",
"terminal",
"unclear"
]
}
},
"required": [
"model",
"usage",
"status",
"verdict",
"confidence",
"probabilities"
],
"additionalProperties": false
}
}Saved example result
This hand-authored response demonstrates the contract. It is not a model accuracy measurement. Run it without an API key: npx jev-recipes demo game-phase.
{
"model": "demo-fixture",
"usage": {
"input_tokens": 0,
"output_tokens": 0
},
"status": "ready",
"verdict": "endgame",
"confidence": 0.85,
"probabilities": {
"opening": 0.01,
"midgame": 0.09,
"endgame": 0.85,
"terminal": 0.02,
"unclear": 0.03
}
}
Evaluation evidence
No verified live accuracy measurement is available. Evaluate representative cases before using this decision in your workflow.
Use the evaluation guide to measure this decision on your own labeled cases.
Limitations
- Classifies from the textual state description; it does not simulate the game. Compute exact win, loss, and draw conditions in code.
- Phase boundaries are fuzzy in many games. Use the probabilities when opening and midgame or midgame and endgame are both plausible.
Related recipes
- game-action: Use game-action to choose a move from JSON game state and available actions.
- step-progress: Use step-progress to judge how far a non-game task has advanced.