Daita Logo

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

python
agent = await Agent.from_db(
    "postgresql://user:pass@host/db",
    memory=True,
)

You can also pass an existing Memory plugin:

python
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_convention
  • metric_definition
  • business_rule
  • data_contract_note
  • schema_interpretation

#Example

python
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:

python
{
    "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:

text
orders.refunded_at marks orders that should be excluded from revenue.

Bad memory:

text
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:

python
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

python
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().