runAgentStep(runId)
→ buildAgentContext(runId)
→ retrieve top relevant workflow memories
→ add relevantMemories to agent context
→ agent/prompt may use memory only for routing
→ guardrails block unsafe memory use
→ MemoryHit.usedByAgent = true once memory enters agent decision path

Agent Memory Integration

Goal

Day 5 connected workflow memory to the ClaimFlow agent.

The goal was not to let memory decide claims. The goal was:

retrieve relevant workflow memory
→ add it to agent context
→ let the agent use it for routing/reviewer verification
→ block unsafe memory-based approval, denial, or field overwrite

Memory is context. Current claim data, current policy evidence, and human review remain source of truth.


1. Relevant memories added into agent context

buildAgentContext(runId) was updated to retrieve memories before returning the final agent context.

The retrieval uses the current claim state:

runId
extractedJson
effective validationJson
missingFields
requiredEvidence
reviewTaskStatus
retrievalStatus
policyDecision

Then it calls:

retrieveRelevantMemories({
  runId,
  claimState,
  writeHits: true,
  limit: 5,
});

The result is added into agent context as:

relevantMemories
workflowMemoryContext

So the agent now sees:

current claim state
+ review state
+ policy retrieval state
+ previous agent actions
+ relevant workflow memories

Each memory includes: