Inferensys

Prompt

Agent Memory Refresh and State Reconciliation Prompt

A practical prompt playbook for using Agent Memory Refresh and State Reconciliation Prompt in production AI workflows.
Developer doing prompt engineering on laptop, prompt variations visible on screen, casual coding session.
PROMPT PLAYBOOK

When to Use This Prompt

Learn when to deploy the Agent Memory Refresh and State Reconciliation Prompt and when to choose a different tool.

This prompt is designed for a specific architectural moment: the agent has been away from its session and must now re-enter. The break could be caused by a deployment restart, a context-window overflow that forced an eviction, or a human-in-the-loop pause that lasted long enough for the environment to change. In all these cases, the agent holds a stored state object from a prior checkpoint, but it cannot trust that memory blindly. The job-to-be-done is to compare that stored state against fresh observations from the environment, flag contradictions, mark stale data, and produce a single reconciled state object that the agent can use as its new source of truth before resuming autonomous execution.

The ideal user is an agent runtime developer or AI engineer who is building a state-management layer for autonomous or semi-autonomous agents. You should use this prompt when your agent runtime detects a session boundary and needs to rebuild a trustworthy internal state. The required context includes the stored state object, a set of fresh observations from the environment, and a schema that defines what a valid reconciled state looks like. The prompt expects the model to act as a skeptical auditor, not a trusting summarizer. It must actively look for contradictions between memory and evidence, and it must never silently carry forward a stale field just because it was present in the stored state.

Do not use this prompt for real-time state updates during active execution. When an agent is mid-workflow and a tool returns a result, that update belongs to a step-verification or postcondition-validation prompt, not a full memory reconciliation. This prompt is also a poor fit for simple conversational state tracking, where a turn-level summary is sufficient and there is no external environment to reconcile against. For those cases, use a multi-turn session state summary prompt instead. Finally, avoid this prompt when the stored state is known to be fully trustworthy and the environment is static; the reconciliation overhead adds latency and token cost without benefit.

Before deploying this prompt, ensure your agent runtime can reliably detect session boundaries and trigger the reconciliation workflow. A common failure mode is calling this prompt too frequently, which wastes tokens and can introduce instability if the model overcorrects minor discrepancies. Another failure mode is calling it too late, after the agent has already acted on stale state and caused side effects that are expensive to unwind. Wire the prompt into a state-machine guard that fires on session start, not on every turn. Pair it with a state integrity validation prompt to verify the reconciled output before the agent resumes execution.

PRACTICAL GUARDRAILS

Use Case Fit

Where the Agent Memory Refresh and State Reconciliation Prompt delivers value and where it introduces risk.

01

Good Fit: Long-Running Autonomous Agents

Use when: An agent resumes a session after a tool call, human-in-the-loop pause, or context-window flush and must reconcile its stored state with new observations. Guardrail: Always pair this prompt with a state integrity validation check to catch silent corruption before the agent acts on stale data.

02

Bad Fit: Real-Time Streaming Workflows

Avoid when: Latency budgets are under 500ms or the agent operates on a continuous event stream without discrete pause points. Risk: The reconciliation prompt adds a full round-trip that violates latency SLOs. Guardrail: Use lightweight state diffs computed in application code instead of an LLM call for time-sensitive paths.

03

Required Input: Prior State Snapshot

What to watch: Without a structured prior state object, the model cannot detect contradictions or flag stale data. Guardrail: Always provide a machine-readable state snapshot with timestamps and provenance markers. Reject reconciliation requests that lack a prior state input.

04

Required Input: Fresh Observations

What to watch: Reconciliation without new evidence is just state re-reading and wastes tokens. Guardrail: Require at least one new observation, tool result, or environment reading before invoking this prompt. Gate the call in the agent runtime to skip reconciliation when no new data exists.

05

Operational Risk: Over-Correction

Risk: The model may over-trust fresh observations and discard valid stored state, causing the agent to repeat completed work or lose important context. Guardrail: Require the output to include explicit conflict flags and confidence scores per field. Route high-impact state changes to a human approval queue before the agent acts on them.

06

Operational Risk: Confirmation Bias

Risk: The model may favor stored state over contradictory fresh evidence, especially when the prior state is presented with high confidence language. Guardrail: Structure the prompt to present observations first and stored state second. Add an explicit instruction to prefer observation-grounded facts when conflicts arise, with mandatory evidence citations.

PROMPT PLAYBOOK

Copy-Ready Prompt Template

A reusable prompt template for reconciling an agent's stored session state with fresh observations, flagging conflicts and stale data.

The following prompt template is designed to be dropped into an agent's state reconciliation step. It forces the model to compare a previously stored state snapshot against new evidence, producing an updated state object with explicit conflict markers and stale-data flags. Use this when an agent returns to a session after a gap, when a tool call returns results that contradict prior assumptions, or when a human operator provides corrective feedback that invalidates parts of the stored state.

text
You are an agent state reconciliation module. Your task is to compare the [STORED_STATE] against [NEW_OBSERVATIONS] and produce an updated state object.

[STORED_STATE] contains the agent's last known representation of the session, including completed tasks, in-progress items, pending actions, and any assumptions or preferences recorded during prior turns.

[NEW_OBSERVATIONS] contains fresh evidence gathered since the state was last saved. This may include tool call results, user corrections, sensor readings, or outputs from other agents.

[CONFLICT_RESOLUTION_POLICY] defines how to handle contradictions:
- If [NEW_OBSERVATIONS] directly contradicts a field in [STORED_STATE], prefer the new observation unless [CONFLICT_RESOLUTION_POLICY] specifies otherwise.
- Flag all overridden fields with a `conflict_resolved` marker and record both the old value and the new value.
- If a field in [STORED_STATE] cannot be verified by [NEW_OBSERVATIONS] and is older than [STALENESS_THRESHOLD], mark it as `stale` and reduce its confidence score.

[OUTPUT_SCHEMA] requires the following structure:
{
  "updated_state": {
    "completed_tasks": [
      {
        "task_id": "string",
        "status": "completed",
        "completed_at": "ISO8601 timestamp",
        "evidence_ref": "reference to supporting observation"
      }
    ],
    "in_progress_tasks": [
      {
        "task_id": "string",
        "status": "in_progress",
        "last_known_step": "string",
        "confidence": 0.0-1.0,
        "stale": false
      }
    ],
    "pending_tasks": [
      {
        "task_id": "string",
        "status": "pending",
        "blockers": ["string"],
        "stale": false
      }
    ],
    "assumptions": [
      {
        "field": "string",
        "value": "any",
        "confidence": 0.0-1.0,
        "stale": false,
        "conflict_resolved": false,
        "previous_value": null
      }
    ],
    "session_metadata": {
      "last_updated": "ISO8601 timestamp",
      "reconciliation_timestamp": "ISO8601 timestamp",
      "observation_sources": ["string"]
    }
  },
  "conflicts": [
    {
      "field_path": "string",
      "old_value": "any",
      "new_value": "any",
      "resolution": "string explaining why new value was chosen",
      "confidence_after_resolution": 0.0-1.0
    }
  ],
  "stale_fields": [
    {
      "field_path": "string",
      "last_verified": "ISO8601 timestamp or null",
      "reason": "string explaining why this field could not be verified"
    }
  ],
  "unresolved_items": [
    {
      "item": "string",
      "issue": "string describing what remains uncertain",
      "recommended_action": "re-observe | ask_user | escalate | accept_uncertainty"
    }
  ]
}

[CONSTRAINTS]:
- Do not invent observations. Only use evidence present in [NEW_OBSERVATIONS].
- If a task appears in both [STORED_STATE] and [NEW_OBSERVATIONS] with different statuses, treat it as a conflict.
- If [NEW_OBSERVATIONS] is empty or contains only a timestamp update, do not mark fields as stale unless they exceed [STALENESS_THRESHOLD].
- Preserve all task IDs from [STORED_STATE] unless [NEW_OBSERVATIONS] proves they are invalid.
- Set confidence scores below 0.5 for any field that relies on a single unverified observation.

[EXAMPLES]:
[FEW_SHOT_EXAMPLES]

Produce only the JSON output matching [OUTPUT_SCHEMA]. Do not include explanatory text outside the JSON object.

To adapt this template, replace each square-bracket placeholder with concrete values from your agent runtime. [STORED_STATE] should be the serialized state object from your last checkpoint. [NEW_OBSERVATIONS] should be a structured dump of recent tool results, user messages, or sensor data. [CONFLICT_RESOLUTION_POLICY] can be a short rule like "prefer user corrections over tool output" or "prefer the most recent timestamp." [STALENESS_THRESHOLD] should be a duration string such as "5 minutes" or "1 hour" depending on how rapidly your domain state decays. [FEW_SHOT_EXAMPLES] should contain one or two worked examples showing a conflict and a stale-field scenario so the model internalizes the expected behavior before processing the real input.

Before deploying this prompt into a production agent loop, validate the output against the schema using a JSON schema validator. Run eval cases where you deliberately inject contradictions between [STORED_STATE] and [NEW_OBSERVATIONS] and confirm that the conflicts array captures every injected discrepancy. Test edge cases: empty observations, completely stale state, identical state and observations, and malformed input. If the agent operates in a domain where incorrect state could cause financial, safety, or compliance harm, route the unresolved_items array to a human reviewer before the agent acts on the reconciled state. Do not let the agent execute irreversible actions based on fields marked with confidence below your operational threshold.

IMPLEMENTATION TABLE

Prompt Variables

Required inputs for the Agent Memory Refresh and State Reconciliation Prompt. Each placeholder must be populated before the prompt is assembled. Validation notes describe how to verify the input is well-formed before sending it to the model.

PlaceholderPurposeExampleValidation Notes

[STORED_STATE]

The agent's previously persisted state snapshot, including completed tasks, in-progress items, and known facts from the last session.

{"session_id":"sess_42","completed":["task_1"],"in_progress":{"task_2":"awaiting_api_response"},"facts":{"user_name":"Alex"}}

Must be valid JSON. Schema check: required fields are session_id, completed, in_progress, facts. Reject if session_id is missing or state timestamp is older than 24 hours without a staleness marker.

[NEW_OBSERVATIONS]

Fresh evidence gathered since the last state save, such as tool outputs, user messages, or sensor readings that may confirm or contradict stored state.

["API returned status 200 for task_2","User message: 'My name is actually Jordan now'"]

Must be a non-empty array of strings or structured observation objects. Reject if empty or if any observation lacks a timestamp or source identifier. Each observation must have a source field for provenance tracking.

[CONFLICT_RESOLUTION_POLICY]

Rules for how to resolve contradictions between stored state and new observations. Defines whether fresh evidence always wins, stored state is authoritative, or a confidence-weighted merge is required.

"fresh_evidence_wins_with_log"

Must be one of: fresh_evidence_wins_with_log, stored_state_authoritative, confidence_weighted_merge, escalate_to_human. Reject unknown values. If escalate_to_human is set, ensure [ESCALATION_TARGET] is also populated.

[STALENESS_THRESHOLD_SECONDS]

Maximum age in seconds before a stored state entry is automatically flagged as stale and requires re-verification.

3600

Must be a positive integer. Reject values below 60 (too aggressive) or above 86400 (24 hours, likely too permissive for most agent workflows). Default to 3600 if not provided but log a warning.

[OUTPUT_SCHEMA]

The expected JSON schema for the reconciled state output, defining required fields, types, and conflict-flag structure.

{"type":"object","required":["reconciled_state","conflicts","stale_fields"],"properties":{"conflicts":{"type":"array","items":{"type":"object","required":["field","stored_value","observed_value","resolution"]}}}}

Must be a valid JSON Schema draft-07 object. Validate with a schema parser before prompt assembly. Reject if required fields reconciled_state, conflicts, or stale_fields are missing from the schema definition.

[AGENT_IDENTITY]

A stable identifier for the agent instance, used to tag state updates and prevent cross-session contamination.

"agent_checkout_flow_v2"

Must be a non-empty string matching the pattern ^[a-z0-9_]+$. Reject if it contains spaces, special characters, or exceeds 64 characters. This value is used in audit logs and state partitioning.

[MAX_CONFIDENCE_THRESHOLD]

The confidence level above which the model should auto-resolve conflicts without flagging for human review. Conflicts below this threshold are escalated.

0.85

Must be a float between 0.0 and 1.0. Reject values below 0.5 (too permissive) or exactly 1.0 (never auto-resolves). Default to 0.85 if not provided. Pair with [ESCALATION_TARGET] when conflicts fall below this threshold.

[ESCALATION_TARGET]

The human role, queue, or system to notify when conflicts cannot be auto-resolved or when the staleness threshold is exceeded with high-impact state.

"ops_review_queue"

Must be a non-empty string. Required when [CONFLICT_RESOLUTION_POLICY] is escalate_to_human or when [MAX_CONFIDENCE_THRESHOLD] is set below 0.7. Validate that the target exists in the routing configuration before prompt execution.

PROMPT PLAYBOOK

Implementation Harness Notes

How to wire the Agent Memory Refresh and State Reconciliation prompt into a reliable application harness with validation, retries, and safe state updates.

This prompt is not a standalone chat instruction—it is a state reconciliation module that must be integrated into an agent runtime's memory management loop. The harness is responsible for providing the prompt with a complete snapshot of the agent's stored state, the new observations that triggered the refresh, and a strict output schema. The prompt's job is to produce a reconciled state object with conflict flags and stale-data markers; the harness's job is to validate that output, decide whether to accept or retry, and safely apply the update to the agent's working memory. Without a disciplined harness, a malformed reconciliation output can corrupt the agent's state and cascade into downstream planning failures.

Wire this prompt into the agent's state refresh pipeline as a dedicated step that runs when the agent returns to a session after a gap, when new observations contradict stored beliefs, or when a configurable staleness threshold is exceeded. The harness should assemble the prompt inputs from two sources: the agent's current state store (serialized as structured JSON) and the fresh observation payload (from tool outputs, user input, or environment sensors). Include a [RECONCILIATION_TIMESTAMP] and [SESSION_ID] in the prompt context to anchor the output in time and enable audit trail correlation. After calling the model, validate the output against a strict schema that requires: a reconciled_state object, a conflicts array with field, stored_value, observed_value, and resolution entries, and a stale_fields array marking data that was not refreshed. Reject any output that is missing these sections or contains fields not present in the input schemas.

Implement a two-stage validation harness before the reconciled state is committed. First, run structural validation: check that the output is valid JSON, that all required keys are present, and that no hallucinated fields appear. Second, run semantic validation: verify that every conflict entry references real fields from the input state or observations, that resolutions are one of the allowed enum values (accept_observed, retain_stored, flag_for_review, merge), and that stale-field markers only reference fields that existed in the stored state but were absent from observations. If validation fails, retry the prompt once with the validation errors appended to the [CONSTRAINTS] section. If the second attempt also fails, log the failure, preserve the previous state unchanged, and escalate to a human reviewer or a fallback conservative merge strategy. For high-risk domains such as healthcare or finance, always require human approval before applying any reconciliation that includes flag_for_review conflicts or modifies fields marked as immutable in the state schema.

Choose a model with strong structured output capabilities and low latency for this prompt, as state reconciliation is often on the critical path for agent responsiveness. GPT-4o and Claude 3.5 Sonnet are good defaults; avoid smaller models that may drop conflict entries or hallucinate field names. Enable structured output mode or JSON mode with the reconciliation schema provided as a tool or response format. Set temperature=0 to maximize determinism—reconciliation should not be creative. Implement a timeout of 10–15 seconds with a fallback to a rule-based merge (e.g., observed values overwrite stored values for non-immutable fields) if the model call fails. Log every reconciliation attempt with the input state hash, observation hash, output state hash, validation result, and latency for observability and regression testing. This log becomes your golden dataset for evaluating prompt changes and detecting reconciliation drift over time.

IMPLEMENTATION TABLE

Expected Output Contract

Fields, types, and validation rules for the reconciled state object produced by the Agent Memory Refresh and State Reconciliation Prompt. Use this contract to parse, validate, and route the output before it updates the agent's active state.

Field or ElementType or FormatRequiredValidation Rule

reconciled_state

object

Top-level object must contain all keys present in [PRIOR_STATE] plus any new keys discovered in [FRESH_OBSERVATIONS]. Schema check: JSON parse must succeed.

reconciled_state.*.value

any

Each field must have a non-null value. If a field's value is unknown, use explicit string 'UNKNOWN' with confidence set to 0.0. Null check on every field.

reconciled_state.*.confidence

float 0.0-1.0

Must be a number between 0.0 and 1.0 inclusive. Fields sourced from [FRESH_OBSERVATIONS] with direct evidence should have confidence >= 0.8. Parse check: numeric, in range.

reconciled_state.*.source

enum string

Must be one of: 'prior_state', 'fresh_observation', 'inferred', 'user_confirmed'. Enum check: reject any value not in the allowed set.

conflicts

array of objects

Array must be present even if empty. Each conflict object requires 'field', 'prior_value', 'observed_value', 'resolution', and 'resolution_confidence' keys. Schema check: required keys present.

conflicts[].field

string

Must match a key path present in [PRIOR_STATE] or [FRESH_OBSERVATIONS]. Cross-reference check: reject references to non-existent fields.

conflicts[].resolution

enum string

Must be one of: 'use_observed', 'keep_prior', 'merge', 'escalate', 'unknown'. Enum check: reject any value not in the allowed set.

stale_fields

array of strings

Array of field key paths from [PRIOR_STATE] that were not confirmed by [FRESH_OBSERVATIONS] and are older than [STALENESS_THRESHOLD]. Each entry must be a valid key path in [PRIOR_STATE]. Cross-reference check.

PRACTICAL GUARDRAILS

Common Failure Modes

When agents reconcile stored memory with fresh observations, these failures surface first. Each card identifies a specific breakage pattern and the guardrail that prevents it in production.

01

Stale Memory Overrides Fresh Evidence

What to watch: The agent trusts its stored state more than new observations, ignoring contradictory sensor data or tool outputs. This happens when the prompt weights prior beliefs too heavily or when the reconciliation step is ordered before evidence collection. Guardrail: Structure the prompt to force evidence-first reasoning. Require the agent to list all new observations before accessing stored state, and flag any stored field that contradicts fresh evidence as STALE with a mandatory override.

02

Silent State Corruption on Partial Reconciliation

What to watch: The agent updates some state fields but not others after a tool failure or timeout, leaving the state object internally inconsistent. Downstream steps then operate on a mix of old and new data without knowing which fields are reliable. Guardrail: Require atomic state updates with an integrity hash. After any reconciliation attempt, run a state integrity validation prompt that checks cross-field consistency and marks any unreconciled fields with an UNVERIFIED flag and the timestamp of the last known-good value.

03

Conflict Resolution Bias Toward Recency

What to watch: When stored state and new evidence conflict, the agent defaults to trusting whichever is newer without evaluating which source is more reliable. A recent sensor error overwrites a correct stored value. Guardrail: Add a conflict resolution step that scores each source on reliability indicators: source type, measurement method, timestamp precision, and prior accuracy. Require the agent to output a conflict_record with both values, source scores, and an explicit resolution rationale before mutating state.

04

Missing Evidence Treated as Negative Evidence

What to watch: The agent interprets the absence of an expected observation as confirmation that a condition is false, rather than marking it as unknown. A tool that returns no results for a query is treated as proof that nothing exists. Guardrail: Distinguish three states explicitly in the prompt schema: CONFIRMED (evidence present), DISCONFIRMED (evidence explicitly contradicts), and UNOBSERVED (no evidence either way). Require the agent to justify any transition from UNOBSERVED to a conclusion.

05

Context Window Truncation Drops State Fields

What to watch: When the agent's context window is near capacity, the reconciliation prompt silently drops older state fields from the input, and the agent generates output that appears complete but is missing entire sections of prior state. Guardrail: Include a state field inventory at the top of the prompt listing every expected field with a checksum. After reconciliation, validate that every input field appears in the output or is explicitly marked as EVICTED with a reason. Reject outputs that silently drop fields.

06

Over-Correction on Transient Errors

What to watch: A single failed tool call or anomalous observation causes the agent to invalidate large portions of stored state, discarding accurate information because of one transient error. Guardrail: Require corroboration before state invalidation. A single contradictory observation should flag a field as DISPUTED rather than OVERWRITTEN. Only after multiple independent observations agree should the state be updated. Include a dispute_count and corroboration_threshold in the state schema.

IMPLEMENTATION TABLE

Evaluation Rubric

Use this rubric to evaluate the quality of the Agent Memory Refresh and State Reconciliation output before integrating it into your agent runtime. Each criterion targets a specific failure mode common in state reconciliation workflows.

CriterionPass StandardFailure SignalTest Method

Conflict Detection Completeness

All contradictions between [STORED_STATE] and [FRESH_OBSERVATIONS] are flagged with a conflict type and source reference

A known contradiction present in the test fixture is missing from the output's conflict list

Diff the output's conflict list against a pre-annotated ground-truth set of injected contradictions; recall must be >= 0.95

Stale-Data Marker Accuracy

Every field in [STORED_STATE] that is superseded by [FRESH_OBSERVATIONS] is marked stale; no field still valid per observations is marked stale

A stale field is missing the stale marker, or a current field is incorrectly flagged as stale

Compare stale markers against a ground-truth mask; precision and recall must both be >= 0.90

Reconciled State Internal Consistency

The reconciled state contains no contradictory field pairs (e.g., status=complete and status=pending for the same entity)

Two fields in the reconciled state assert mutually exclusive values for the same entity attribute

Run a schema-aware consistency checker across the reconciled state; zero hard contradictions permitted

Uncertainty Flagging for Unresolved Conflicts

Every conflict that cannot be automatically resolved is accompanied by an uncertainty marker and a recommended resolution action

An unresolved conflict appears in the output without an uncertainty marker or resolution hint

Assert that the count of unresolved conflicts equals the count of uncertainty markers in the output

Evidence Provenance Preservation

Every updated field in the reconciled state retains or adds a source pointer to the originating observation or stored record

A field value changes but its source reference is null, missing, or points to an unrelated observation

Validate that every modified field has a non-null source field matching an ID in [FRESH_OBSERVATIONS] or [STORED_STATE]

No Silent Data Loss

All fields present in [STORED_STATE] that are not contradicted or superseded are preserved in the reconciled state

A field from [STORED_STATE] disappears from the reconciled state without being marked stale or conflicted

Compute the set difference between [STORED_STATE] top-level keys and reconciled state keys; unaccounted removals must be zero

Conflict Resolution Rationale Quality

Each auto-resolved conflict includes a concise, evidence-grounded rationale explaining why one source was preferred

A resolved conflict has an empty, generic, or circular rationale (e.g., 'chose newer value' without timestamp evidence)

Spot-check a sample of resolution rationales against the source evidence; a human reviewer confirms >= 85% are specific and evidence-grounded

Output Schema Conformance

The output strictly matches the [OUTPUT_SCHEMA] with all required fields present and no extra top-level keys

Schema validation fails due to missing required fields, type mismatches, or unexpected properties

Validate the output JSON against the [OUTPUT_SCHEMA] using a strict schema validator; must pass with zero errors

ADAPTATION OPTIONS

Adapt This Prompt

How to adapt

Start with the base prompt and a simple JSON schema for the reconciled state. Use a single-turn call with the stored state and new observations concatenated. Skip conflict resolution logic initially—just flag mismatches without attempting automatic resolution.

code
[STORED_STATE]
[NEW_OBSERVATIONS]

Reconcile these. Return JSON with:
- updated_state: merged view
- conflicts: list of mismatches found
- stale_fields: fields from stored_state not confirmed by new observations

Watch for

  • The model silently favoring new observations over stored state without justification
  • Missing stale_fields when observations are incomplete
  • Overwriting stored state fields that weren't addressed by new observations at all
Prasad Kumkar

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.