agent.db Context
Public inspection and debugging API attached to agents created by Agent.from_db().
#Overview
Every from_db() agent receives an agent.db context object:
python
agent = await Agent.from_db("postgresql://user:pass@host/db")
print(agent.db.schema)
print(agent.db.mode)
print(agent.db.summary)Use this instead of reading private implementation attributes.
#Properties
| Property | Description |
|---|---|
agent.db.schema | Discovered normalized schema |
agent.db.plugin | Underlying database plugin |
agent.db.mode | Selected from_db mode |
agent.db.drift | Schema drift metadata, when detected |
agent.db.memory | Memory plugin when memory is enabled |
agent.db.memory_semantics | DB semantic memory adapter when memory is enabled |
agent.db.lineage | Lineage plugin when lineage is enabled |
agent.db.history | Conversation history when history is enabled |
agent.db.quality | DataQuality plugin when quality is enabled |
agent.db.summary | Compact database summary |
agent.db.suggested_questions | Suggested starter questions |
agent.db.monitor_events | Local monitor event records |
#Audit
python
await agent.run("Count orders by status")
print(agent.db.audit.entries)
print(agent.db.audit.last())
print(agent.db.audit.export_json(indent=2))Audit entries are redacted and intended for debugging and observability.
#Findings
python
print(agent.db.findings.all)
print(agent.db.findings.open)
print(agent.db.findings.resolved)
print(agent.db.findings.last())You can also add a finding from application code:
python
agent.db.findings.add({
"title": "Orders table has stale data",
"severity": "warning",
"status": "open",
"kind": "db_observation",
"source": {"type": "manual"},
"entity": {"table": "orders"},
"observed": {"max_updated_at": "2026-05-15T00:00:00Z"},
})#Register Monitors
python
agent.db.register_monitors([
{
"name": "Orders freshness",
"type": "freshness",
"severity": "warning",
"entity": {"table": "orders"},
"sql": "SELECT MAX(updated_at) FROM orders",
"threshold": {"max_age_hours": 24},
}
])See Monitors & Findings for monitor details.
#describe()
from_db() agents also expose a DB-focused describe() method:
python
metadata = agent.describe()
print(metadata["kind"])
print(metadata["capabilities"])
print(metadata["db"]["query_policy"])The response is compact and side-effect free. It is useful for logging, dashboards, and debugging.
#Stable vs Debug Fields
Prefer:
agent.db.*agent.describe()agent.tool_registry.tool_names
Avoid relying on private implementation attributes in application code. They may change as the runtime evolves.