This prompt is for developers building coding agents, tool-use agents, or multi-step automation systems where the model must resolve a user's natural language reference to a specific previous action, its output, or a generated artifact. The core job-to-be-done is converting a follow-up instruction like 'run a linter on the file I just created' or 'debug its result' into a concrete, machine-readable target—a tool call argument, an artifact ID, or a file path—by grounding the reference in the agent's recent action history. The ideal user is an AI engineer or product developer integrating an LLM into an agent loop that maintains a structured action log. You need a well-formed action history with unique action IDs, timestamps, output summaries, and statuses (success, failure, in-progress) for this prompt to work. Without that structured context, the model has nothing to resolve against and will hallucinate references.
Prompt
Agent Action Reference Resolution Prompt

When to Use This Prompt
Define the job, reader, and constraints for the Agent Action Reference Resolution Prompt.
Do not use this prompt when the agent has no action history to reference, when the user's instruction is fully self-contained with explicit file paths or IDs, or when the referenced action failed or was rolled back and its artifacts are no longer available. In that last case, the prompt's failure mode check is designed to detect the invalid reference and return a status: 'invalid_reference' instead of guessing. This prompt is also inappropriate for simple single-turn tool calls where no prior context exists. If your system allows users to refer to entities outside the action log—such as files in a repository or knowledge base articles—you need a separate entity-linking step before this prompt, or you must extend the [CONTEXT] to include those external candidates. For high-stakes actions like database migrations, production deployments, or destructive file operations, always route the resolved action through a human approval step before execution, regardless of the model's confidence.
Before implementing this prompt, ensure your agent harness captures and persists a structured action log. Each entry should include at minimum an action_id, a human-readable description of what was done, the status, and any output_artifacts with their IDs or paths. This log becomes the [ACTION_HISTORY] input to the prompt. The prompt is designed to be stateless per call—it does not modify the log—so you can run it safely as a pre-processing step before tool execution. Start by testing it against a golden set of reference patterns: direct pronouns ('it', 'that file'), definite descriptions ('the config I just generated'), and ordinal references ('the second test'). Measure precision and recall on resolved action IDs before integrating it into your agent's critical path.
Use Case Fit
Where the Agent Action Reference Resolution Prompt works, where it fails, and the operational risks to manage before deployment.
Good Fit: Tool-Use Agents with Linear Histories
Use when: The agent executes a sequence of tool calls and the user refers to a previous action by its result or ordinal position (e.g., 'the file I just created', 'its output', 'step 3'). The prompt reliably resolves these references when the action history is a clean, append-only log. Guardrail: Ensure the action log passed into the prompt includes only successful, committed actions. Filter out failed, rolled-back, or in-progress steps before resolution.
Bad Fit: Ambiguous References Without Disambiguation Budget
Avoid when: The user's reference could map to multiple prior actions with similar artifacts (e.g., two 'config files' created in different steps) and the system has no budget for a clarification turn. The prompt will guess, often incorrectly. Guardrail: Implement a confidence threshold. If the top candidate score is below the threshold, route to a clarification prompt instead of forcing a resolution.
Required Input: Structured Action History
What to watch: The prompt cannot resolve references from unstructured chat logs alone. It requires a structured history of prior actions, each with a unique ID, tool name, input arguments, output summary, and success/failure status. Guardrail: Build a dedicated action log schema in your agent harness. Do not rely on the model to parse raw conversation text to find prior actions.
Operational Risk: Referencing Failed or Rolled-Back Actions
Risk: The user refers to 'the deployment' or 'the migration', but that action failed or was rolled back. The prompt may resolve the reference to a non-existent or invalid artifact, causing the agent to act on bad state. Guardrail: Include an explicit status field for each action in the history. Add a pre-resolution check that rejects references to actions with a terminal failure or rollback status and returns an error explaining why.
Operational Risk: Stale References After Many Turns
Risk: In long sessions, a user's reference like 'the error from earlier' may point to an action from 20 turns ago that is no longer relevant or has been superseded. Guardrail: Implement a recency bias in the prompt instructions and consider pruning the action history to the last N turns or a time window. Add a staleness flag to the output if the resolved action exceeds a configurable age threshold.
Bad Fit: Non-Action References in Mixed Dialogue
Avoid when: The conversation mixes action references with general dialogue references (e.g., 'the idea you mentioned' vs. 'the file you created'). The prompt may incorrectly treat a conceptual reference as an action reference. Guardrail: Add a pre-classification step that determines whether the user's turn contains an action artifact reference at all. Route non-action references to a general coreference resolver instead.
Copy-Ready Prompt Template
A reusable prompt template for resolving agent action references to previous tool calls, outputs, and artifacts.
This prompt template is designed to be dropped into an agent loop immediately after a user turn that contains an ambiguous reference to a prior action. It forces the model to ground the reference in the actual execution history—tool call IDs, output artifacts, file paths, or error states—rather than guessing. The template uses square-bracket placeholders so you can wire it into your agent harness with the current session state, available tool schemas, and the specific reference that needs resolution.
textYou are an action reference resolver for an agent that has already executed tool calls. Your job is to resolve the user's reference to a previous action, output, or artifact into a concrete, machine-readable identifier. ## RESOLUTION RULES 1. Map the user's reference to exactly one prior action from the execution history. 2. If the referenced action failed, was rolled back, or produced an error, you MUST flag it as UNRESOLVABLE with the failure reason. 3. If multiple candidates match, return the most recent one that satisfies all explicit constraints (temporal, type, status). 4. If no candidate matches, return UNRESOLVABLE with a suggested clarification question. 5. Never invent an action ID or artifact path that does not appear in the history. ## INPUTS **User Reference:** [USER_REFERENCE] **Execution History (most recent first):** [EXECUTION_HISTORY] **Current Working Context:** [WORKING_CONTEXT] ## OUTPUT SCHEMA Return ONLY valid JSON matching this schema: { "status": "RESOLVED" | "UNRESOLVABLE" | "MULTIPLE_CANDIDATES", "resolved_action_id": "string | null", "resolved_artifact": { "type": "tool_call_id" | "file_path" | "output_id" | "error_id", "value": "string | null" }, "candidate_actions": ["string (action IDs)"], "failure_reason": "string | null (required if UNRESOLVABLE)", "clarification_question": "string | null (required if UNRESOLVABLE or MULTIPLE_CANDIDATES)", "confidence": 0.0-1.0 } ## CONSTRAINTS [CONSTRAINTS] ## EXAMPLES [EXAMPLES]
To adapt this template, replace each placeholder with live data from your agent runtime. [USER_REFERENCE] is the raw user utterance containing the reference, such as "run the linter on the file I just created" or "retry its output." [EXECUTION_HISTORY] should be a structured dump of recent tool calls with their IDs, arguments, outputs, status codes, and timestamps—ordered most recent first. [WORKING_CONTEXT] includes the current working directory, open files, or active session artifacts that the user might implicitly reference. [CONSTRAINTS] is where you inject domain-specific rules, such as "never resolve to a tool call that modified a production database" or "require human confirmation for any resolved action that deletes data." [EXAMPLES] should include 2-4 few-shot demonstrations covering a successful resolution, an unresolvable reference due to a failed action, and a multiple-candidate disambiguation case. Before deploying, validate that the output JSON parses correctly and that the resolved_action_id actually exists in the execution history you provided—this is the most common silent failure mode.
After integrating this prompt into your agent loop, add a post-resolution validator that checks whether the resolved action ID is still valid at execution time. Actions that completed successfully may have had their side effects overwritten by subsequent steps, and actions that failed may have left partial state. Wire the UNRESOLVABLE path to a clarification prompt that asks the user a single targeted question, not a generic "I didn't understand." For high-risk domains where the agent can modify files, run commands, or change configuration, route all MULTIPLE_CANDIDATES resolutions to a human approval queue before the agent acts on the resolved reference.
Prompt Variables
Placeholders required by the Agent Action Reference Resolution Prompt. Each variable must be populated from the agent's runtime state before the prompt is assembled. Validation notes describe how to verify the input is well-formed and safe before inference.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[CURRENT_USER_UTTERANCE] | The latest user message containing a reference to a prior action, output, or artifact. | What was the exit code of that last build? | Non-empty string. Must be the raw, unmodified user input. Check for null or whitespace-only strings before assembly. |
[ACTION_HISTORY_LOG] | Chronological list of previous actions taken by the agent, including tool names, arguments, and statuses. | [{action_id: act-7, tool: run_tests, status: completed, output_artifact_id: art-42}] | Must be a valid JSON array. Each entry requires action_id, tool, status, and output_artifact_id fields. Reject if status is missing or if the array exceeds the context budget. |
[ARTIFACT_REGISTRY] | Map of artifact IDs to their metadata, including type, file path, creation timestamp, and current validity status. | {art-42: {type: test_report, path: /tmp/results.xml, valid: true, created_at: 2025-01-15T10:30:00Z}} | Must be a valid JSON object. Each artifact entry requires a valid boolean field. Reject any artifact where valid is false or null; these must be excluded from resolution candidates. |
[ROLLBACK_LOG] | List of actions that were rolled back or had their side effects reversed, with timestamps and rollback reasons. | [{rolled_back_action_id: act-5, reason: user_abort, timestamp: 2025-01-15T10:29:00Z}] | Must be a valid JSON array. Entries require rolled_back_action_id and timestamp. If empty, provide an empty array. Any action ID present here must be excluded from reference resolution. |
[AGENT_CAPABILITY_MANIFEST] | List of available tools and their input schemas, used to validate that a resolved reference can be mapped to a valid tool argument. | [{tool: read_file, params: {file_path: string}}] | Must be a valid JSON array conforming to the agent's tool schema contract. Each tool entry requires a tool name and a params object. Validate against the actual tool registry at assembly time to prevent schema drift. |
[RESOLUTION_POLICY] | Rules for how the agent should handle ambiguous, stale, or failed-action references. | prefer_recent: true, max_candidates: 3, stale_threshold_seconds: 300, on_failed_action: flag_for_human | Must be a valid JSON object. Required fields: prefer_recent (boolean), max_candidates (integer > 0), stale_threshold_seconds (integer >= 0), on_failed_action (enum: flag_for_human | abort | skip). Reject if on_failed_action is not a recognized value. |
[CONTEXT_WINDOW_BUDGET_BYTES] | Maximum byte size allocated for the assembled prompt, used to truncate history logs if necessary. | 8000 | Must be a positive integer. Validate that the assembled prompt does not exceed this value before inference. If truncation is required, prioritize keeping the most recent actions and the artifact registry intact. |
Implementation Harness Notes
How to wire the Agent Action Reference Resolution Prompt into a coding or tool-use agent application with validation, retries, and failure handling.
The Agent Action Reference Resolution Prompt is designed to sit between the user's natural-language instruction and the agent's tool execution layer. When a user says 'run the test I just wrote' or 'deploy its output', the application must resolve those references into concrete tool call arguments—file paths, artifact IDs, or command parameters—before the agent can act. This prompt is not a standalone chatbot; it is a resolution step in a pipeline. The typical wiring pattern is: receive user input, retrieve recent agent action history from the session store, assemble the prompt with the user utterance and action log, call the model, validate the resolved output, and then pass the resolved arguments to the downstream tool executor.
Input Assembly: The prompt requires two primary inputs: the current user utterance and a structured action history. The action history should be a JSON array of recent agent actions, each containing at minimum an action_id, action_type (e.g., file_create, tool_call, deploy), status (success, failed, rolled_back), timestamp, and a summary field describing what the action produced. Do not pass raw tool output logs; summarize them into concise, referenceable descriptions. For example, instead of dumping a full compiler output, store "Compiled main.go with no errors, produced binary at ./bin/app". This summarization step is critical—the model needs enough detail to disambiguate references but not so much that it overwhelms the context window or introduces noise.
Validation and Failure Modes: After the model returns a resolved reference, validate the output against the action history before executing any tool call. Check that the resolved action_id or artifact_id actually exists in the history and that its status is not failed or rolled_back. If the model resolves a reference to a failed action, the harness must intercept this and either prompt the user for clarification or return a structured error. Implement a retry loop with a maximum of two attempts: if the first resolution produces an invalid or missing reference, append the validation error to the prompt context and retry. If the second attempt also fails, escalate to the user with a clear message like 'I couldn't find the file you're referring to. The last file I created was ./src/utils_test.go. Did you mean that?' Never silently execute a tool call with an unresolved or guessed reference in production.
Model Choice and Latency: This prompt is a classification-plus-resolution task, not a generation task. Use a fast, instruction-tuned model such as GPT-4o-mini, Claude 3.5 Haiku, or Gemini 1.5 Flash. The prompt is designed to work with a single model call per resolution; avoid chaining multiple models for this step. If your agent already maintains a structured action log, the resolution step should add under 500ms of latency. Cache the action history summary in the session store and update it after each agent action to avoid recomputing summaries on every turn. For high-throughput coding agents, consider batching resolution requests when a user utterance contains multiple references, but always validate each resolved reference independently.
Logging and Observability: Log every resolution attempt with the user utterance, the action history snippet used, the model's raw output, the validated result, and whether the resolution succeeded or escalated. This trace is essential for debugging reference resolution failures in production. Common failure patterns to monitor include: the model resolving to an action that was rolled back, the model hallucinating an action ID that never existed, and the model defaulting to the most recent action when the user intended an earlier one. Set up an eval harness that runs a golden set of reference-resolution test cases—including ambiguous references, references to failed actions, and references across long action histories—against every prompt change before deployment.
Expected Output Contract
The resolved output must be a single, machine-readable JSON object. Use this contract to validate the agent's response before passing the resolved argument or artifact ID to the next tool call.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
resolved_action | string | Must match a valid action name from [ACTION_CATALOG] exactly. No paraphrasing allowed. | |
resolved_arguments | object | Must conform to the JSON schema of the resolved action. All required parameters must be present and non-null. | |
artifact_id | string or null | If the reference resolves to a previous output, this must be the exact ID from [SESSION_ARTIFACTS]. Null if the reference is to an action, not an artifact. | |
reference_source_turn | integer or null | The turn index from [SESSION_HISTORY] that grounds the resolution. Must be null if and only if resolution_status is 'unresolvable'. | |
resolution_status | enum | Must be one of: 'resolved', 'unresolvable', 'requires_clarification'. No other values permitted. | |
clarification_question | string or null | Required if resolution_status is 'requires_clarification'. Must be a single, targeted question. Must be null otherwise. | |
failure_mode_check | object | Must contain a boolean 'is_failed_or_rolled_back' field. If true, the agent must not proceed with the resolved action and must escalate. | |
confidence_score | float | A value between 0.0 and 1.0. If below [CONFIDENCE_THRESHOLD], the system must trigger a clarification or human review path. |
Common Failure Modes
What breaks first when resolving agent action references and how to guard against it.
Referenced Action Failed or Was Rolled Back
What to watch: The model resolves a reference like 'the file I just created' to an action that failed silently, returned an error, or was rolled back by a subsequent tool call. The resolved artifact ID points to nothing valid. Guardrail: Before resolving, inject the last N action outcomes with explicit success/failure status. Require the prompt to check action status and output a reference_valid boolean. If false, escalate to clarification instead of resolving.
Ambiguous Match Across Multiple Similar Actions
What to watch: The user says 'run the test again' but the agent has executed three different test commands in the last five turns. The prompt picks the most recent action, which is the wrong one. Guardrail: Include a disambiguation step that ranks candidates by recency, type match, and explicit user naming. If the top two candidates are within a confidence threshold, force a targeted clarification question rather than guessing.
Stale Reference to Overwritten or Deleted Artifacts
What to watch: The user refers to 'its output' but the artifact was overwritten by a later action or deleted from the workspace. The resolved ID points to a file or object that no longer exists. Guardrail: Maintain a session artifact ledger with create/update/delete timestamps. Before resolving, validate that the artifact ID still exists in the current workspace state. If not, return a stale_reference flag with the last known state.
Pronoun Drift Across Long Action Chains
What to watch: In a chain of 10+ tool calls, 'it' or 'that' drifts from the intended referent because the model latches onto the most recent noun phrase in the assistant's own response rather than the user's intended target. Guardrail: Structure the prompt to prioritize user-mentioned entities over assistant-mentioned entities when resolving pronouns. Include explicit turn-level salience scoring that decays with distance but resets on explicit user re-mention.
Implicit Reference to Side-Effect Outputs
What to watch: The user says 'debug the error' referring to a stack trace that appeared in a tool output three turns ago but was never explicitly named or saved as an artifact. The resolver misses it because it only indexes explicit action outputs. Guardrail: Expand the reference candidate set to include error messages, warnings, and unstructured text from tool outputs, not just artifact IDs. Tag these as implicit_referents with a confidence score and source turn.
Resolution Bypasses Human Approval Gate
What to watch: The resolver maps 'the config change' to a destructive action that requires human approval, but the resolved tool call skips the approval check because the reference resolution happened before the guardrail was evaluated. Guardrail: Attach an approval_required flag to each action in the history. When resolving a reference to an action with that flag set, re-trigger the approval flow before executing the resolved tool call. Never let resolution shortcut the approval pipeline.
Evaluation Rubric
Use this rubric to test the Agent Action Reference Resolution Prompt before shipping. Each criterion targets a specific failure mode common in tool-use agents resolving references to prior actions, outputs, or artifacts.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Exact Artifact ID Resolution | Resolved [ARTIFACT_ID] matches the single correct file, output, or result from the referenced action in session history. | Returns an ID for a different artifact, a deleted artifact, or a hallucinated ID not present in the tool call log. | Run 20 test cases with known prior actions. Assert resolved ID equals expected ID. Check for off-by-one errors when multiple similar artifacts exist. |
Failed Action Reference Handling | When the user references an action that failed or was rolled back, the output includes | Returns a resolved ID for a failed action or silently substitutes a different artifact without flagging the failure. | Inject a session history where the referenced tool call returned an error. Verify the output abstains and surfaces the failure reason. |
Ambiguous Reference Clarification | When multiple prior actions match the user's description, the output includes | Arbitrarily picks the most recent or first match without indicating ambiguity, or returns a null ID without explanation. | Create a session with two similar file-write actions. Use a vague reference like 'the file I just created'. Verify the output lists both candidates and requests disambiguation. |
Implicit Artifact Reference Grounding | Resolves references like 'its result' or 'the output' to the correct artifact from the immediately preceding or most salient action. | Links 'its result' to an action from 5 turns ago when a more recent action is the clear antecedent, or fails to resolve entirely. | Construct a turn sequence with interleaved actions. Use 'run that again with its output' and verify the resolver correctly chains the action and its result artifact. |
Tool Call Argument Reconstruction | Produces a valid, complete tool call argument object in [RESOLVED_TOOL_CALL] that merges the resolved reference with any new user parameters. | Generates a tool call with missing required parameters, hallucinates default values, or includes stale parameters from the original action that the user did not repeat. | Validate the output [RESOLVED_TOOL_CALL] against the target tool's JSON schema. Check that only explicitly referenced prior values are carried forward. |
Cross-Turn Entity Persistence | Correctly tracks an artifact across multiple turns even when the user uses different descriptors, such as 'the config file', 'that YAML', and 'it'. | Loses track of the entity after a topic shift or fails to update the reference when a new artifact of the same type is created. | Simulate a 10-turn session with multiple file creations. Use a chain of 3 different references to the same artifact. Verify consistent ID resolution at each step. |
Stale Reference Re-Verification | When a reference points to an artifact that was modified or deleted after creation, the output flags the artifact as stale and requests re-confirmation. | Blindly resolves to the original artifact ID without checking whether subsequent actions invalidated it. | Create a session where a file is created, then deleted, then referenced. Verify the output indicates the artifact no longer exists and does not return the original ID. |
Hallucination Prevention Under No Match | When no prior action matches the user's reference, the output includes | Generates a plausible-sounding but non-existent artifact ID, or hallucinates a prior action that never occurred in the session. | Feed a session with 5 unrelated actions and a reference to 'the report I exported'. Verify the output abstains cleanly without inventing an export action or file ID. |
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
Use the base prompt with a simple JSON output schema. Drop the [FAILURE_MODE_CHECK] and [ROLLBACK_DETECTION] sections initially. Focus on getting correct resolutions for the happy path.
codeYou are an agent action reference resolver. Given the [ACTION_HISTORY] and the user's [CURRENT_UTTERANCE], resolve any references to previous actions, outputs, or artifacts. Return JSON: { "resolved_action_id": "string | null", "resolved_artifact_id": "string | null", "confidence": "high | medium | low" }
Watch for
- Resolving to the most recent action by default when the user meant an earlier one
- Confusing file creation actions with file modification actions
- Missing temporal cues like 'the one I just created' vs 'the one from earlier'

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