agentsml-impl 0.2.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.
Files changed (129) hide show
  1. agentsml_impl/__init__.py +3 -0
  2. agentsml_impl/cli.py +472 -0
  3. agentsml_impl/compiler/__init__.py +1 -0
  4. agentsml_impl/compiler/capabilities.py +330 -0
  5. agentsml_impl/compiler/conditions.py +177 -0
  6. agentsml_impl/compiler/diagnostics.py +112 -0
  7. agentsml_impl/compiler/durations.py +31 -0
  8. agentsml_impl/compiler/expressions.py +123 -0
  9. agentsml_impl/compiler/identifiers.py +60 -0
  10. agentsml_impl/compiler/ir.py +391 -0
  11. agentsml_impl/compiler/limits.py +28 -0
  12. agentsml_impl/compiler/loader.py +83 -0
  13. agentsml_impl/compiler/naming.py +87 -0
  14. agentsml_impl/compiler/planner.py +79 -0
  15. agentsml_impl/compiler/render.py +90 -0
  16. agentsml_impl/compiler/schema_validation.py +121 -0
  17. agentsml_impl/compiler/semantic_validation.py +424 -0
  18. agentsml_impl/protocols/__init__.py +1 -0
  19. agentsml_impl/runtime/__init__.py +1 -0
  20. agentsml_impl/runtime/events.py +59 -0
  21. agentsml_impl/runtime/json_schema.py +138 -0
  22. agentsml_impl/runtime/tools.py +145 -0
  23. agentsml_impl/schemas/agentsml.schema.json +406 -0
  24. agentsml_impl/schemas/v0.1/agentsml.schema.json +628 -0
  25. agentsml_impl/schemas/v0.2/agentsml.schema.json +363 -0
  26. agentsml_impl/schemas/v0.3/agentsml.schema.json +406 -0
  27. agentsml_impl/targets/__init__.py +1 -0
  28. agentsml_impl/targets/a2a/__init__.py +0 -0
  29. agentsml_impl/targets/a2a/adapter.py +94 -0
  30. agentsml_impl/targets/a2a/capabilities.yaml +25 -0
  31. agentsml_impl/targets/ag2/__init__.py +0 -0
  32. agentsml_impl/targets/ag2/adapter.py +655 -0
  33. agentsml_impl/targets/ag2/capabilities.yaml +37 -0
  34. agentsml_impl/targets/ag_ui/__init__.py +0 -0
  35. agentsml_impl/targets/ag_ui/adapter.py +123 -0
  36. agentsml_impl/targets/ag_ui/capabilities.yaml +25 -0
  37. agentsml_impl/targets/agno/__init__.py +0 -0
  38. agentsml_impl/targets/agno/adapter.py +191 -0
  39. agentsml_impl/targets/agno/capabilities.yaml +26 -0
  40. agentsml_impl/targets/ap2/__init__.py +0 -0
  41. agentsml_impl/targets/ap2/adapter.py +84 -0
  42. agentsml_impl/targets/ap2/capabilities.yaml +25 -0
  43. agentsml_impl/targets/base.py +157 -0
  44. agentsml_impl/targets/bedrock_agentcore/__init__.py +0 -0
  45. agentsml_impl/targets/bedrock_agentcore/adapter.py +592 -0
  46. agentsml_impl/targets/bedrock_agentcore/capabilities.yaml +26 -0
  47. agentsml_impl/targets/claude_agent_sdk/__init__.py +0 -0
  48. agentsml_impl/targets/claude_agent_sdk/adapter.py +178 -0
  49. agentsml_impl/targets/claude_agent_sdk/capabilities.yaml +26 -0
  50. agentsml_impl/targets/crewai/__init__.py +0 -0
  51. agentsml_impl/targets/crewai/adapter.py +441 -0
  52. agentsml_impl/targets/crewai/capabilities.yaml +30 -0
  53. agentsml_impl/targets/databricks/__init__.py +0 -0
  54. agentsml_impl/targets/databricks/adapter.py +427 -0
  55. agentsml_impl/targets/databricks/capabilities.yaml +26 -0
  56. agentsml_impl/targets/flowise/__init__.py +0 -0
  57. agentsml_impl/targets/flowise/adapter.py +71 -0
  58. agentsml_impl/targets/flowise/capabilities.yaml +26 -0
  59. agentsml_impl/targets/google_adk/__init__.py +0 -0
  60. agentsml_impl/targets/google_adk/adapter.py +589 -0
  61. agentsml_impl/targets/google_adk/capabilities.yaml +36 -0
  62. agentsml_impl/targets/langchain/__init__.py +1 -0
  63. agentsml_impl/targets/langchain/adapter.py +351 -0
  64. agentsml_impl/targets/langchain/capabilities.yaml +30 -0
  65. agentsml_impl/targets/langflow/__init__.py +0 -0
  66. agentsml_impl/targets/langflow/adapter.py +147 -0
  67. agentsml_impl/targets/langflow/capabilities.yaml +26 -0
  68. agentsml_impl/targets/langgraph/__init__.py +0 -0
  69. agentsml_impl/targets/langgraph/adapter.py +911 -0
  70. agentsml_impl/targets/langgraph/capabilities.yaml +33 -0
  71. agentsml_impl/targets/llamaindex/__init__.py +1 -0
  72. agentsml_impl/targets/llamaindex/adapter.py +406 -0
  73. agentsml_impl/targets/llamaindex/capabilities.yaml +31 -0
  74. agentsml_impl/targets/lyzr/__init__.py +0 -0
  75. agentsml_impl/targets/lyzr/adapter.py +146 -0
  76. agentsml_impl/targets/lyzr/capabilities.yaml +26 -0
  77. agentsml_impl/targets/mastra/__init__.py +0 -0
  78. agentsml_impl/targets/mastra/adapter.py +635 -0
  79. agentsml_impl/targets/mastra/capabilities.yaml +32 -0
  80. agentsml_impl/targets/mcp_server/__init__.py +0 -0
  81. agentsml_impl/targets/mcp_server/adapter.py +141 -0
  82. agentsml_impl/targets/mcp_server/capabilities.yaml +25 -0
  83. agentsml_impl/targets/microsoft_agent_framework/__init__.py +0 -0
  84. agentsml_impl/targets/microsoft_agent_framework/adapter.py +563 -0
  85. agentsml_impl/targets/microsoft_agent_framework/capabilities.yaml +26 -0
  86. agentsml_impl/targets/n8n/__init__.py +0 -0
  87. agentsml_impl/targets/n8n/adapter.py +139 -0
  88. agentsml_impl/targets/n8n/capabilities.yaml +26 -0
  89. agentsml_impl/targets/openai_agents/__init__.py +0 -0
  90. agentsml_impl/targets/openai_agents/adapter.py +175 -0
  91. agentsml_impl/targets/openai_agents/capabilities.yaml +27 -0
  92. agentsml_impl/targets/pydantic_ai/__init__.py +0 -0
  93. agentsml_impl/targets/pydantic_ai/adapter.py +922 -0
  94. agentsml_impl/targets/pydantic_ai/capabilities.yaml +37 -0
  95. agentsml_impl/targets/registry.py +290 -0
  96. agentsml_impl/targets/relevance_ai/__init__.py +0 -0
  97. agentsml_impl/targets/relevance_ai/adapter.py +66 -0
  98. agentsml_impl/targets/relevance_ai/capabilities.yaml +26 -0
  99. agentsml_impl/targets/smolagents/__init__.py +0 -0
  100. agentsml_impl/targets/smolagents/adapter.py +210 -0
  101. agentsml_impl/targets/smolagents/capabilities.yaml +27 -0
  102. agentsml_impl/targets/snowflake_cortex/__init__.py +0 -0
  103. agentsml_impl/targets/snowflake_cortex/adapter.py +167 -0
  104. agentsml_impl/targets/snowflake_cortex/capabilities.yaml +26 -0
  105. agentsml_impl/targets/spring_ai/__init__.py +1 -0
  106. agentsml_impl/targets/spring_ai/adapter.py +626 -0
  107. agentsml_impl/targets/spring_ai/capabilities.yaml +31 -0
  108. agentsml_impl/targets/strands_agents/__init__.py +1 -0
  109. agentsml_impl/targets/strands_agents/adapter.py +309 -0
  110. agentsml_impl/targets/strands_agents/capabilities.yaml +29 -0
  111. agentsml_impl/targets/support_matrix.py +91 -0
  112. agentsml_impl/targets/ucp/__init__.py +0 -0
  113. agentsml_impl/targets/ucp/adapter.py +86 -0
  114. agentsml_impl/targets/ucp/capabilities.yaml +25 -0
  115. agentsml_impl/targets/vercel_ai/__init__.py +1 -0
  116. agentsml_impl/targets/vercel_ai/adapter.py +349 -0
  117. agentsml_impl/targets/vercel_ai/capabilities.yaml +30 -0
  118. agentsml_impl/targets/vertex_agent_engine/__init__.py +0 -0
  119. agentsml_impl/targets/vertex_agent_engine/adapter.py +407 -0
  120. agentsml_impl/targets/vertex_agent_engine/capabilities.yaml +26 -0
  121. agentsml_impl/targets/zapier_agents/__init__.py +0 -0
  122. agentsml_impl/targets/zapier_agents/adapter.py +106 -0
  123. agentsml_impl/targets/zapier_agents/capabilities.yaml +26 -0
  124. agentsml_impl-0.2.0.dist-info/METADATA +109 -0
  125. agentsml_impl-0.2.0.dist-info/RECORD +129 -0
  126. agentsml_impl-0.2.0.dist-info/WHEEL +5 -0
  127. agentsml_impl-0.2.0.dist-info/entry_points.txt +3 -0
  128. agentsml_impl-0.2.0.dist-info/licenses/LICENSE +28 -0
  129. agentsml_impl-0.2.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,427 @@
