This prompt is designed for agent runtimes that must decide what to do next when multiple actions are possible. It takes a structured representation of the agent's current state, including completed tasks, in-progress work, pending subtasks, available tools, and known constraints, and returns a ranked list of candidate next actions with rationale, expected state changes, and risk flags. Use this prompt when your agent reaches a decision point and needs to select among competing actions rather than following a static execution plan. The ideal user is an agent developer or platform engineer building an autonomous or semi-autonomous agent loop where the next step is not predetermined by a script or DAG.
Prompt
State-Based Next Action Recommendation Prompt

When to Use This Prompt
Understand the exact job this prompt performs, the conditions it requires, and the situations where it will fail or mislead your agent.
This is not a planning prompt for generating new subtasks from scratch. It assumes a set of candidate actions already exists and the job is prioritization and selection. The prompt works best when the state representation is machine-generated and structured, not free-text narrative. Provide the state as a JSON object with explicit fields for completed, in-progress, and pending items, each carrying status, timestamps, and blocker flags. The prompt expects tool definitions with clear contracts so it can reason about preconditions and side effects. If your agent lacks a reliable state snapshot or the candidate actions are vague, this prompt will produce plausible-sounding but incorrect rankings.
Do not use this prompt for generating new task decompositions, for open-ended brainstorming, or when the agent has only one available action. It is also unsuitable when the state representation is a long, unstructured chat history—the model will struggle to extract the structured signals needed for reliable prioritization. For high-risk domains such as healthcare, finance, or legal workflows, always route the ranked output through a human approval step before execution. The prompt includes risk flags for each candidate action, which your harness should use to gate autonomous execution.
Before deploying, test the prompt against a golden dataset of state snapshots paired with ground-truth priority rankings. Common failure modes include over-prioritizing recently mentioned tasks, ignoring blocker dependencies, and failing to account for tool availability constraints. The implementation harness section covers validation, retry logic, and human-in-the-loop integration. If your agent frequently produces incorrect rankings, revisit the quality and structure of your state representation before tuning the prompt itself.
Use Case Fit
Where the State-Based Next Action Recommendation Prompt delivers value and where it introduces risk. Use these cards to decide if this prompt fits your agent architecture before integrating it into a planning or execution loop.
Good Fit: Structured Task Queues
Use when: the agent maintains a known set of pending subtasks with clear dependencies and statuses. The prompt excels at ranking actions when the state is machine-readable and the action space is bounded. Guardrail: validate that the recommended action exists in the current task list before execution.
Bad Fit: Open-Ended Exploration
Avoid when: the agent is exploring an unknown environment with no predefined task list or when goals are ambiguous. The prompt will fabricate plausible-sounding actions that may be irrelevant or unsafe. Guardrail: require a confirmed goal and task decomposition before invoking this prompt.
Required Input: Complete State Snapshot
Risk: missing or stale state fields cause the prompt to recommend actions based on incorrect assumptions about what has been completed. Guardrail: run a state integrity validation prompt before this one. Reject recommendations if the input state fails completeness checks.
Operational Risk: Action-Only Output Without Execution Guard
Risk: the prompt recommends an action but does not check whether the agent has the required tool, permission, or authority to execute it. Guardrail: always pass the recommended action through a precondition validation step before execution. Never directly execute the raw output.
Operational Risk: Priority Drift Over Long Sessions
Risk: as the agent accumulates state, the prompt may overweight recently completed tasks and deprioritize older blocked items that still matter. Guardrail: include explicit staleness timestamps in the state input and test for priority inversion against a ground-truth ordering weekly.
Bad Fit: Real-Time or Latency-Sensitive Loops
Avoid when: the agent must select the next action in under 200ms or inside a tight execution loop. The prompt's reasoning overhead adds unacceptable latency. Guardrail: use a deterministic rule-based scheduler for hot paths and reserve this prompt for periodic replanning checkpoints.
Copy-Ready Prompt Template
A copy-paste prompt that analyzes the current agent state and returns a ranked list of candidate next actions with rationale, expected state changes, and risk flags.
This prompt is the core decision module for an agent that must select its next action based on a structured representation of its current state. It is designed to be dropped into an agent loop where the application layer feeds in the state snapshot, candidate actions, and constraints, then parses the JSON output to drive execution. The prompt forces the model to reason about priority, dependencies, and risk before acting, which reduces impulsive tool calls and out-of-order execution in autonomous workflows.
textYou are an agent decision module. Your task is to analyze the current agent state and recommend the single highest-priority next action. You must also provide a ranked list of alternatives with rationale. ## CURRENT STATE [STATE_JSON] ## CANDIDATE ACTIONS For each candidate action, the following fields are provided: - action_id: unique identifier - description: what the action does - preconditions: conditions that must be true before this action can execute - estimated_cost: relative cost (low, medium, high) or token estimate - dependencies: list of action_ids that must complete first [CANDIDATE_ACTIONS] ## CONSTRAINTS - [CONSTRAINT_1] - [CONSTRAINT_2] - [CONSTRAINT_3] ## OUTPUT REQUIREMENTS Return a valid JSON object with this exact structure: { "recommended_action": { "action_id": "string", "rationale": "string explaining why this action is the highest priority right now", "expected_state_change": { "fields_updated": ["field_name"], "new_values": { "field_name": "expected value or type" } }, "risk_flags": ["flag1", "flag2"], "confidence": 0.0_to_1.0 }, "ranked_alternatives": [ { "action_id": "string", "rank": 1, "rationale": "string", "why_not_recommended": "string explaining why this was not chosen as the top action" } ], "unexecutable_actions": [ { "action_id": "string", "blocking_reason": "string explaining which precondition or dependency is not met" } ], "state_issues": [ "any inconsistencies, missing fields, or stale data detected in the current state" ] } ## RULES 1. Only recommend an action if all its preconditions are met and all dependencies are satisfied. 2. If no action is executable, set recommended_action to null and explain why in state_issues. 3. Prefer actions that unblock other high-value actions. 4. Flag any action that could cause irreversible side effects. 5. If confidence is below 0.7, include a specific uncertainty in the rationale. 6. Do not invent actions not present in the candidate list. 7. If the state contains contradictory information, flag it in state_issues and reduce confidence.
Adaptation guidance: Replace [STATE_JSON] with your application's serialized state object—this should include completed tasks, in-progress items, pending subtasks, resource availability, and any session metadata. Replace [CANDIDATE_ACTIONS] with the list of actions your agent can take, each annotated with preconditions and dependencies. The [CONSTRAINT] placeholders should capture hard rules like rate limits, budget caps, mandatory human approval gates, or domain-specific safety policies. If your model supports JSON mode or structured outputs, enable it and pass the output schema from the Expected Output Contract section to guarantee valid JSON. For high-risk domains, add a constraint requiring confidence above 0.9 before taking irreversible actions, and route low-confidence recommendations to a human review queue.
Prompt Variables
Each placeholder must be populated before the prompt is sent to the model. The quality of the state representation and candidate action list directly determines recommendation quality.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[CURRENT_STATE] | Serialized snapshot of agent progress, including completed tasks, in-progress items, pending subtasks, and any blocker flags | {"completed": ["T1", "T2"], "in_progress": {"T3": {"status": "blocked", "blocker": "missing_api_key"}}, "pending": ["T4", "T5"]} | Must be valid JSON with required keys: completed, in_progress, pending. Null values allowed for empty lists. Schema check before prompt assembly. |
[CANDIDATE_ACTIONS] | List of all possible next actions the agent could take, each with a unique ID, description, and estimated cost or duration | [{"id": "A1", "description": "Fetch user permissions from /auth endpoint", "estimated_duration_seconds": 2}, {"id": "A2", "description": "Retry failed T3 with new API key", "estimated_duration_seconds": 5}] | Must be a non-empty array. Each action requires id (string) and description (string). estimated_duration_seconds is optional but recommended. Parse check for valid JSON array. |
[GOAL_CONTEXT] | The original objective, success criteria, and any constraints or boundaries the agent must respect | {"objective": "Generate monthly compliance report for Q3", "success_criteria": ["All 12 required sections present", "Each claim cites a source document"], "constraints": ["Do not access production databases directly", "Max runtime 30 minutes"]} | Must include objective (string) and constraints (array). success_criteria is optional but strongly recommended. Validate that constraints are actionable, not vague. |
[TOOL_CATALOG] | Available tools, their input schemas, and current availability status for the agent to consider when ranking actions | [{"name": "query_database", "available": true, "input_schema": {"query": "string", "max_rows": "integer"}}, {"name": "send_email", "available": false, "reason": "SMTP credentials expired"}] | Each tool entry requires name (string) and available (boolean). input_schema recommended for available tools. Unavailable tools must include a reason string. Schema conformance check required. |
[PRIORITY_WEIGHTS] | Tunable weights for the ranking algorithm: urgency, impact, dependency resolution, cost, and risk tolerance | {"urgency_weight": 0.3, "impact_weight": 0.25, "dependency_weight": 0.2, "cost_weight": 0.15, "risk_weight": 0.1} | All weights must be floats between 0.0 and 1.0. Sum must equal 1.0 within a tolerance of 0.01. Parse check and sum validation before prompt injection. |
[BLOCKER_REGISTRY] | Known blockers with affected subtasks, root cause classification, and resolution status | [{"blocker_id": "B1", "affected_subtasks": ["T3"], "root_cause": "missing_api_key", "resolution_status": "pending_human", "detected_at": "2025-01-15T14:30:00Z"}] | Each blocker requires blocker_id, affected_subtasks (array), root_cause (string), and resolution_status (enum: pending_human, pending_retry, resolved, escalated). Timestamps must be ISO 8601. Enum check on resolution_status. |
[MAX_ACTIONS_TO_RETURN] | Integer cap on how many ranked actions the prompt should return to avoid overwhelming the execution loop | 3 | Must be a positive integer between 1 and 10. Values above 10 degrade decision quality in testing. Parse check for integer type and range validation. |
[OUTPUT_SCHEMA] | Expected JSON structure for the ranked action list, including rationale, expected state change, and risk flags per action | {"ranked_actions": [{"rank": 1, "action_id": "string", "rationale": "string", "expected_state_change": "string", "risk_flags": ["string"]}]} | Schema must be provided as a valid JSON Schema or example structure. Validate that the prompt output conforms to this schema post-generation. Missing rationale or risk_flags fields are common failure modes. |
Implementation Harness Notes
How to wire the State-Based Next Action Recommendation Prompt into an agent runtime as a reliable decision module.
This prompt is a decision module, not a standalone application. It should be called at specific decision points within an agent execution loop—typically after a tool call completes, when a subtask finishes, or when the agent's internal state changes. The prompt expects a structured state snapshot as input and returns a ranked list of candidate actions. The calling runtime is responsible for assembling the state snapshot, invoking the prompt, validating the output, and executing the top-ranked action. Do not treat this prompt as a free-form reasoning step; it must be called with a consistent state schema and its output must be machine-validated before any action is taken.
Integration pattern: Wrap the prompt in a function with a strict input contract. The function signature should accept a state object matching the [CURRENT_STATE] schema and return a parsed action list. Implement a JSON schema validator for the output before the agent acts on any recommendation. If validation fails, retry once with the validation error injected into the [CONSTRAINTS] block. If the retry also fails, fall back to a deterministic priority rule (e.g., execute the oldest pending task) and log the failure for review. Model selection: Use a model with strong instruction-following and structured output capabilities. For high-throughput loops, consider a smaller, fine-tuned model if action patterns are stable. For high-stakes domains, route to a more capable model and add a human approval gate for actions flagged with risk_level: high. Logging: Record every invocation with the input state hash, the recommended actions, the selected action, and the validation result. This trace is essential for debugging priority inversions and stale-state recommendations.
Tool integration: The recommended actions should map directly to tool names or function calls available in the agent runtime. The prompt's [AVAILABLE_TOOLS] block must be kept in sync with the actual tool registry. If a recommended action references a tool that is unavailable or has changed signature, the runtime must reject the recommendation and re-invoke the prompt with the corrected tool list. Retry and escalation: If the same action is recommended repeatedly without progress, the runtime should detect the loop (e.g., three identical recommendations with no state change), invoke a loop-detection prompt, and escalate to a human operator if the loop persists. Human review gate: For domains where incorrect actions carry material risk, insert a human approval step before executing any action with risk_level: high or confidence < 0.8. The approval UI should display the current state summary, the recommended action with rationale, and the expected state change.
What to avoid: Do not call this prompt on every tick of the agent loop without a state change—it wastes tokens and increases latency. Do not skip output validation; malformed action recommendations will crash the agent or cause silent failures. Do not use this prompt as a substitute for a proper planning module; it selects the next action from a known task set, it does not decompose new goals. Wire it as a narrow, well-tested decision point, and build the surrounding harness to catch its failures before they become agent failures.
Expected Output Contract
The model must return a JSON object matching this schema. Validate every field before using the output to drive agent behavior.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
recommended_action | object | Must contain id, priority, and rationale fields. Reject if missing any sub-field. | |
recommended_action.id | string | Must match pattern ^[A-Z]+-[0-9]{3,4}$. Reject if malformed or null. | |
recommended_action.priority | integer | Must be between 1 and 10 inclusive. Reject if out of range or non-integer. | |
recommended_action.rationale | string | Must be 20-500 characters. Reject if shorter, longer, or empty. | |
candidate_actions | array | Must contain 2-5 objects. Reject if empty, single element, or more than 5. | |
candidate_actions[].action_id | string | Must match pattern ^[A-Z]+-[0-9]{3,4}$. Reject duplicates within the array. | |
candidate_actions[].expected_state_change | string | Must be a non-empty string describing the post-action state. Reject if null or whitespace-only. | |
risk_flags | array | If present, each element must be one of: HALLUCINATION_RISK, TOOL_FAILURE, STALE_STATE, IRREVERSIBLE, PERMISSION_REQUIRED. Reject unknown flags. |
Common Failure Modes
State-based next action recommendation prompts fail in predictable ways. Each card below identifies a production failure mode, how to detect it, and how to build a guardrail before it reaches users.
Priority Inversion Under Load
What to watch: The model deprioritizes a genuinely urgent action because it overweights recency, verbosity, or surface-level salience in the state summary. A low-risk cleanup task gets ranked above a time-sensitive blocker. Guardrail: Include explicit priority weights and deadline fields in the state schema. Run eval pairs where the ground-truth priority contradicts surface features and measure ranking accuracy.
Stale State Drives Stale Actions
What to watch: The state summary contains outdated information—completed tasks still marked in-progress, resolved blockers still flagged—and the model recommends actions based on the stale view. Guardrail: Attach a last_updated timestamp to every state field. Before action ranking, run a staleness check prompt that flags fields older than a threshold and forces a refresh or confidence downgrade.
Overfitting to the First Plausible Action
What to watch: The model latches onto the first action that looks reasonable and generates rationalization rather than genuine comparison. The ranked list becomes a single real candidate plus filler. Guardrail: Require the output schema to include a why_not field for each top candidate explaining why it might be wrong. Test with adversarial state pairs where the obvious first action is incorrect.
Risk Blindness in Low-Information States
What to watch: When the state summary has gaps or low-confidence fields, the model still recommends actions with high certainty and no risk flags. Irreversible actions get recommended without escalation. Guardrail: Add a minimum_confidence gate. If any state field used in the recommendation falls below threshold, the prompt must either request clarification or escalate. Test with deliberately degraded state inputs.
Context-Window Truncation Drops Critical State
What to watch: In long-running sessions, the state summary grows until it exceeds the context window. The model's action recommendation is based on a truncated view that silently omits blockers or dependencies near the end. Guardrail: Implement a pre-ranking state compression step that prioritizes retention of blockers, unmet dependencies, and deadline-bearing items. Validate by comparing recommendations from full vs. truncated state and measuring divergence.
Action Churn Across Consecutive Calls
What to watch: The model recommends action A on call N, then recommends action B on call N+1 without any state change, then flips back to A on call N+2. This oscillation wastes tool calls and violates latency budgets. Guardrail: Include the previous recommendation and its outcome in the state input. Add a constraint that changing the top-ranked action requires explicit new evidence. Monitor action-flip rate in production traces.
Evaluation Rubric
Test your prompt against these criteria before deploying to production. Run evaluations on a golden dataset of state-action pairs with known correct rankings.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Top-1 Action Correctness | The highest-ranked action matches the ground-truth priority action in at least 90% of golden cases | Top-1 accuracy below 85% or systematic preference for a specific action type regardless of state | Run prompt on golden dataset with known correct top action; compute exact-match accuracy across all cases |
Rank Correlation | Spearman rank correlation between predicted and ground-truth action ordering is at least 0.80 | Correlation below 0.70 or inverted ordering for high-severity state scenarios | Compute Spearman's rho between predicted ranking and ground-truth ranking for each test case; report mean and distribution |
Rationale Grounding | Every recommended action includes a rationale that references at least one specific state field from [CURRENT_STATE] | Rationale contains generic language with no state reference, or hallucinates state fields not present in input | Parse rationale text; verify each rationale string contains at least one key or value present in the input state object |
Risk Flag Presence | Actions with potential negative side effects include a non-empty risk flag in the output | High-risk actions such as data deletion or user notification lack risk flags, or risk flags are empty strings | Maintain a list of high-risk action types; for each output action matching that list, assert risk_flag field is non-null and non-empty |
Expected State Change Validity | Each action's expected_state_change describes a plausible transformation of [CURRENT_STATE] fields | Expected state change contradicts current state values, references nonexistent fields, or describes impossible transitions | Parse expected_state_change; validate that referenced fields exist in input schema and that before-to-after transitions are logically consistent |
Output Schema Conformance | Output is valid JSON matching the [OUTPUT_SCHEMA] with all required fields present and correctly typed | Missing required fields, wrong types, extra fields not in schema, or malformed JSON that fails to parse | Validate output against JSON Schema definition; reject on parse failure, missing required fields, or type mismatches |
Action Count Constraint | Output contains between 1 and [MAX_ACTIONS] ranked candidate actions | Zero actions returned when state clearly requires action, or more than [MAX_ACTIONS] returned without truncation | Count actions array length; assert length is between 1 and [MAX_ACTIONS] inclusive |
Priority Justification Consistency | Higher-ranked actions have stronger or more urgent justification than lower-ranked actions in the same output | Lower-ranked action has justification indicating higher urgency than a higher-ranked action, or justifications are identical across ranks | Pairwise comparison of justification urgency language across adjacent ranks; flag inversions where lower rank implies higher urgency |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Start with the base prompt and a simple JSON schema for the ranked action list. Use a single-turn call with a hardcoded state object. Skip confidence scoring and risk flags initially. Focus on getting the ranking order correct before adding complexity.
codeYou are an agent state analyzer. Given the current agent state below, recommend the single highest-priority next action. Current State: [AGENT_STATE_JSON] Return a JSON object with: - "top_action": the action ID - "rationale": one sentence explaining why
Watch for
- The model picking the easiest action instead of the highest-priority one
- Rationales that sound plausible but contradict the state
- Missing validation of whether the recommended action's preconditions are actually met

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us