Agents Example | OpenMemory
Learn how to build autonomous agents with long-term memory using OpenMemory.
Building Agents with Memory
Agents need memory to be truly autonomous. Without it, they are just loops.
The Loop
A memory-enabled agent loop looks like this:
- Observe: Receive input from environment.
- Recall: Query OpenMemory for relevant past experiences.
- Plan: Use LLM to decide action, conditioned on memory.
- Act: Execute tool or API call.
- Reflect: Store the result and the reasoning back into OpenMemory.
Code Snippet
async function agentLoop(input: string) {
const context = await mem.query(input);
const plan = await llm.plan(input, context);
const result = await tools.execute(plan);
await mem.add(`Action: ${plan}, Result: ${result}`);
}