1
+ """Databricks Agent target adapter — Level 1 runnable code generation."""
2
+
3
+ from __future__ import annotations
4
+ import json
5
+ from pathlib import Path
6
+
7
+ from agentsml_impl.compiler.identifiers import python_identifier_ir
8
+ from agentsml_impl.compiler.naming import pascal_identifier
9
+ from agentsml_impl.compiler.ir import AgentSystemIR, ModelIR
10
+ from agentsml_impl.compiler.diagnostics import DiagCode, DiagnosticSet
11
+ from agentsml_impl.compiler.planner import GenerationPlan
12
+ from agentsml_impl.compiler.render import toml_string, write_file
13
+ from agentsml_impl.runtime.tools import generate_tools_module
14
+ from agentsml_impl.targets.base import TargetAdapter, GenerationResult
15
+
16
+
17
+ class Adapter(TargetAdapter):
18
+ @property
19
+ def name(self) -> str:
20
+ return "databricks"
21
+
22
+ def analyze(self, ir: AgentSystemIR, diagnostics: DiagnosticSet) -> None:
23
+ from agentsml_impl.compiler.capabilities import analyze_capabilities
24
+ analyze_capabilities(ir, "databricks", diagnostics)
25
+
26
+ def generate(self, ir: AgentSystemIR, plan: GenerationPlan,
27
+ out_dir: Path, diagnostics: DiagnosticSet) -> GenerationResult:
28
+ ir = python_identifier_ir(ir)
29
+ out_dir.mkdir(parents=True, exist_ok=True)
30
+ pkg = plan.package_name
31
+ src = out_dir / "src" / pkg
32
+ src.mkdir(parents=True, exist_ok=True)
33
+
34
+ files: list[str] = []
35
+ files += _write_pyproject(ir, plan, out_dir)
36
+ files += _write_tools(ir, src, out_dir, diagnostics)
37
+ files += _write_agent(ir, plan, src, out_dir, diagnostics)
38
+ files += _write_run(plan, src, out_dir)
39
+ files += _write_notebook(ir, plan, src, out_dir)
40
+ files += _write_init(src, out_dir)
41
+ files += _write_bundle(plan, out_dir)
42
+ files += _write_deployment_md(plan, out_dir)
43
+ files += _write_readme(ir, plan, out_dir)
44
+
45
+ return GenerationResult(
46
+ target=self.name, out_dir=out_dir, files_written=files, success=True
47
+ )
48
+
49
+
50
+ def _write_pyproject(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
51
+ c = f'''\
52
+ [build-system]
53
+ requires = ["setuptools>=68"]
54
+ build-backend = "setuptools.build_meta"
55
+
56
+ [project]
57
+ name = "{plan.package_name}"
58
+ version = "{ir.metadata.version or '0.1.0'}"
59
+ description = {toml_string(ir.metadata.description or plan.project_name)}
60
+ requires-python = ">=3.11"
61
+ dependencies = [
62
+ "mlflow>=2.14.0",
63
+ "python-dotenv"
64
+ ]
65
+
66
+ [tool.setuptools.packages.find]
67
+ where = ["src"]
68
+ '''
69
+ write_file(out_dir, "pyproject.toml", c)
70
+ return ["pyproject.toml"]
71
+
72
+
73
+ def _write_tools(ir: AgentSystemIR, src: Path, out_dir: Path, ds: DiagnosticSet) -> list[str]:
74
+ if not ir.tools:
75
+ return []
76
+ c = generate_tools_module(ir.tools, ds, framework="databricks")
77
+ c = c.replace("from typing import Any", "from typing import Any\nimport mlflow")
78
+ rel = f"src/{src.name}/tools.py"
79
+ write_file(out_dir, rel, c)
80
+ return [rel]
81
+
82
+
83
+ def _tool_specs(ir: AgentSystemIR, tool_keys: list[str]) -> list[dict]:
84
+ """OpenAI-style function tool definitions for the declared tools."""
85
+ specs = []
86
+ for tk in tool_keys:
87
+ tool = ir.tools.get(tk)
88
+ if tool is None:
89
+ continue
90
+ params = tool.input_schema if isinstance(tool.input_schema, dict) and tool.input_schema else {"type": "object", "properties": {}}
91
+ specs.append({"type": "function", "function": {
92
+ "name": tk, "description": tool.description or f"Tool {tk}", "parameters": params}})
93
+ return specs
94
+
95
+
96
+ _AGENT_TEMPLATE = '''\
97
+ class __CLASS__(mlflow.pyfunc.PythonModel):
98
+ """Databricks Mosaic AI agent model for '__AK__' served through MLflow."""
99
+
100
+ def __init__(self):
101
+ self.model_name = "__MODEL__"
102
+ self.system_prompt = """__INST__"""
103
+ self.tools = [__TOOLS__]
104
+ self.tool_specs = json.loads(__SPECS__)
105
+
106
+ @mlflow.trace(name="__AK___predict")
107
+ def predict(self, context: Any, model_input: Any) -> dict[str, Any]:
108
+ """Invoke the Mosaic AI agent model via the Databricks OpenAI-compatible client."""
109
+ if isinstance(model_input, dict):
110
+ messages = model_input.get("messages", [])
111
+ query = messages[-1].get("content", "") if messages else model_input.get("prompt", "")
112
+ else:
113
+ query = str(model_input)
114
+
115
+ try:
116
+ from databricks.sdk import WorkspaceClient
117
+ except ImportError as exc:
118
+ return self._echo(query, f"databricks client unavailable: {exc}")
119
+ try:
120
+ workspace = WorkspaceClient()
121
+ except Exception as exc: # no host/token or default config available
122
+ if not (os.environ.get("DATABRICKS_HOST") and os.environ.get("DATABRICKS_TOKEN")):
123
+ return self._echo(query, f"databricks credentials not configured: {exc}")
124
+ return self._error(exc)
125
+ try:
126
+ client = workspace.serving_endpoints.get_open_ai_client()
127
+ kwargs: dict[str, Any] = {}
128
+ if self.tool_specs:
129
+ kwargs["tools"] = self.tool_specs
130
+ completion = client.chat.completions.create(
131
+ model=self.model_name,
132
+ messages=[
133
+ {"role": "system", "content": self.system_prompt},
134
+ {"role": "user", "content": query},
135
+ ],
136
+ **kwargs,
137
+ )
138
+ message = completion.choices[0].message
139
+ result: dict[str, Any] = {
140
+ "messages": [{"role": "assistant", "content": message.content or ""}],
141
+ "model": self.model_name,
142
+ "status": "success",
143
+ }
144
+ calls = getattr(message, "tool_calls", None)
145
+ if calls:
146
+ result["tool_calls"] = [
147
+ {"id": c.id, "name": c.function.name, "arguments": c.function.arguments}
148
+ for c in calls
149
+ ]
150
+ result["tool_results"] = self._dispatch_tool_calls(result["tool_calls"])
151
+ return result
152
+ except Exception as exc:
153
+ return self._error(exc)
154
+
155
+ def _error(self, exc: Exception) -> dict[str, Any]:
156
+ return {
157
+ "messages": [{"role": "assistant", "content": ""}],
158
+ "model": self.model_name,
159
+ "status": "error",
160
+ "error": f"{type(exc).__name__}: {exc}",
161
+ }
162
+
163
+ def _echo(self, query: str, reason: str) -> dict[str, Any]:
164
+ return {
165
+ "messages": [{"role": "assistant", "content": f"Databricks Mosaic AI ({self.model_name}) response to: {query}"}],
166
+ "model": self.model_name,
167
+ "status": "success",
168
+ "fallback_reason": reason,
169
+ }
170
+
171
+ def _dispatch_tool_calls(self, tool_calls: list[dict[str, Any]]) -> list[dict[str, Any]]:
172
+ """Execute model-requested tool calls once (single round, no loop)."""
173
+ results: list[dict[str, Any]] = []
174
+ for call in tool_calls:
175
+ fn = getattr(_tools_module, call["name"], None) if _tools_module is not None else None
176
+ if fn is None:
177
+ results.append({"id": call["id"], "name": call["name"], "error": "unknown tool"})
178
+ continue
179
+ try:
180
+ args = call["arguments"]
181
+ args = json.loads(args) if isinstance(args, str) and args else (args or {})
182
+ results.append({"id": call["id"], "name": call["name"], "result": fn(**args)})
183
+ except Exception as exc:
184
+ results.append({"id": call["id"], "name": call["name"], "error": f"{type(exc).__name__}: {exc}"})
185
+ return results
186
+ '''
187
+
188
+
189
+ def _write_agent(ir: AgentSystemIR, plan: GenerationPlan, src: Path, out_dir: Path, ds: DiagnosticSet) -> list[str]:
190
+ agent_blocks: list[str] = []
191
+ class_names: list[str] = []
192
+ tools_import = f"from .tools import {', '.join(ir.tools.keys())}" if ir.tools else ""
193
+
194
+ for ak, agent in ir.agents.items():
195
+ m = ir.models.get(agent.model)
196
+ mstr = m.name if m else 'databricks-dbrx-instruct'
197
+ inst = agent.instructions.replace('"""', "'''")
198
+ tools_list = ", ".join(agent.tools) if agent.tools else ""
199
+
200
+ class_name = f"{pascal_identifier(ak, prefix='Agent')}Agent"
201
+ class_names.append(class_name)
202
+ specs = _tool_specs(ir, agent.tools)
203
+ block = _AGENT_TEMPLATE
204
+ for k, v in {
205
+ "__CLASS__": class_name, "__AK__": ak, "__MODEL__": mstr,
206
+ "__INST__": inst, "__TOOLS__": tools_list,
207
+ "__SPECS__": repr(json.dumps(specs)),
208
+ }.items():
209
+ block = block.replace(k, v)
210
+ agent_blocks.append(block)
211
+
212
+ tools_module_import = "from . import tools as _tools_module" if ir.tools else "_tools_module = None"
213
+ first_cls = class_names[0] if class_names else "DefaultAgent"
214
+ if not class_names:
215
+ agent_blocks.append('''\
216
+ class DefaultAgent(mlflow.pyfunc.PythonModel):
217
+ def predict(self, context: Any, model_input: Any) -> dict[str, Any]:
218
+ return {"messages": [{"role": "assistant", "content": str(model_input)}], "status": "success"}
219
+ ''')
220
+
221
+ c = f'''\
222
+ """Databricks Mosaic AI Agent definitions for {plan.project_name}."""
223
+ from __future__ import annotations
224
+ from typing import Any
225
+ import os
226
+ import mlflow
227
+ import mlflow.pyfunc
228
+ import json
229
+ {tools_import}
230
+ {tools_module_import}
231
+
232
+ {chr(10).join(agent_blocks)}
233
+
234
+ root_agent = {first_cls}()
235
+ __all__ = [{", ".join(repr(cn) for cn in class_names)}, "root_agent"]
236
+ '''
237
+ rel = f"src/{src.name}/agent.py"
238
+ write_file(out_dir, rel, c)
239
+ return [rel]
240
+
241
+
242
+ def _write_run(plan: GenerationPlan, src: Path, out_dir: Path) -> list[str]:
243
+ c = f'''\
244
+ """Runner for {plan.project_name} (Databricks)."""
245
+ from __future__ import annotations
246
+ import sys
247
+ from .agent import root_agent
248
+
249
+ def main() -> None:
250
+ q = " ".join(sys.argv[1:]) or "Hello"
251
+ res = root_agent.predict(None, {{"messages": [{{"role": "user", "content": q}}]}})
252
+ messages = res.get("messages", [])
253
+ output = messages[-1].get("content") if messages else str(res)
254
+ print("Result:", output)
255
+
256
+ if __name__ == "__main__":
257
+ main()
258
+ '''
259
+ rel = f"src/{src.name}/run.py"
260
+ write_file(out_dir, rel, c)
261
+ return [rel]
262
+
263
+
264
+ def _write_notebook(ir: AgentSystemIR, plan: GenerationPlan, src: Path, out_dir: Path) -> list[str]:
265
+ c = f'''\
266
+ # Databricks notebook source
267
+ # MAGIC %md
268
+ # MAGIC # Deploy {plan.project_name} to Databricks Model Serving
269
+ # MAGIC
270
+ # MAGIC This notebook registers the `{plan.project_name}` agent with Unity Catalog
271
+ # MAGIC and provisions a Model Serving endpoint.
272
+
273
+ # COMMAND ----------
274
+ import mlflow
275
+ from {plan.package_name}.agent import root_agent
276
+
277
+ # COMMAND ----------
278
+ # MAGIC %md
279
+ # MAGIC ## 1. Log and register agent with Unity Catalog
280
+
281
+ # COMMAND ----------
282
+ catalog = "main"
283
+ schema = "default"
284
+ model_name = f"{{catalog}}.{{schema}}.{plan.package_name}"
285
+
286
+ with mlflow.start_run():
287
+ model_info = mlflow.pyfunc.log_model(
288
+ python_model=root_agent,
289
+ artifact_path="agent",
290
+ registered_model_name=model_name,
291
+ )
292
+ print(f"Logged agent model URI: {{model_info.model_uri}}")
293
+
294
+ # COMMAND ----------
295
+ # MAGIC %md
296
+ # MAGIC ## 2. Model Serving endpoint configuration
297
+
298
+ # COMMAND ----------
299
+ try:
300
+ from databricks.sdk import WorkspaceClient
301
+ from databricks.sdk.service.serving import EndpointCoreConfigInput, ServedEntityInput
302
+ w = WorkspaceClient()
303
+ endpoint_name = "{plan.package_name}-serving"
304
+ print(f"Ready to deploy endpoint: {{endpoint_name}}")
305
+ except Exception as e:
306
+ print(f"Note: WorkspaceClient requires active Databricks workspace context: {{e}}")
307
+ '''
308
+ rel = f"src/{src.name}/notebook.py"
309
+ write_file(out_dir, rel, c)
310
+ return [rel]
311
+
312
+
313
+ def _write_init(src: Path, out_dir: Path) -> list[str]:
314
+ c = f'"""Package: {src.name}."""\n'
315
+ rel = f"src/{src.name}/__init__.py"
316
+ write_file(out_dir, rel, c)
317
+ return [rel]
318
+
319
+
320
+ def _write_bundle(plan: GenerationPlan, out_dir: Path) -> list[str]:
321
+ c = f"""\
322
+ bundle:
323
+ name: {plan.package_name}
324
+
325
+ variables:
326
+ model_version:
327
+ description: Registered model version to serve (created when the notebook logs the model)
328
+ default: "1"
329
+
330
+ resources:
331
+ registered_models:
332
+ {plan.package_name}_model:
333
+ name: {plan.package_name}
334
+ catalog_name: main
335
+ schema_name: default
336
+ comment: {json.dumps('Registered model for ' + plan.project_name)}
337
+
338
+ model_serving_endpoints:
339
+ {plan.package_name}_endpoint:
340
+ name: {plan.package_name}-serving
341
+ config:
342
+ served_entities:
343
+ - entity_name: main.default.{plan.package_name}
344
+ entity_version: ${{var.model_version}}
345
+ workload_size: Small
346
+ scale_to_zero_enabled: true
347
+ """
348
+ write_file(out_dir, "databricks.yml", c)
349
+ return ["databricks.yml"]
350
+
351
+
352
+ def _write_deployment_md(plan: GenerationPlan, out_dir: Path) -> list[str]:
353
+ c = f"""\
354
+ # Deploying {plan.project_name} to Databricks Mosaic AI
355
+
356
+ This project uses Databricks Mosaic AI Agent Framework, MLflow, and Unity Catalog.
357
+
358
+ ## Prerequisites
359
+
360
+ 1. Install the Databricks CLI:
361
+ ```bash
362
+ brew tap databricks/tap
363
+ brew install databricks
364
+ ```
365
+ 2. Configure authentication:
366
+ ```bash
367
+ databricks auth login --host https://<workspace-id>.cloud.databricks.com
368
+ ```
369
+
370
+ ## Deploying with Databricks Asset Bundles (DAB)
371
+
372
+ Validate the bundle configuration:
373
+ ```bash
374
+ databricks bundle validate
375
+ ```
376
+
377
+ Run `src/{plan.package_name}/notebook.py` in your workspace first: it logs and registers the model, and the serving endpoint cannot be created until that model version exists. Then deploy with the version the notebook produced:
378
+ ```bash
379
+ databricks bundle deploy --var model_version=<n>
380
+ ```
381
+
382
+ ## Running the Notebook in Workspace
383
+
384
+ You can import `src/{plan.package_name}/notebook.py` directly into your Databricks workspace to log the model to Unity Catalog and view MLflow traces.
385
+ """
386
+ write_file(out_dir, "deployment.md", c)
387
+ return ["deployment.md"]
388
+
389
+
390
+ def _write_readme(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
391
+ c = f"""\
392
+ # {plan.project_name} — Databricks Mosaic AI
393
+
394
+ Generated by `agentsml-impl`.
395
+
396
+ This project targets Databricks Mosaic AI Agent Framework, MLflow Model Serving,
397
+ and Unity Catalog governance.
398
+
399
+ ## Architecture
400
+
401
+ - `src/{plan.package_name}/agent.py`: `mlflow.pyfunc.PythonModel` agent class with `@mlflow.trace` telemetry.
402
+ - `src/{plan.package_name}/notebook.py`: Exportable Databricks notebook for logging to Unity Catalog.
403
+ - `databricks.yml`: Databricks Asset Bundle (DAB) for automated deployment to Model Serving.
404
+ - `deployment.md`: Step-by-step Databricks deployment instructions.
405
+ - `src/{plan.package_name}/run.py`: Local execution runner.
406
+
407
+ ## Runtime behavior
408
+
409
+ `predict()` uses the Databricks OpenAI-compatible client when `databricks.sdk` is importable and
410
+ credentials resolve (`DATABRICKS_HOST`/`DATABRICKS_TOKEN` or a default SDK config); otherwise it
411
+ returns a deterministic echo with `fallback_reason`. Any other failure is returned (not raised)
412
+ as `{{"status": "error", "error": "<type>: <message>"}}`. Tool calls from the model are executed
413
+ once (single round) against `tools.py` and reported under `tool_results`.
414
+
415
+ ## Quickstart
416
+
417
+ ```bash
418
+ pip install -e .
419
+ python -m {plan.package_name}.run "Analyze data patterns"
420
+ ```
421
+
422
+ ## Deploying to Databricks
423
+
424
+ See [deployment.md](deployment.md) for details on deploying with Databricks Asset Bundles.
425
+ """
426
+ write_file(out_dir, "README.md", c)
427
+ return ["README.md"]
@@ -0,0 +1,26 @@
1
+ target: databricks
2
+ kind: code
3
+ language: python
4
+ status: implemented
5
+ level: 1
6
+ version_tested: "1.0.0"
7
+ supports:
8
+ agents: native
9
+ tools: native
10
+ workflows: lossy
11
+ graph_edges: lossy
12
+ graph_conditions: lossy
13
+ cycles: lossy
14
+ parallel: unsupported
15
+ human_approval: adapter
16
+ mcp: adapter
17
+ a2a: manual
18
+ ag_ui: unsupported
19
+ structured_output: manual
20
+ observability: native
21
+ artifacts:
22
+ - python_project
23
+ - diagnostics
24
+ - readme
25
+ notes: >
26
+ Maps to Databricks Mosaic AI Agent Framework.
File without changes
@@ -0,0 +1,71 @@
1
+ """Flowise target adapter — Level 1 code generation (JSON export)."""
2
+
3
+ from __future__ import annotations
4
+ import json
5
+ from pathlib import Path
6
+
7
+ from agentsml_impl.compiler.ir import AgentSystemIR, ModelIR
8
+ from agentsml_impl.compiler.diagnostics import DiagCode, DiagnosticSet
9
+ from agentsml_impl.compiler.planner import GenerationPlan
10
+ from agentsml_impl.compiler.render import write_file
11
+ from agentsml_impl.targets.base import TargetAdapter, GenerationResult
12
+
13
+
14
+ class Adapter(TargetAdapter):
15
+ @property
16
+ def name(self) -> str:
17
+ return "flowise"
18
+
19
+ def analyze(self, ir: AgentSystemIR, diagnostics: DiagnosticSet) -> None:
20
+ from agentsml_impl.compiler.capabilities import analyze_capabilities
21
+ analyze_capabilities(ir, "flowise", diagnostics)
22
+
23
+ def generate(self, ir: AgentSystemIR, plan: GenerationPlan,
24
+ out_dir: Path, diagnostics: DiagnosticSet) -> GenerationResult:
25
+ out_dir.mkdir(parents=True, exist_ok=True)
26
+
27
+ files: list[str] = []
28
+ files += _write_flowise_json(ir, plan, out_dir)
29
+ files += _write_readme(ir, plan, out_dir)
30
+
31
+ return GenerationResult(
32
+ target=self.name, out_dir=out_dir, files_written=files, success=True
33
+ )
34
+
35
+
36
+ def _write_flowise_json(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
37
+ nodes = []
38
+ for ak, agent in ir.agents.items():
39
+ nodes.append({
40
+ "id": f"agent_{ak}",
41
+ "type": "agent",
42
+ "data": {
43
+ "agentName": ak,
44
+ "systemMessage": agent.instructions
45
+ }
46
+ })
47
+
48
+ export = {
49
+ "nodes": nodes,
50
+ "edges": []
51
+ }
52
+
53
+ c = json.dumps(export, indent=2)
54
+ rel = "flowise.json"
55
+ write_file(out_dir, rel, c)
56
+ return [rel]
57
+
58
+
59
+ def _write_readme(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
60
+ c = f"""\
61
+ # {plan.project_name} — Flowise
62
+
63
+ Generated by `agentsml-impl`.
64
+
65
+ ## Quickstart
66
+ 1. Open Flowise UI
67
+ 2. Import Chatflow
68
+ 3. Upload `flowise.json`
69
+ """
70
+ write_file(out_dir, "README.md", c)
71
+ return ["README.md"]
@@ -0,0 +1,26 @@
1
+ target: flowise
2
+ kind: code
3
+ language: json
4
+ status: implemented
5
+ level: 1
6
+ version_tested: "1.0.0"
7
+ supports:
8
+ agents: native
9
+ tools: adapter
10
+ workflows: lossy
11
+ graph_edges: lossy
12
+ graph_conditions: lossy
13
+ cycles: lossy
14
+ parallel: lossy
15
+ human_approval: adapter
16
+ mcp: unsupported
17
+ a2a: manual
18
+ ag_ui: unsupported
19
+ structured_output: unsupported
20
+ observability: native
21
+ artifacts:
22
+ - json_export
23
+ - diagnostics
24
+ - readme
25
+ notes: >
26
+ Maps to Flowise JSON export.
File without changes