Factory¶
deep_db_agents.factory ¶
Factory functions: the entry points of the library.
Exposes create_deep_db_agents, create_db_agents and create_deep_db_multi_agents,
which turn a database URL into a ready-to-use LangChain / Deep Agent.
create_db_agents ¶
create_db_agents(db_url: str, credential: dict[str, Any] | None = None, system: str = '', *, guardrails: GuardrailConfig | None = None, metrics: SessionMetrics | None = None, **kwargs: Any)
Create a plain LangChain Agent specialized on the database pointed to by db_url.
Unlike :func:create_deep_db_agents, the file-materialization tools (materialize_*)
are not exposed: they require the deepagents filesystem backend, which the plain agent
does not have.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_url
|
str
|
Database URL in the form |
required |
credential
|
dict[str, Any] | None
|
Access credentials; the expected keys depend on the target database
(e.g. |
None
|
system
|
str
|
Database-specific system prompt, appended to the dialect's generic prompt. |
''
|
guardrails
|
GuardrailConfig | None
|
Safety thresholds for the tools (max LIMIT, timeout, EXPLAIN threshold,
row budget). Defaults to |
None
|
metrics
|
SessionMetrics | None
|
Optional |
None
|
**kwargs
|
Any
|
Forwarded as-is to |
{}
|
Returns:
| Type | Description |
|---|---|
|
The compiled agent, with an |
|
|
interface. Also supports |
|
|
thread pool). |
Example
from deep_db_agents import create_db_agents
agent = create_db_agents(
"sqlite:///./data/app.db",
system="Answer briefly, cite the exact table and column names.",
)
result = agent.invoke({"messages": [{"role": "user", "content": "List all tables."}]})
Source code in src/deep_db_agents/factory.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
create_deep_db_agents ¶
create_deep_db_agents(db_url: str, credential: dict[str, Any] | None = None, system: str = '', *, guardrails: GuardrailConfig | None = None, enable_code_interpreter: bool = False, metrics: SessionMetrics | None = None, **kwargs: Any)
Create a Deep Agent specialized on the database pointed to by db_url.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_url
|
str
|
Database URL in the form |
required |
credential
|
dict[str, Any] | None
|
Access credentials; the expected keys depend on the target database
(e.g. |
None
|
system
|
str
|
Database-specific system prompt, appended to the dialect's generic prompt. |
''
|
guardrails
|
GuardrailConfig | None
|
Safety thresholds for the tools (max LIMIT, timeout, EXPLAIN threshold,
row budget). Defaults to |
None
|
enable_code_interpreter
|
bool
|
If |
False
|
metrics
|
SessionMetrics | None
|
Optional |
None
|
**kwargs
|
Any
|
Forwarded as-is to |
{}
|
Returns:
| Type | Description |
|---|---|
|
The compiled agent, with an |
|
|
interface. Also supports |
|
|
under |
|
|
calls concurrently (see |
Example
from deep_db_agents import create_deep_db_agents
agent = create_deep_db_agents(
"postgres://localhost:5432/mydb",
credential={"user": "reader", "password": "secret"},
system="Focus on the `orders` and `customers` tables.",
)
result = agent.invoke(
{"messages": [{"role": "user", "content": "How many orders last week?"}]}
)
Source code in src/deep_db_agents/factory.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
create_deep_db_multi_agents ¶
create_deep_db_multi_agents(db_agents: Mapping[str, Mapping[str, Any]], system: str = '', **kwargs: Any)
Create a Deep Agent orchestrator that coordinates multiple deep_db_agents.
The orchestrator never queries a database directly: it delegates each sub-question to
the sub-agent specialized on the relevant database (exposed through the task tool)
and combines the results. This enables answering questions that span multiple databases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_agents
|
Mapping[str, Mapping[str, Any]]
|
Mapping of |
required |
system
|
str
|
Extra system prompt, appended to the orchestrator's generic prompt and the sub-agent roster, to provide additional context (domain, join rules, ...). |
''
|
**kwargs
|
Any
|
Forwarded as-is to |
{}
|
Returns:
| Type | Description |
|---|---|
|
The compiled orchestrator agent, with an |
|
|
interface. |
Raises:
| Type | Description |
|---|---|
InvalidMultiAgentConfigError
|
If |
Example
from deep_db_agents import create_deep_db_agents, create_deep_db_multi_agents
orders_agent = create_deep_db_agents("postgres://localhost:5432/orders")
events_agent = create_deep_db_agents("mongodb://localhost:27017/events")
orchestrator = create_deep_db_multi_agents(
{
"orders": {
"description": "Orders and customers (Postgres)",
"agent": orders_agent,
},
"events": {"description": "Raw event log (MongoDB)", "agent": events_agent},
}
)
query = "Compare orders vs. events last week."
result = orchestrator.invoke({"messages": [{"role": "user", "content": query}]})
Source code in src/deep_db_agents/factory.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |