Daita Logo

from_db Configuration

Public Agent.from_db() parameters for database connection, LLM configuration, schema discovery, query guardrails, prompt budgets, and optional integrations.

#Signature

python
await Agent.from_db(
    source,
    *,
    name=None,
    model=None,
    api_key=None,
    llm_provider=None,
    prompt=None,
    db_schema=None,
    mode="analyst",
    include_sample_values=None,
    redact_pii_columns=True,
    lineage=None,
    memory=None,
    calibrate_memory=None,
    history=None,
    cache_ttl=None,
    read_only=None,
    query_default_limit=None,
    query_max_rows=None,
    query_max_chars=None,
    query_timeout=None,
    allowed_tables=None,
    blocked_tables=None,
    blocked_columns=None,
    toolkit="auto",
    quality=None,
    budget="retrieval",
    schema_prompt_policy=None,
    tool_result_policy=None,
    **agent_kwargs,
)

#Core Parameters

  • source (str | BaseDatabasePlugin): Connection string or database plugin instance. Required.
  • name (str): Agent name. Defaults to an inferred database-domain name.
  • prompt (str): Domain context prepended to the generated database prompt.
  • mode (str): Behavior preset. One of simple, analyst, governed, or data_team.
  • agent_kwargs: Additional keyword arguments forwarded to Agent.__init__, such as temperature, display_reasoning, or relay configuration.

from_db() sets temperature=0 by default unless you pass a different value.

#LLM Configuration

  • model (str): Model override.
  • api_key (str): Provider API key override.
  • llm_provider (str): LLM provider override.
python
agent = await Agent.from_db(
    "postgresql://user:pass@host/db",
    llm_provider="openai",
    model="gpt-5.4-mini",
)

#Schema Discovery

  • db_schema (str): Target DB schema, such as public for PostgreSQL.
  • include_sample_values (bool): Include numeric sample values. Defaults to the selected mode.
  • redact_pii_columns (bool): Skip sampling columns whose names look sensitive.
  • cache_ttl (int | None): Schema cache TTL in seconds. None disables TTL-based cache writes but can still reuse an existing schema snapshot or catalog snapshot when one is available.
python
agent = await Agent.from_db(
    "postgresql://user:pass@host/db",
    db_schema="analytics",
    cache_ttl=3600,
)

#Query Guardrails

  • read_only (bool): Omit write tools and reject mutating SQL. Defaults to the selected mode, usually True.
  • query_default_limit (int): LIMIT applied when SQL omits one.
  • query_max_rows (int): Maximum rows returned from DB query tools.
  • query_max_chars (int): Maximum serialized result size.
  • query_timeout (float): Timeout in seconds for DB tool execution.
  • allowed_tables (List[str]): Only allow queries against these tables.
  • blocked_tables (List[str]): Reject queries against these tables.
  • blocked_columns (List[str]): Reject queries that reference these columns.
python
agent = await Agent.from_db(
    "postgresql://user:pass@host/db",
    read_only=True,
    query_default_limit=25,
    query_max_rows=100,
    query_timeout=30,
    allowed_tables=["orders", "customers", "products"],
    blocked_columns=["email", "phone", "address"],
)

#Tooling

  • toolkit ("auto" | "analyst" | "all" | None): Register analyst tools. "auto" uses the selected mode.
  • quality (bool): Register data-quality tools. Defaults to the selected mode.
python
agent = await Agent.from_db(
    "postgresql://user:pass@host/db",
    toolkit="analyst",
    quality=True,
)

#Optional Integrations

  • lineage (bool | LineagePlugin): Enable FK lineage registration.
  • memory (bool | MemoryPlugin): Enable DB semantic memory and db_remember.
  • calibrate_memory (bool): Run optional numeric unit calibration when memory is enabled.
  • history (bool | ConversationHistory): Enable conversational follow-up context.
python
from daita import ConversationHistory
 
history = ConversationHistory(max_turns=8)
 
agent = await Agent.from_db(
    "postgresql://user:pass@host/db",
    mode="governed",
    memory=True,
    history=history,
    lineage=True,
)

#Prompt and Result Policies

Advanced users can import public policy classes from daita.agents.db.config:

python
from daita.agents.db.config import SchemaPromptPolicy, ToolResultPolicy
 
agent = await Agent.from_db(
    "postgresql://user:pass@host/db",
    schema_prompt_policy=SchemaPromptPolicy(
        max_inline_schema_tokens=1800,
        max_inline_tables=8,
        max_inline_columns=80,
        preferred_strategy="compact",
    ),
    tool_result_policy=ToolResultPolicy(
        max_result_tokens=900,
        max_rows_inline=10,
        max_cell_chars=180,
    ),
)

Most applications should start with the simpler budget presets: auto, full, compact, or retrieval.

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