apx-agent 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- apx_agent/__init__.py +556 -0
- apx_agent/_agent_tool.py +92 -0
- apx_agent/_agents.py +793 -0
- apx_agent/_audit.py +223 -0
- apx_agent/_callbacks.py +303 -0
- apx_agent/_canary.py +541 -0
- apx_agent/_canary_apps.py +707 -0
- apx_agent/_chat_agent.py +640 -0
- apx_agent/_compile.py +784 -0
- apx_agent/_compile_run.py +252 -0
- apx_agent/_cost.py +208 -0
- apx_agent/_defaults.py +269 -0
- apx_agent/_dev.py +2308 -0
- apx_agent/_discovery.py +10 -0
- apx_agent/_doctor.py +355 -0
- apx_agent/_embeddings.py +80 -0
- apx_agent/_eval.py +474 -0
- apx_agent/_eval_chain.py +379 -0
- apx_agent/_example.py +367 -0
- apx_agent/_example_delta.py +468 -0
- apx_agent/_example_lakebase.py +437 -0
- apx_agent/_example_mining.py +309 -0
- apx_agent/_example_tools.py +219 -0
- apx_agent/_guards.py +437 -0
- apx_agent/_hot_swap.py +168 -0
- apx_agent/_hot_swap_apps.py +142 -0
- apx_agent/_inspection.py +200 -0
- apx_agent/_invocations.py +189 -0
- apx_agent/_lakebase_engine.py +72 -0
- apx_agent/_lint.py +230 -0
- apx_agent/_llm.py +153 -0
- apx_agent/_managed_mcp.py +227 -0
- apx_agent/_mcp.py +81 -0
- apx_agent/_memory.py +476 -0
- apx_agent/_memory_consolidate.py +182 -0
- apx_agent/_memory_delta.py +632 -0
- apx_agent/_memory_lakebase.py +534 -0
- apx_agent/_memory_tools.py +311 -0
- apx_agent/_memory_wiring.py +438 -0
- apx_agent/_mlflow_tracing.py +266 -0
- apx_agent/_models.py +331 -0
- apx_agent/_obo.py +308 -0
- apx_agent/_prompt_assembly.py +218 -0
- apx_agent/_publish.py +180 -0
- apx_agent/_readyz.py +193 -0
- apx_agent/_remote.py +480 -0
- apx_agent/_resources.py +594 -0
- apx_agent/_responses_agent.py +839 -0
- apx_agent/_run_once.py +115 -0
- apx_agent/_schema.py +202 -0
- apx_agent/_session.py +195 -0
- apx_agent/_session_delta.py +197 -0
- apx_agent/_session_lakebase.py +220 -0
- apx_agent/_sql.py +190 -0
- apx_agent/_static/topology/assets/index-DMgQ9RNB.css +1 -0
- apx_agent/_static/topology/assets/index-DQAJccQT.js +62 -0
- apx_agent/_static/topology/index.html +13 -0
- apx_agent/_static/vendor/marked.min.js +6 -0
- apx_agent/_static/vendor/purify.min.js +3 -0
- apx_agent/_template.py +130 -0
- apx_agent/_tool.py +232 -0
- apx_agent/_tool_config.py +260 -0
- apx_agent/_tool_factory.py +87 -0
- apx_agent/_tool_publish.py +236 -0
- apx_agent/_topology.py +736 -0
- apx_agent/_trace_export.py +336 -0
- apx_agent/_trace_store.py +214 -0
- apx_agent/_ui_chat.py +1837 -0
- apx_agent/_ui_edit.py +1524 -0
- apx_agent/_ui_nav.py +319 -0
- apx_agent/_ui_probe.py +1148 -0
- apx_agent/_ui_setup.py +1648 -0
- apx_agent/_watchdog.py +891 -0
- apx_agent/_wiring.py +881 -0
- apx_agent/bootstrap.py +149 -0
- apx_agent/catalog.py +403 -0
- apx_agent/cli.py +6003 -0
- apx_agent/coworker.py +108 -0
- apx_agent/data_agent.py +218 -0
- apx_agent/foundation_model.py +109 -0
- apx_agent/genie.py +195 -0
- apx_agent/http_tools.py +271 -0
- apx_agent/jobs_tools.py +331 -0
- apx_agent/mcp_consume.py +290 -0
- apx_agent/py.typed +0 -0
- apx_agent/sql_tools.py +104 -0
- apx_agent/vector_search.py +91 -0
- apx_agent/workflow/__init__.py +61 -0
- apx_agent/workflow/cli.py +319 -0
- apx_agent/workflow/engine.py +137 -0
- apx_agent/workflow/engine_delta.py +380 -0
- apx_agent/workflow/engine_memory.py +178 -0
- apx_agent/workflow/loop_agent.py +649 -0
- apx_agent/workflow/population_store.py +461 -0
- apx_agent-0.3.0.dist-info/METADATA +302 -0
- apx_agent-0.3.0.dist-info/RECORD +98 -0
- apx_agent-0.3.0.dist-info/WHEEL +4 -0
- apx_agent-0.3.0.dist-info/entry_points.txt +6 -0
apx_agent/__init__.py
ADDED
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
"""apx-agent — declarative agent DSL that compiles to LangGraph + MLflow."""
|
|
2
|
+
|
|
3
|
+
# Agent types
|
|
4
|
+
from ._agents import (
|
|
5
|
+
BaseAgent,
|
|
6
|
+
HandoffAgent,
|
|
7
|
+
KeywordRouter,
|
|
8
|
+
LlmAgent,
|
|
9
|
+
LoopAgent,
|
|
10
|
+
ParallelAgent,
|
|
11
|
+
RouterAgent,
|
|
12
|
+
SequentialAgent,
|
|
13
|
+
)
|
|
14
|
+
from ._remote import RemoteDatabricksAgent
|
|
15
|
+
|
|
16
|
+
# Canonical short name — Agent is the DSL-facing alias for LlmAgent
|
|
17
|
+
Agent = LlmAgent
|
|
18
|
+
|
|
19
|
+
# Agent-as-tool composition primitive
|
|
20
|
+
from ._agent_tool import agent_tool
|
|
21
|
+
|
|
22
|
+
# DataAgent — LlmAgent specialized for governed UC data access
|
|
23
|
+
from .data_agent import DataAgent, DataTemplate
|
|
24
|
+
from .coworker import CoworkerAgent, CoworkerTemplate
|
|
25
|
+
|
|
26
|
+
# Template protocol, registry, and decorator
|
|
27
|
+
from ._template import Template, TemplateInfo, TemplateRegistry, template, template_registry
|
|
28
|
+
|
|
29
|
+
# Models
|
|
30
|
+
from ._models import (
|
|
31
|
+
AfterModelHook,
|
|
32
|
+
AfterToolHook,
|
|
33
|
+
AgentCard,
|
|
34
|
+
AgentConfig,
|
|
35
|
+
AgentContext,
|
|
36
|
+
AgentTool,
|
|
37
|
+
BeforeModelHook,
|
|
38
|
+
BeforeToolHook,
|
|
39
|
+
ExampleBackendConfig,
|
|
40
|
+
GuardrailsConfig,
|
|
41
|
+
InputGuardrailFn,
|
|
42
|
+
MemoryBackendConfig,
|
|
43
|
+
Message,
|
|
44
|
+
OutputGuardrailFn,
|
|
45
|
+
SessionBackendConfig,
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
# FastAPI dependency injection
|
|
49
|
+
from ._defaults import Dependencies
|
|
50
|
+
|
|
51
|
+
# SQL utilities
|
|
52
|
+
from ._sql import decode_statement, get_warehouse_id, run_sql
|
|
53
|
+
|
|
54
|
+
# Provider compatibility layer — get_llm() factory + named subclasses
|
|
55
|
+
from ._llm import ChatDatabricksGptReasoning, get_llm
|
|
56
|
+
|
|
57
|
+
# App factory and setup
|
|
58
|
+
from ._wiring import create_app, finalize_agent, mount_mcp_endpoints, setup_agent
|
|
59
|
+
from ._readyz import mount_readyz
|
|
60
|
+
from ._tool_config import ToolConfigError, load_config_tools, merge_config_tools
|
|
61
|
+
|
|
62
|
+
# Eval bridge
|
|
63
|
+
from ._eval import (
|
|
64
|
+
app_predict_fn,
|
|
65
|
+
endpoint_predict_fn,
|
|
66
|
+
eval_against_endpoint,
|
|
67
|
+
evaluate,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
# Genie tool factories
|
|
71
|
+
from .genie import genie_query_tool, genie_tool
|
|
72
|
+
|
|
73
|
+
# Unity Catalog tool factories
|
|
74
|
+
from .catalog import (
|
|
75
|
+
catalog_tool,
|
|
76
|
+
lineage_tool,
|
|
77
|
+
schema_tool,
|
|
78
|
+
uc_function_tool,
|
|
79
|
+
uc_function_toolkit,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
# Platform tool factories
|
|
83
|
+
from .vector_search import vector_search_tool
|
|
84
|
+
from .sql_tools import sql_tool
|
|
85
|
+
from .http_tools import http_tool, openapi_tool
|
|
86
|
+
from .mcp_consume import mcp_tool, mcp_toolkit
|
|
87
|
+
from .foundation_model import foundation_model_tool
|
|
88
|
+
from .jobs_tools import (
|
|
89
|
+
jobs_for_table_tool,
|
|
90
|
+
jobs_history_tool,
|
|
91
|
+
jobs_logs_tool,
|
|
92
|
+
jobs_source_paths_tool,
|
|
93
|
+
jobs_tools,
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
# LangGraph compiler (optional — requires the ``langgraph`` extra)
|
|
97
|
+
from ._compile import CompileContext, compile_to_langgraph
|
|
98
|
+
|
|
99
|
+
# MLflow ChatAgent wrapper (optional — requires the ``langgraph`` and ``eval`` extras)
|
|
100
|
+
from ._chat_agent import chat_agent_for, compile_to_chat_agent, log_agent
|
|
101
|
+
|
|
102
|
+
# Databricks Apps ResponsesAgent compile target (optional — same extras)
|
|
103
|
+
from ._responses_agent import compile_to_responses_agent
|
|
104
|
+
|
|
105
|
+
# Unified OBO header extraction (both runtimes use this)
|
|
106
|
+
from ._obo import extract_obo_headers, make_obo_workspace_client
|
|
107
|
+
|
|
108
|
+
# Resource declaration — auto-derive MLflow resources from the agent tree
|
|
109
|
+
from ._resources import (
|
|
110
|
+
ResourceSpec,
|
|
111
|
+
attach_resources,
|
|
112
|
+
collect_resource_specs,
|
|
113
|
+
mlflow_resources_for,
|
|
114
|
+
resources_to_databricks_yml,
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
# @tool decorator and UC publishing
|
|
118
|
+
from ._tool import ToolMetadata, get_tool_metadata, tool
|
|
119
|
+
from ._tool_factory import build_tool, resolve_description
|
|
120
|
+
from ._tool_publish import PublishResult, publish_tools_to_uc
|
|
121
|
+
|
|
122
|
+
# Session / multi-turn memory
|
|
123
|
+
from ._session import (
|
|
124
|
+
InMemorySessionStore,
|
|
125
|
+
Session,
|
|
126
|
+
SessionStore,
|
|
127
|
+
append_turn,
|
|
128
|
+
load_or_create_session,
|
|
129
|
+
)
|
|
130
|
+
from ._session_delta import DeltaSessionStore
|
|
131
|
+
from ._session_lakebase import LakebaseSessionStore
|
|
132
|
+
|
|
133
|
+
# Durable memory + few-shot examples
|
|
134
|
+
from ._memory import (
|
|
135
|
+
EmbeddingFn,
|
|
136
|
+
InMemoryMemoryStore,
|
|
137
|
+
Memory,
|
|
138
|
+
MemoryFilter,
|
|
139
|
+
MemoryStore,
|
|
140
|
+
RecallOptions,
|
|
141
|
+
RecallResult,
|
|
142
|
+
cosine_similarity,
|
|
143
|
+
)
|
|
144
|
+
from ._example import (
|
|
145
|
+
Example,
|
|
146
|
+
ExampleFilter,
|
|
147
|
+
ExampleResult,
|
|
148
|
+
ExampleStore,
|
|
149
|
+
FindSimilarOptions,
|
|
150
|
+
InMemoryExampleStore,
|
|
151
|
+
)
|
|
152
|
+
from ._memory_lakebase import LakebaseMemoryStore
|
|
153
|
+
from ._example_lakebase import LakebaseExampleStore
|
|
154
|
+
from ._memory_delta import DeltaMemoryStore, VectorSearchLike
|
|
155
|
+
from ._example_delta import DeltaExampleStore
|
|
156
|
+
|
|
157
|
+
# Agent-facing memory / example tools (LLM-callable wrappers around the stores)
|
|
158
|
+
from ._memory_tools import make_memory_tools
|
|
159
|
+
from ._example_tools import make_example_tools
|
|
160
|
+
|
|
161
|
+
# Prompt-assembly helpers — stitch memory + example recall into a system prompt
|
|
162
|
+
from ._prompt_assembly import (
|
|
163
|
+
assemble_context,
|
|
164
|
+
assemble_example_context,
|
|
165
|
+
assemble_memory_context,
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
# Example mining — extract few-shot examples from session history
|
|
169
|
+
from ._example_mining import (
|
|
170
|
+
MineResult,
|
|
171
|
+
Turn as ExampleMiningTurn,
|
|
172
|
+
mine_examples,
|
|
173
|
+
pair_turns,
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
# Memory consolidation — LLM-summarize older memories into a rollup row
|
|
177
|
+
from ._memory_consolidate import (
|
|
178
|
+
ConsolidateResult,
|
|
179
|
+
consolidate_memories,
|
|
180
|
+
)
|
|
181
|
+
|
|
182
|
+
# Databricks Managed MCP integration
|
|
183
|
+
from ._managed_mcp import (
|
|
184
|
+
ManagedMCPEndpoint,
|
|
185
|
+
managed_mcp_client_config,
|
|
186
|
+
managed_mcp_urls,
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
# Mosaic AI Supervisor Agent publishing
|
|
190
|
+
from ._publish import create_supervisor_agent, publish_to_supervisor
|
|
191
|
+
|
|
192
|
+
# Local lightweight guards — zero-latency runtime checks
|
|
193
|
+
from ._guards import (
|
|
194
|
+
FeatureFlagGuard,
|
|
195
|
+
RateLimit,
|
|
196
|
+
ToolAllowlist,
|
|
197
|
+
ToolDenylist,
|
|
198
|
+
compose,
|
|
199
|
+
prompt_injection_heuristic,
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
# Cost tracking helpers
|
|
203
|
+
from ._cost import CostBreakdown, cost_for_agent, cost_for_endpoint
|
|
204
|
+
|
|
205
|
+
# Scheduled-job / batch invocation — non-interactive entry point
|
|
206
|
+
from ._run_once import run_once
|
|
207
|
+
|
|
208
|
+
# Static lint
|
|
209
|
+
from ._lint import LintFinding, Severity, lint_agent
|
|
210
|
+
|
|
211
|
+
# Hot-swap the LLM endpoint on a deployed agent without re-logging
|
|
212
|
+
from ._hot_swap import (
|
|
213
|
+
APX_MODEL_OVERRIDE_ENV,
|
|
214
|
+
HotSwapResult,
|
|
215
|
+
get_active_override,
|
|
216
|
+
hot_swap_model,
|
|
217
|
+
)
|
|
218
|
+
|
|
219
|
+
# Hot-swap analog for the Apps target — re-deploys with a different bundle var
|
|
220
|
+
from ._hot_swap_apps import (
|
|
221
|
+
DEFAULT_LLM_VAR_NAME,
|
|
222
|
+
AppsHotSwapResult,
|
|
223
|
+
hot_swap_apps,
|
|
224
|
+
read_var_default,
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
# Trace exporter
|
|
228
|
+
from ._trace_export import ExportResult, export_traces
|
|
229
|
+
|
|
230
|
+
# Topology visualization
|
|
231
|
+
from ._topology import (
|
|
232
|
+
AgentNode,
|
|
233
|
+
Topology,
|
|
234
|
+
TopologyEdge,
|
|
235
|
+
discover_topology,
|
|
236
|
+
render_topology,
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
# Cross-agent evaluation
|
|
240
|
+
from ._eval_chain import ChainCaseResult, ChainEvalReport, evaluate_chain
|
|
241
|
+
|
|
242
|
+
# Canary / A-B deployment helpers (Model Serving target)
|
|
243
|
+
from ._canary import (
|
|
244
|
+
CanaryConfig,
|
|
245
|
+
CanaryReport,
|
|
246
|
+
VersionMetrics,
|
|
247
|
+
analyze_canary,
|
|
248
|
+
deploy_canary,
|
|
249
|
+
get_canary_config,
|
|
250
|
+
promote_canary,
|
|
251
|
+
rollback_canary,
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
# Canary helpers for the Databricks Apps target — multi-target bundle flow
|
|
255
|
+
from ._canary_apps import (
|
|
256
|
+
TRACE_APP_NAME_TAG,
|
|
257
|
+
AppsCanaryConfig,
|
|
258
|
+
AppsCanaryReport,
|
|
259
|
+
AppsPromoteResult,
|
|
260
|
+
AppsVersionMetrics,
|
|
261
|
+
add_canary_target_to_yml,
|
|
262
|
+
analyze_canary_app,
|
|
263
|
+
canary_app_name,
|
|
264
|
+
canary_target_name,
|
|
265
|
+
deploy_canary_app,
|
|
266
|
+
promote_canary_app,
|
|
267
|
+
remove_canary_target_from_yml,
|
|
268
|
+
rollback_canary_app,
|
|
269
|
+
sanitize_version,
|
|
270
|
+
write_databricks_yml,
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
# databricks-watchdog integration
|
|
274
|
+
from ._watchdog import (
|
|
275
|
+
WatchdogClient,
|
|
276
|
+
WatchdogDecision,
|
|
277
|
+
WatchdogGuard,
|
|
278
|
+
emit_agent_metadata,
|
|
279
|
+
make_mcp_transport,
|
|
280
|
+
make_uc_violation_writer,
|
|
281
|
+
make_watchdog_transport,
|
|
282
|
+
set_uc_tags_for_agent,
|
|
283
|
+
)
|
|
284
|
+
|
|
285
|
+
# MLflow ChatAgent /invocations route mounter (optional — same extras)
|
|
286
|
+
from ._invocations import mount_invocations_route
|
|
287
|
+
|
|
288
|
+
# MLflow tracing helpers (optional — graceful no-op without mlflow)
|
|
289
|
+
from ._mlflow_tracing import (
|
|
290
|
+
current_active_span,
|
|
291
|
+
enable_langchain_autolog,
|
|
292
|
+
is_mlflow_available,
|
|
293
|
+
safe_span,
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
# Audit log schema — apx.* span attributes
|
|
297
|
+
from ._audit import (
|
|
298
|
+
AuditAttrs,
|
|
299
|
+
hash_for_audit,
|
|
300
|
+
input_keys_summary,
|
|
301
|
+
output_summary,
|
|
302
|
+
set_audit_attrs,
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
# Bootstrap helpers for Apps-target quickstart
|
|
306
|
+
from .bootstrap import init_apps_experiment
|
|
307
|
+
|
|
308
|
+
__all__ = [
|
|
309
|
+
# Agent types
|
|
310
|
+
"Agent",
|
|
311
|
+
"BaseAgent",
|
|
312
|
+
"CoworkerAgent",
|
|
313
|
+
"CoworkerTemplate",
|
|
314
|
+
"DataAgent",
|
|
315
|
+
"DataTemplate",
|
|
316
|
+
"HandoffAgent",
|
|
317
|
+
"KeywordRouter",
|
|
318
|
+
"LlmAgent",
|
|
319
|
+
"LoopAgent",
|
|
320
|
+
"ParallelAgent",
|
|
321
|
+
"RouterAgent",
|
|
322
|
+
"SequentialAgent",
|
|
323
|
+
"RemoteDatabricksAgent",
|
|
324
|
+
"agent_tool",
|
|
325
|
+
# Template protocol + registry
|
|
326
|
+
"Template",
|
|
327
|
+
"TemplateInfo",
|
|
328
|
+
"TemplateRegistry",
|
|
329
|
+
"template",
|
|
330
|
+
"template_registry",
|
|
331
|
+
# Models
|
|
332
|
+
"AfterModelHook",
|
|
333
|
+
"AfterToolHook",
|
|
334
|
+
"AgentCard",
|
|
335
|
+
"AgentConfig",
|
|
336
|
+
"AgentContext",
|
|
337
|
+
"AgentTool",
|
|
338
|
+
"BeforeModelHook",
|
|
339
|
+
"BeforeToolHook",
|
|
340
|
+
"ExampleBackendConfig",
|
|
341
|
+
"GuardrailsConfig",
|
|
342
|
+
"InputGuardrailFn",
|
|
343
|
+
"MemoryBackendConfig",
|
|
344
|
+
"Message",
|
|
345
|
+
"OutputGuardrailFn",
|
|
346
|
+
"SessionBackendConfig",
|
|
347
|
+
# Dependencies
|
|
348
|
+
"Dependencies",
|
|
349
|
+
# SQL utilities
|
|
350
|
+
"decode_statement",
|
|
351
|
+
"get_warehouse_id",
|
|
352
|
+
"run_sql",
|
|
353
|
+
# Provider compat
|
|
354
|
+
"ChatDatabricksGptReasoning",
|
|
355
|
+
"get_llm",
|
|
356
|
+
# App factory
|
|
357
|
+
"create_app",
|
|
358
|
+
"finalize_agent",
|
|
359
|
+
"mount_mcp_endpoints",
|
|
360
|
+
"mount_readyz",
|
|
361
|
+
"setup_agent",
|
|
362
|
+
# Declarative tool config
|
|
363
|
+
"ToolConfigError",
|
|
364
|
+
"load_config_tools",
|
|
365
|
+
"merge_config_tools",
|
|
366
|
+
# Eval
|
|
367
|
+
"app_predict_fn",
|
|
368
|
+
"endpoint_predict_fn",
|
|
369
|
+
"eval_against_endpoint",
|
|
370
|
+
"evaluate",
|
|
371
|
+
# Tool factories
|
|
372
|
+
"genie_query_tool",
|
|
373
|
+
"genie_tool",
|
|
374
|
+
"catalog_tool",
|
|
375
|
+
"lineage_tool",
|
|
376
|
+
"schema_tool",
|
|
377
|
+
"uc_function_tool",
|
|
378
|
+
"uc_function_toolkit",
|
|
379
|
+
"vector_search_tool",
|
|
380
|
+
"sql_tool",
|
|
381
|
+
"http_tool",
|
|
382
|
+
"openapi_tool",
|
|
383
|
+
"mcp_tool",
|
|
384
|
+
"mcp_toolkit",
|
|
385
|
+
"foundation_model_tool",
|
|
386
|
+
"jobs_for_table_tool",
|
|
387
|
+
"jobs_history_tool",
|
|
388
|
+
"jobs_logs_tool",
|
|
389
|
+
"jobs_source_paths_tool",
|
|
390
|
+
"jobs_tools",
|
|
391
|
+
# LangGraph compiler
|
|
392
|
+
"CompileContext",
|
|
393
|
+
"compile_to_langgraph",
|
|
394
|
+
# MLflow ChatAgent wrapper
|
|
395
|
+
"chat_agent_for",
|
|
396
|
+
"compile_to_chat_agent",
|
|
397
|
+
"log_agent",
|
|
398
|
+
# Databricks Apps ResponsesAgent compile target
|
|
399
|
+
"compile_to_responses_agent",
|
|
400
|
+
# Unified OBO header extraction
|
|
401
|
+
"extract_obo_headers",
|
|
402
|
+
"make_obo_workspace_client",
|
|
403
|
+
# Resource declaration
|
|
404
|
+
"ResourceSpec",
|
|
405
|
+
"attach_resources",
|
|
406
|
+
"collect_resource_specs",
|
|
407
|
+
"mlflow_resources_for",
|
|
408
|
+
"resources_to_databricks_yml",
|
|
409
|
+
# @tool decorator and UC publishing
|
|
410
|
+
"tool",
|
|
411
|
+
"build_tool",
|
|
412
|
+
"resolve_description",
|
|
413
|
+
"ToolMetadata",
|
|
414
|
+
"get_tool_metadata",
|
|
415
|
+
"publish_tools_to_uc",
|
|
416
|
+
"PublishResult",
|
|
417
|
+
# Session / multi-turn memory
|
|
418
|
+
"Session",
|
|
419
|
+
"SessionStore",
|
|
420
|
+
"InMemorySessionStore",
|
|
421
|
+
"DeltaSessionStore",
|
|
422
|
+
"LakebaseSessionStore",
|
|
423
|
+
"append_turn",
|
|
424
|
+
"load_or_create_session",
|
|
425
|
+
# Durable memory + examples
|
|
426
|
+
"EmbeddingFn",
|
|
427
|
+
"InMemoryMemoryStore",
|
|
428
|
+
"Memory",
|
|
429
|
+
"MemoryFilter",
|
|
430
|
+
"MemoryStore",
|
|
431
|
+
"RecallOptions",
|
|
432
|
+
"RecallResult",
|
|
433
|
+
"cosine_similarity",
|
|
434
|
+
"Example",
|
|
435
|
+
"ExampleFilter",
|
|
436
|
+
"ExampleResult",
|
|
437
|
+
"ExampleStore",
|
|
438
|
+
"FindSimilarOptions",
|
|
439
|
+
"InMemoryExampleStore",
|
|
440
|
+
"LakebaseMemoryStore",
|
|
441
|
+
"LakebaseExampleStore",
|
|
442
|
+
"DeltaMemoryStore",
|
|
443
|
+
"DeltaExampleStore",
|
|
444
|
+
"VectorSearchLike",
|
|
445
|
+
# Agent-facing memory / example tools
|
|
446
|
+
"make_memory_tools",
|
|
447
|
+
"make_example_tools",
|
|
448
|
+
# Prompt-assembly helpers
|
|
449
|
+
"assemble_context",
|
|
450
|
+
"assemble_example_context",
|
|
451
|
+
"assemble_memory_context",
|
|
452
|
+
# Example mining
|
|
453
|
+
"ExampleMiningTurn",
|
|
454
|
+
"MineResult",
|
|
455
|
+
"mine_examples",
|
|
456
|
+
"pair_turns",
|
|
457
|
+
# Memory consolidation
|
|
458
|
+
"ConsolidateResult",
|
|
459
|
+
"consolidate_memories",
|
|
460
|
+
# Managed MCP
|
|
461
|
+
"ManagedMCPEndpoint",
|
|
462
|
+
"managed_mcp_urls",
|
|
463
|
+
"managed_mcp_client_config",
|
|
464
|
+
# Supervisor publishing
|
|
465
|
+
"create_supervisor_agent",
|
|
466
|
+
"publish_to_supervisor",
|
|
467
|
+
# Local lightweight guards
|
|
468
|
+
"FeatureFlagGuard",
|
|
469
|
+
"RateLimit",
|
|
470
|
+
"ToolAllowlist",
|
|
471
|
+
"ToolDenylist",
|
|
472
|
+
"prompt_injection_heuristic",
|
|
473
|
+
"compose",
|
|
474
|
+
# Cost tracking
|
|
475
|
+
"CostBreakdown",
|
|
476
|
+
"cost_for_agent",
|
|
477
|
+
"cost_for_endpoint",
|
|
478
|
+
# Batch / scheduled-job invocation
|
|
479
|
+
"run_once",
|
|
480
|
+
# Lint
|
|
481
|
+
"LintFinding",
|
|
482
|
+
"Severity",
|
|
483
|
+
"lint_agent",
|
|
484
|
+
# Hot-swap
|
|
485
|
+
"APX_MODEL_OVERRIDE_ENV",
|
|
486
|
+
"HotSwapResult",
|
|
487
|
+
"get_active_override",
|
|
488
|
+
"hot_swap_model",
|
|
489
|
+
# Hot-swap (Apps target)
|
|
490
|
+
"AppsHotSwapResult",
|
|
491
|
+
"DEFAULT_LLM_VAR_NAME",
|
|
492
|
+
"hot_swap_apps",
|
|
493
|
+
"read_var_default",
|
|
494
|
+
# Trace exporter
|
|
495
|
+
"ExportResult",
|
|
496
|
+
"export_traces",
|
|
497
|
+
# Topology
|
|
498
|
+
"AgentNode",
|
|
499
|
+
"Topology",
|
|
500
|
+
"TopologyEdge",
|
|
501
|
+
"discover_topology",
|
|
502
|
+
"render_topology",
|
|
503
|
+
# Cross-agent eval
|
|
504
|
+
"ChainCaseResult",
|
|
505
|
+
"ChainEvalReport",
|
|
506
|
+
"evaluate_chain",
|
|
507
|
+
# Canary / A-B helpers (Model Serving)
|
|
508
|
+
"CanaryConfig",
|
|
509
|
+
"CanaryReport",
|
|
510
|
+
"VersionMetrics",
|
|
511
|
+
"analyze_canary",
|
|
512
|
+
"deploy_canary",
|
|
513
|
+
"get_canary_config",
|
|
514
|
+
"promote_canary",
|
|
515
|
+
"rollback_canary",
|
|
516
|
+
# Canary helpers (Databricks Apps)
|
|
517
|
+
"AppsCanaryConfig",
|
|
518
|
+
"AppsCanaryReport",
|
|
519
|
+
"AppsPromoteResult",
|
|
520
|
+
"AppsVersionMetrics",
|
|
521
|
+
"TRACE_APP_NAME_TAG",
|
|
522
|
+
"add_canary_target_to_yml",
|
|
523
|
+
"analyze_canary_app",
|
|
524
|
+
"canary_app_name",
|
|
525
|
+
"canary_target_name",
|
|
526
|
+
"deploy_canary_app",
|
|
527
|
+
"promote_canary_app",
|
|
528
|
+
"remove_canary_target_from_yml",
|
|
529
|
+
"rollback_canary_app",
|
|
530
|
+
"sanitize_version",
|
|
531
|
+
"write_databricks_yml",
|
|
532
|
+
# Watchdog integration
|
|
533
|
+
"WatchdogClient",
|
|
534
|
+
"WatchdogDecision",
|
|
535
|
+
"WatchdogGuard",
|
|
536
|
+
"emit_agent_metadata",
|
|
537
|
+
"set_uc_tags_for_agent",
|
|
538
|
+
"make_uc_violation_writer",
|
|
539
|
+
"make_mcp_transport",
|
|
540
|
+
"make_watchdog_transport",
|
|
541
|
+
# MLflow /invocations route mounter
|
|
542
|
+
"mount_invocations_route",
|
|
543
|
+
# MLflow tracing
|
|
544
|
+
"current_active_span",
|
|
545
|
+
"enable_langchain_autolog",
|
|
546
|
+
"is_mlflow_available",
|
|
547
|
+
"safe_span",
|
|
548
|
+
# Audit log schema
|
|
549
|
+
"AuditAttrs",
|
|
550
|
+
"set_audit_attrs",
|
|
551
|
+
"hash_for_audit",
|
|
552
|
+
"input_keys_summary",
|
|
553
|
+
"output_summary",
|
|
554
|
+
# Bootstrap
|
|
555
|
+
"init_apps_experiment",
|
|
556
|
+
]
|
apx_agent/_agent_tool.py
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""agent_tool — wrap any BaseAgent as a callable tool.
|
|
2
|
+
|
|
3
|
+
Mirrors Google ADK's ``AgentTool`` pattern as a first-class composition
|
|
4
|
+
primitive. Lets one ``LlmAgent`` delegate to another agent (local or remote)
|
|
5
|
+
based on the LLM's tool-calling decision, rather than via a fixed workflow
|
|
6
|
+
position.
|
|
7
|
+
|
|
8
|
+
Workflow agents (``SequentialAgent``, ``ParallelAgent``, ``LoopAgent``, ...)
|
|
9
|
+
compose agents along *deterministic* edges. ``agent_tool`` composes along
|
|
10
|
+
*LLM-driven* edges — the parent's LLM picks when and with what input.
|
|
11
|
+
|
|
12
|
+
Both local in-process and remote agents are supported transparently:
|
|
13
|
+
|
|
14
|
+
# Local in-process
|
|
15
|
+
specialist = Agent(tools=[lookup_lineage])
|
|
16
|
+
orchestrator = Agent(tools=[agent_tool(specialist, name="data_inspector",
|
|
17
|
+
description="Inspect table lineage")])
|
|
18
|
+
|
|
19
|
+
# Remote (via RemoteDatabricksAgent)
|
|
20
|
+
remote_billing = await RemoteDatabricksAgent.from_app_name("billing-agent")
|
|
21
|
+
orchestrator = Agent(tools=[agent_tool(remote_billing, name="billing",
|
|
22
|
+
description="Answer billing questions")])
|
|
23
|
+
|
|
24
|
+
The same wrapper handles both — ``BaseAgent.run`` is the only contract.
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
from __future__ import annotations
|
|
28
|
+
|
|
29
|
+
import re
|
|
30
|
+
from typing import TYPE_CHECKING
|
|
31
|
+
|
|
32
|
+
from ._defaults import Dependencies
|
|
33
|
+
from ._models import Message
|
|
34
|
+
from ._tool_factory import build_tool
|
|
35
|
+
|
|
36
|
+
if TYPE_CHECKING:
|
|
37
|
+
from ._agents import BaseAgent
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _snake_case(name: str) -> str:
|
|
41
|
+
s1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", name)
|
|
42
|
+
return re.sub("([a-z0-9])([A-Z])", r"\1_\2", s1).lower()
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _infer_name(agent: "BaseAgent") -> str:
|
|
46
|
+
explicit = getattr(agent, "_name", None)
|
|
47
|
+
if explicit:
|
|
48
|
+
return _snake_case(explicit)
|
|
49
|
+
return _snake_case(type(agent).__name__)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def agent_tool(
|
|
53
|
+
agent: "BaseAgent",
|
|
54
|
+
*,
|
|
55
|
+
name: str | None = None,
|
|
56
|
+
description: str | None = None,
|
|
57
|
+
):
|
|
58
|
+
"""Wrap an agent as a tool callable from another ``LlmAgent``.
|
|
59
|
+
|
|
60
|
+
The returned object is a typed Python function suitable for the
|
|
61
|
+
``tools=[...]`` parameter of ``LlmAgent``. When the parent LLM picks
|
|
62
|
+
this tool, the framework invokes ``agent.run(...)`` in-process (or over
|
|
63
|
+
HTTP for ``RemoteDatabricksAgent``) and returns the result.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
agent: Any ``BaseAgent``. Local (``LlmAgent``, ``SequentialAgent``,
|
|
67
|
+
``ParallelAgent``, ``LoopAgent``, ``RouterAgent``, ``HandoffAgent``)
|
|
68
|
+
or remote (``RemoteDatabricksAgent``) — the wrapper doesn't care.
|
|
69
|
+
name: Tool name the parent LLM sees. Defaults to ``agent._name`` or
|
|
70
|
+
snake-cased class name. Required to be descriptive — the parent
|
|
71
|
+
LLM picks tools by name and description.
|
|
72
|
+
description: Tool description the parent LLM sees. Strongly recommend
|
|
73
|
+
providing this explicitly; the default is a generic delegate
|
|
74
|
+
message which won't help the LLM decide when to call this tool.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
A typed function with LLM-visible parameter ``message: str``.
|
|
78
|
+
"""
|
|
79
|
+
tool_name = name or _infer_name(agent)
|
|
80
|
+
tool_desc = description or (
|
|
81
|
+
f"Delegate the user's request to the {tool_name} agent. "
|
|
82
|
+
"Pass the relevant question or instruction as ``message``."
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
async def _wrapped(message: str, request: Dependencies.Request) -> str:
|
|
86
|
+
result = await agent.run(
|
|
87
|
+
[Message(role="user", content=message)],
|
|
88
|
+
request,
|
|
89
|
+
)
|
|
90
|
+
return result
|
|
91
|
+
|
|
92
|
+
return build_tool(_wrapped, name=tool_name, description=tool_desc)
|