Recipe catalog / game-phase
Classify game phase
game-phase is a Jev recipe from the jev-recipes TypeScript package. Which phase of the game does state describe: opening, midgame, endgame, or game over? Use it when an agent adapts its strategy, prompts, or time budget by game phase and you have a textual state description rather than a structured engine.
Last updated .
Explore this recipe interactively · Source and implementation guide · Markdown version
How do I 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);
What input does game-phase take?
| 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
}
}What does a game-phase result look like?
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
}
}
Input
See shared options and behavior for client configuration, validation, and errors. Types are inferred from this folder's Zod 4 schemas. rules is optional and is omitted from the request when absent.
Result
verdict is one of opening, midgame, endgame, terminal, unclear. unclear means the supplied facts do not establish a decision and always requires review.
A result is ready when confidence meets minConfidence and the verdict is not unclear. Inspect the verdict as well as the status: a ready result can name an outcome your application treats as negative. probabilities covers every verdict.
Reuse and calls
Uses the shared choice helper for the Jev call and response parsing. This folder owns its question, verdict criteria, and review policy. A live invocation makes one logical Jev request.
Limits
The verdict is read from the state description and any rules text supplied; the recipe does not simulate moves or evaluate positions. It cannot confirm a checkmate, elimination, or final score that the description does not state, so compute terminal conditions in game code. Phase boundaries vary by game and by convention, and the probabilities show when two phases are both plausible.
Example input
demo.json contains editable input and a hand-authored response. After installing jev-recipes, npx jev-recipes demo game-phase shows an offline illustration, not an accuracy measurement. Use npx jev-recipes describe game-phase to inspect the input and result schemas.
How accurate is game-phase?
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.
What are the limits of game-phase?
- 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.
Which recipes are related to game-phase?
- 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.