cd /news/ai-agents/i-used-hindsight-to-remember-human-i… · home › topics › ai-agents › article
[ARTICLE · art-141293] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

I Used Hindsight to Remember Human Invoice Decisions

A developer built VendorSense, an accounts-payable agent that combines PDF invoice extraction, Groq-based LLM reasoning, and a Hindsight memory layer so that prior human approval and rejection decisions inform future invoice evaluations. The system recalls vendor-specific history — amount patterns, payment terms, purchase-order formats, bank details, and past exceptions — and injects it into the model prompt before a decision, then retains confirmed human outcomes as new memories. Invoices are routed to AUTO_PROCESS or an exception path, with bank-detail changes always requiring human review.

by read7 min views1 publishedSep 28, 2026

The first useful question I asked about invoice automation was not “Can the model read an invoice?” It was “What happens when the same vendor sends its fiftieth invoice?”

Reading one invoice is straightforward. The harder problem is context. A human reviewer remembers that a vendor normally uses a particular purchase-order format, stays within a familiar amount range, keeps the same payment terms, and has had previous invoices approved after specific checks. A stateless model has to rediscover that context every time.

I built VendorSense around that gap. It is an Accounts Payable agent that combines invoice extraction, Hindsight memory, and LLM reasoning so previous human decisions can influence future invoice evaluations.

The system I built

VendorSense follows a deliberately narrow workflow:

Invoice

↓

Extract invoice details

↓

Hindsight Recall

↓

Groq reasoning

↓

AUTO-PROCESS or EXCEPTION

↓

Human confirmation when required

↓

Hindsight Retain

↓

Future invoices use that experience

The application is built with Python and Streamlit. PDF invoices are parsed with pypdf, Groq handles reasoning, and Hindsight provides the memory layer.

The interface exposes invoice intake, an agent pipeline, processing metrics, an exception view, and a dedicated Vendor Memory view. I wanted the memory loop to be visible instead of hiding it behind an API call.

Figure 1 — The VendorSense dashboard makes the invoice pipeline and learning activity visible.

AUTO_PROCESS represents simulated Accounts Payable routing; the system does not execute a real payment.

The application also records the processed invoice and keeps the uploaded file in its archive, separate from learned Hindsight experience.

Why I put Hindsight before reasoning

The most important architectural decision was the ordering of operations.

I did not want the agent to analyze an invoice and then optionally look up history. I wanted history to become part of the model's input before the decision was made.

For each invoice, VendorSense constructs a query from the current vendor and invoice context. It asks Hindsight to retrieve previous approvals, rejections, amount patterns, payment terms, purchase-order patterns, verified bank information, previous exceptions, human decisions, and learned vendor behavior. The recall call is:

result = hindsight.recall(

    bank_id=BANK_ID,

    query=query,

    max_tokens=2500,

    budget="mid",

)

I then place the returned memories alongside the current invoice:

user_prompt = f"""

CURRENT INVOICE:

{json.dumps(invoice, indent=2)} HINDSIGHT MEMORY:

{memory_text} Evaluate this invoice.

"""

This creates a useful separation:

Current invoice

Hindsight memory

What is happening now

What happened before

Amount, PO, terms, bank details

Previous decisions and vendor patterns

Current evidence

Historical context

That separation is what makes Hindsight useful here. The model is no longer forced to treat every invoice as a clean slate.

Figure 2 — VendorSense keeps the processed invoice as part of the application's invoice workflow and archive.

Memory is evidence, not truth

The next problem was more subtle.

If I give a model historical context, it is tempting to treat that context as authoritative. I decided not to. The reasoning instructions in VendorSense explicitly establish:

Hindsight memory is evidence, not absolute truth.

The same instructions tell the agent to behave conservatively when there is little relevant experience, recognize familiar vendor patterns when the evidence supports them, route meaningful deviations to an exception path, and require review when bank details change.

The important part: humans create the learning signal

A model recommendation should not automatically become a fact about the vendor.

VendorSense therefore learns from confirmed human outcomes.

When an invoice is routed for review, the reviewer can approve or reject it and add a note. The application turns that outcome into an explicit learning event:

experience = f"""

VendorSense AP learning event.

Vendor: {invoice.get('vendor')}

Invoice ID: {invoice.get('invoice_id')}

Amount: ₹{invoice.get('amount')}

Purchase Order: {invoice.get('purchase_order')}

Payment Terms: {invoice.get('payment_terms')}

Bank ending: {invoice.get('bank_account_last4')}

Human decision: {decision}

Human review note:

{reason} This is a human-confirmed AP experience.

Use this experience when evaluating future invoices

from this vendor.

"""

Then the learning event is retained in Hindsight:

hindsight.retain(

    bank_id=BANK_ID,

    content=experience,

)

Figure 3 — The Recall and Retain implementation that connects VendorSense to Hindsight memory.

The learning loop is therefore:

Agent recommendation

    ↓

Human confirmation

    ↓

Confirmed experience

    ↓

Hindsight Retain

    ↓

Future Hindsight Recall

I prefer this to letting the model learn from its own outputs. Recommendations do not become trusted vendor knowledge until a human has confirmed the outcome.

The before-and-after moment The easiest way to see the value of memory is to process two invoices from the same vendor.

Imagine an invoice from Apex Industrial Supplies arriving for the first time. VendorSense can extract the vendor, amount, purchase order, payment terms, and bank information, but it has little vendor-specific history to work with.

The safe response is to evaluate the invoice conservatively and bring a human into the loop.

The human confirms the outcome.

VendorSense retains that experience.

Now another Apex invoice arrives.

The invoice is not evaluated in isolation anymore. Hindsight can return the previous experience, including the prior human decision and recurring vendor patterns. The reasoning layer can use that context to distinguish a routine invoice from something that deserves attention.

The behavioral change can be summarized simply:

First interaction

Later interaction

Little vendor-specific context

Relevant vendor experience is available

Conservative evaluation

Historical context informs the evaluation

Human decision creates learning data

Previous learning is recalled

Agent starts with little experience

Agent can use accumulated experience

Learning should not make the agent careless

There is an equally important counterexample.

Suppose Apex becomes a familiar vendor. Previous invoices match expected patterns. Several have been confirmed by humans.

Then the bank details change.

A memory-powered workflow that blindly trusted its history could reason:

“I know this vendor, so this is probably fine.”

VendorSense is designed not to do that.

The model output includes a bank_change_detected flag, and the application enforces the exception path:

result = json.loads(content)

if result.get("bank_change_detected") is True:

    result["decision"] = "EXCEPTION"

return result

That gives the system a useful rule:

A strong historical pattern should improve recognition of normal behavior, not erase sensitivity to meaningful change.

Familiarity is not permanent permission.

Figure 4 — The human-review view makes the evidence and review decision visible before a confirmed outcome becomes learning data.

Making the memory layer inspectable

Another practical lesson was that memory should not feel magical.

The invoice workflow shows the current invoice, retrieved Hindsight memory, the agent decision, confidence, reason, evidence, and the human review/learning action.

A dedicated Vendor Memory view makes the same lifecycle easier to inspect.

That gives the user a traceable sequence instead of a black box:

Current invoice

 ↓

Memory retrieved

 ↓

Reasoning

 ↓

Recommendation

 ↓

Human confirmation

 ↓

Memory updated

What I learned building it

Calling a memory system and displaying old records is easy. The value appears when those memories enter the reasoning step and alter what the agent can conclude.

I do not want the agent to teach itself that its own previous recommendation was correct. A confirmed outcome is a clearer learning signal.

Hindsight gives the agent context, but the reasoning layer still has to evaluate whether that context applies to the current event. “This happened before” is not the same thing as “this is safe now.”

The bank-account change path is deliberately enforced rather than left entirely to model interpretation. Some conditions should be obvious in application logic.

VendorSense focuses on one workflow: evaluating invoices in the context of vendor history. That narrow scope makes the entire loop easier to trace from recall to reasoning to human confirmation to retention.

Where Hindsight fits

Hindsight is not an add-on to VendorSense. It is the component that changes the information available to the reasoning layer.

Without memory, the agent can still extract an invoice and produce a recommendation.

With Hindsight agent memory, the agent can retrieve previous vendor experiences and use confirmed human decisions as context for future evaluations.

The implementation uses the Hindsight GitHub repository and Hindsight documentation as the memory layer around that loop.

The rest of the application handles invoice intake, authentication, interface state, and operational records. Keeping those concerns separate makes the architecture easier to reason about and leaves room to move application persistence to durable infrastructure without changing the memory contract.

The pattern I would reuse

The most reusable part of VendorSense is not the invoice parser or the dashboard.

It is the learning loop:

Recall the past.

Reason about the present.

Ask a human when the evidence is insufficient.

Retain the confirmed outcome.

Use it the next time.

── more in #ai-agents 4 stories · sorted by recency
── more on @vendorsense 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/i-used-hindsight-to-…] indexed:0 read:7min 2026-09-28 · —