from_db Memory
Use DB semantic memory with Agent.from_db() to store metric definitions, business rules, unit conventions, data contracts, and schema interpretations.
#Enable Memory
agent = await Agent.from_db(
"postgresql://user:pass@host/db",
memory=True,
)You can also pass an existing Memory plugin:
from daita.plugins import memory
mem = memory(workspace="analytics")
agent = await Agent.from_db(
"postgresql://user:pass@host/db",
memory=mem,
)#DB Semantic Memory
from_db() uses DB-specific memory semantics. Instead of generic memory writes, agents use db_remember for durable database context.
Supported memory kinds:
unit_conventionmetric_definitionbusiness_ruledata_contract_noteschema_interpretation
#Example
agent = await Agent.from_db(
"postgresql://user:pass@host/db",
memory=True,
)
await agent.run("""
Remember that revenue is gross_order_total_cents / 100,
excluding refunded orders.
""")The agent can store that as DB semantic memory and recall it during later runs.
#Direct Tool Shape
The agent-facing db_remember tool accepts:
{
"kind": "metric_definition",
"key": "metric:revenue",
"text": "Revenue excludes refunded orders and is reported in USD.",
"metadata": {"table": "orders"},
"importance": 0.8,
}Applications usually let the agent call the tool autonomously rather than invoking it directly.
#PII Protection
DB memory rejects obvious PII values and sensitive metadata keys. It is intended for schema-level and business-level facts, not row values.
Good memory:
orders.refunded_at marks orders that should be excluded from revenue.Bad memory:
VIP customer email is jane@example.com.#Calibration
Use calibrate_memory=True to ask the agent to infer numeric unit conventions during setup and store them in DB memory:
agent = await Agent.from_db(
"postgresql://user:pass@host/db",
memory=True,
calibrate_memory=True,
)Calibration is optional because it may perform extra LLM work during construction.
#Inspect Memory
print(agent.db.memory)
print(agent.db.memory_semantics)agent.db.memory is the underlying Memory plugin. agent.db.memory_semantics is the DB-specific adapter used by from_db().