Skip to Content
DocsRecipesCustomer-support bot

Customer-support bot with persistent facts

The bot remembers what each customer told it, even across process restarts. Facts (user X says they live in Tokyo, account Y is on the enterprise plan) get extracted automatically after every conversation.

import asyncio from loomflow import Agent from loomflow.runtime import SqliteRuntime async def main(): # Postgres URL → resolver builds PostgresMemory + pgvector # facts table on first agent.run. Schema migrations are # idempotent; nothing to remember. agent = Agent( instructions=( "You are a customer-support agent for Acme. " "Use any known facts about the user to personalize replies. " "Cite the fact's source when you rely on it." ), model="claude-opus-4-7", memory="postgres://localhost/support_bot", runtime=SqliteRuntime("./support_journal.db"), # auto_extract=True is the default — every run auto-pulls # structured facts from the conversation into the bi-temporal # store, partitioned by user_id. ) while True: prompt = input("User> ") if not prompt: break # In a real bot, ``user_id`` comes from your auth layer. result = await agent.run(prompt, user_id="user_42") print(f"Bot> {result.output}") asyncio.run(main())

The first time a user mentions their plan tier, the consolidator extracts a fact like ("user", "subscription_plan", "enterprise"). Later runs see it in the Known facts: section of the system message and tailor responses without asking again. Plan changes? Supersession closes off the old fact’s validity window automatically. Historical queries still work.

Last updated on