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,3 @@
1
+ """AgentsML IR-first compiler package."""
2
+
3
+ __version__ = "0.2.0"
agentsml_impl/cli.py ADDED
@@ -0,0 +1,472 @@
1
+ """CORE-010: CLI — agentsml-impl command line interface."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from pathlib import Path
6
+ from typing import Optional
7
+
8
+ import typer
9
+ from rich.console import Console
10
+ from rich.table import Table
11
+ from rich import box
12
+
13
+ app = typer.Typer(
14
+ name="agentsml-impl",
15
+ help="AgentsML IR-first compiler — validate, diagnose, and generate target-specific agent code.",
16
+ no_args_is_help=True,
17
+ )
18
+ console = Console()
19
+ err_console = Console(stderr=True)
20
+
21
+
22
+ def _load_ir(input_path: Path, schema_path: Optional[Path] = None):
23
+ """Load, validate, and convert an AgentsML file to IR. Returns (ir, diagnostics) or raises SystemExit."""
24
+ from agentsml_impl.compiler.diagnostics import DiagnosticSet
25
+ from agentsml_impl.compiler.loader import load_yaml, LoadError
26
+ from agentsml_impl.compiler.schema_validation import validate_schema
27
+ from agentsml_impl.compiler.ir import AgentSystemIR
28
+
29
+ ds = DiagnosticSet()
30
+ try:
31
+ doc = load_yaml(input_path, ds)
32
+ except LoadError as exc:
33
+ err_console.print(f"[red]Load error:[/] {exc}")
34
+ raise typer.Exit(1)
35
+
36
+ if ds.has_fatal():
37
+ _print_diagnostics(ds)
38
+ raise typer.Exit(1)
39
+
40
+ validate_schema(doc, ds, schema_path)
41
+ if ds.has_fatal():
42
+ _print_diagnostics(ds)
43
+ raise typer.Exit(1)
44
+
45
+ ir = AgentSystemIR.from_dict(doc)
46
+ return ir, ds
47
+
48
+
49
+ def _print_diagnostics(ds) -> None:
50
+ from agentsml_impl.compiler.diagnostics import Severity
51
+ for d in ds.sorted():
52
+ color = {"fatal": "red", "error": "red", "warning": "yellow", "info": "blue"}.get(d.severity.value, "white")
53
+ loc = f" [dim]({d.path})[/]" if d.path else ""
54
+ console.print(f" [{color}]{d.severity.value.upper()}[/] [{d.code.value}]{loc}: {d.message}")
55
+ if d.recommendation:
56
+ console.print(f" [dim]→ {d.recommendation}[/]")
57
+
58
+
59
+ @app.command("list-targets")
60
+ def cmd_list_targets():
61
+ """List all registered compilation targets."""
62
+ from agentsml_impl.targets.registry import list_targets
63
+ targets = list_targets()
64
+
65
+ table = Table(title="AgentsML Compilation Targets", box=box.ROUNDED)
66
+ table.add_column("Target", style="cyan")
67
+ table.add_column("Language", style="green")
68
+ table.add_column("Wave", justify="right")
69
+ table.add_column("Level", justify="right")
70
+ table.add_column("Maturity")
71
+ table.add_column("Certification")
72
+
73
+ for t in targets:
74
+ level_color = "green" if t["level"] >= 1 else "yellow"
75
+ table.add_row(
76
+ t["name"],
77
+ t["language"],
78
+ str(t["wave"]),
79
+ f"[{level_color}]{t['level']}[/{level_color}]",
80
+ t["maturity"],
81
+ t["certification"],
82
+ )
83
+ console.print(table)
84
+ console.print(f"\n[dim]{len(targets)} targets registered.[/]")
85
+
86
+
87
+ @app.command("validate")
88
+ def cmd_validate(
89
+ input: Path = typer.Argument(..., help="Path to AgentsML YAML file."),
90
+ schema: Optional[Path] = typer.Option(None, "--schema", help="Path to agentsml.schema.json."),
91
+ ):
92
+ """Validate an AgentsML document (schema + semantic checks)."""
93
+ from agentsml_impl.compiler.semantic_validation import validate_semantics
94
+
95
+ console.print(f"[bold]Validating[/] {input}")
96
+ ir, ds = _load_ir(input, schema)
97
+
98
+ validate_semantics(ir, ds)
99
+
100
+ _print_diagnostics(ds)
101
+
102
+ if ds.has_errors():
103
+ console.print(f"\n[red]✗ Validation failed[/] — {ds.summary()}")
104
+ raise typer.Exit(1)
105
+
106
+ console.print(f"\n[green]✓ Valid[/] — {ds.summary()}")
107
+ console.print(f" agents={len(ir.agents)}, tools={len(ir.tools)}, workflows={len(ir.workflows)}")
108
+
109
+
110
+ @app.command("doctor")
111
+ def cmd_doctor(
112
+ input: Path = typer.Argument(..., help="Path to AgentsML YAML file."),
113
+ target: str = typer.Option(..., "--target", "-t", help="Target name (e.g. langgraph)."),
114
+ schema: Optional[Path] = typer.Option(None, "--schema"),
115
+ ):
116
+ """Analyze an AgentsML document for a specific target and show capability report."""
117
+ from agentsml_impl.compiler.semantic_validation import validate_semantics
118
+ from agentsml_impl.compiler.capabilities import analyze_capabilities, load_capabilities
119
+ from agentsml_impl.targets.registry import get_target
120
+
121
+ console.print(f"[bold]Doctor:[/] {input} → [cyan]{target}[/]")
122
+ ir, ds = _load_ir(input, schema)
123
+ validate_semantics(ir, ds)
124
+
125
+ caps = analyze_capabilities(ir, target, ds)
126
+
127
+ _print_diagnostics(ds)
128
+
129
+ tgt_info = get_target(target)
130
+ if tgt_info:
131
+ console.print(f"\nTarget wave [bold]{tgt_info['wave']}[/], implementation level [bold]{tgt_info['level']}[/]")
132
+
133
+ if caps.get("supports"):
134
+ table = Table(title=f"{target} capability summary", box=box.SIMPLE)
135
+ table.add_column("Feature")
136
+ table.add_column("Support")
137
+ for feat, val in caps["supports"].items():
138
+ color = {"native": "green", "adapter": "yellow", "manual": "yellow",
139
+ "lossy": "red", "unsupported": "red"}.get(str(val), "white")
140
+ table.add_row(feat, f"[{color}]{val}[/{color}]")
141
+ console.print(table)
142
+
143
+ status = "[green]✓[/]" if not ds.has_errors() else "[yellow]⚠[/]"
144
+ console.print(f"\n{status} Doctor complete — {ds.summary()}")
145
+
146
+
147
+ @app.command("generate")
148
+ def cmd_generate(
149
+ input: Path = typer.Argument(..., help="Path to AgentsML YAML file."),
150
+ target: str = typer.Option(..., "--target", "-t", help="Target name."),
151
+ out: Path = typer.Option(Path("generated"), "--out", "-o", help="Output directory."),
152
+ schema: Optional[Path] = typer.Option(None, "--schema"),
153
+ dry_run: bool = typer.Option(False, "--dry-run", help="Print files without writing."),
154
+ overwrite: bool = typer.Option(True, "--overwrite/--no-overwrite"),
155
+ ):
156
+ """Generate target-specific artifacts from an AgentsML document."""
157
+ from agentsml_impl.compiler.semantic_validation import validate_semantics
158
+ from agentsml_impl.compiler.capabilities import analyze_capabilities
159
+ from agentsml_impl.compiler.planner import build_plan
160
+ from agentsml_impl.compiler.render import write_file
161
+ from agentsml_impl.targets.registry import get_target, target_dir_name
162
+ from agentsml_impl.targets.base import StubAdapter
163
+ import importlib
164
+
165
+ console.print(f"[bold]Generate:[/] {input} → [cyan]{target}[/] → {out}")
166
+ ir, ds = _load_ir(input, schema)
167
+ validate_semantics(ir, ds)
168
+ analyze_capabilities(ir, target, ds)
169
+ plan = build_plan(ir, target, ds)
170
+
171
+ out_dir = out / plan.package_name / target
172
+ out_dir.mkdir(parents=True, exist_ok=True)
173
+
174
+ # Try to load the real adapter; fall back to stub
175
+ adapter = None
176
+ try:
177
+ module = importlib.import_module(f"agentsml_impl.targets.{target_dir_name(target)}.adapter")
178
+ adapter = module.Adapter()
179
+ except (ImportError, AttributeError):
180
+ adapter = StubAdapter(target)
181
+
182
+ if not dry_run:
183
+ result = adapter.generate(ir, plan, out_dir, ds)
184
+ _print_diagnostics(ds)
185
+ # Always write final diagnostics
186
+ write_file(out_dir, "diagnostics.yaml", ds.to_yaml(), overwrite=overwrite)
187
+ console.print(f"\n[green]✓ Generated[/] {len(result.files_written)} files → {out_dir}")
188
+ for f in result.files_written:
189
+ console.print(f" {f}")
190
+ else:
191
+ console.print("[dim](dry-run — no files written)[/]")
192
+ _print_diagnostics(ds)
193
+
194
+
195
+ @app.command("generate-all")
196
+ def cmd_generate_all(
197
+ input: Path = typer.Argument(..., help="Path to AgentsML YAML file."),
198
+ targets: str = typer.Option(..., "--targets", help="Comma-separated target list."),
199
+ out: Path = typer.Option(Path("generated"), "--out", "-o"),
200
+ schema: Optional[Path] = typer.Option(None, "--schema"),
201
+ ):
202
+ """Generate artifacts for multiple targets at once."""
203
+ target_list = [t.strip() for t in targets.split(",") if t.strip()]
204
+ for t in target_list:
205
+ console.rule(f"[cyan]{t}[/]")
206
+ ctx = typer.Context(cmd_generate)
207
+ cmd_generate(input=input, target=t, out=out, schema=schema, dry_run=False, overwrite=True)
208
+
209
+
210
+ @app.command("explain-target")
211
+ def cmd_explain_target(
212
+ target: str = typer.Argument(..., help="Target name to explain."),
213
+ ):
214
+ """Show detailed information about a target."""
215
+ from agentsml_impl.targets.registry import get_target
216
+ from agentsml_impl.compiler.capabilities import load_capabilities
217
+
218
+ info = get_target(target)
219
+ if not info:
220
+ err_console.print(f"[red]Unknown target:[/] {target}")
221
+ raise typer.Exit(1)
222
+
223
+ caps = load_capabilities(target)
224
+ console.print(f"\n[bold cyan]{target}[/]")
225
+ console.print(f" Language: {info['language']}")
226
+ console.print(f" Wave: {info['wave']} | Level: {info['level']}")
227
+ if caps.get("supports"):
228
+ table = Table(box=box.SIMPLE)
229
+ table.add_column("Feature")
230
+ table.add_column("Support")
231
+ for feat, val in caps["supports"].items():
232
+ table.add_row(feat, str(val))
233
+ console.print(table)
234
+ else:
235
+ console.print(" [dim]No capabilities file found.[/]")
236
+
237
+
238
+ # ---------------------------------------------------------------------------
239
+ # Developer Experience: compile, graph, run
240
+ # ---------------------------------------------------------------------------
241
+
242
+ def _render_mermaid_graph(ir, workflow_filter: Optional[str] = None) -> str:
243
+ lines = ["flowchart TD"]
244
+ workflows = ir.workflows
245
+ if workflow_filter:
246
+ workflows = {k: v for k, v in workflows.items() if k == workflow_filter}
247
+ if not workflows:
248
+ return f"%% Workflow '{workflow_filter}' not found"
249
+
250
+ if workflows:
251
+ for w_key, wf in workflows.items():
252
+ lines.append(f' subgraph wf_{w_key}["Workflow: {w_key}"]')
253
+ for s in wf.steps:
254
+ label = s.id
255
+ if s.agent:
256
+ label += f"\\n(Agent: {s.agent})"
257
+ elif s.tool:
258
+ label += f"\\n(Tool: {s.tool})"
259
+ elif s.workflow:
260
+ label += f"\\n(Sub-workflow: {s.workflow})"
261
+ elif s.approval:
262
+ label += f"\\n[Human Approval]"
263
+
264
+ if s.approval:
265
+ lines.append(f' {s.id}{{"{label}"}}')
266
+ else:
267
+ lines.append(f' {s.id}["{label}"]')
268
+
269
+ if wf.edges:
270
+ for e in wf.edges:
271
+ if e.condition:
272
+ cond_label = e.label or str(e.condition)
273
+ lines.append(f' {e.from_step} -->|"{cond_label}"| {e.to_step}')
274
+ elif e.label:
275
+ lines.append(f' {e.from_step} -->|"{e.label}"| {e.to_step}')
276
+ else:
277
+ lines.append(f' {e.from_step} --> {e.to_step}')
278
+ elif any(s.depends_on for s in wf.steps):
279
+ for s in wf.steps:
280
+ for dep in s.depends_on:
281
+ lines.append(f' {dep} --> {s.id}')
282
+ else:
283
+ for i in range(len(wf.steps) - 1):
284
+ lines.append(f' {wf.steps[i].id} --> {wf.steps[i+1].id}')
285
+ lines.append(" end")
286
+ else:
287
+ lines.append(f' subgraph agents_graph["Agents in {ir.metadata.name}"]')
288
+ for ak, agent in ir.agents.items():
289
+ lines.append(f' agent_{ak}["Agent: {ak}\\nModel: {agent.model}"]')
290
+ for t in agent.tools:
291
+ lines.append(f' tool_{t}["Tool: {t}"]')
292
+ lines.append(f' agent_{ak} -.-> tool_{t}')
293
+ lines.append(" end")
294
+
295
+ return "\n".join(lines)
296
+
297
+
298
+ def _render_ascii_graph(ir, workflow_filter: Optional[str] = None) -> str:
299
+ lines = [f"AgentsML Execution Graph: {ir.metadata.name}", "=" * 50]
300
+ workflows = ir.workflows
301
+ if workflow_filter:
302
+ workflows = {k: v for k, v in workflows.items() if k == workflow_filter}
303
+ if not workflows:
304
+ return f"Workflow '{workflow_filter}' not found"
305
+
306
+ if workflows:
307
+ for w_key, wf in workflows.items():
308
+ lines.append(f"\nWorkflow: {w_key}")
309
+ if wf.description:
310
+ lines.append(f" Description: {wf.description}")
311
+ lines.append(" Steps:")
312
+ for i, s in enumerate(wf.steps):
313
+ prefix = " ├──" if i < len(wf.steps) - 1 else " └──"
314
+ target_str = f"agent={s.agent}" if s.agent else (f"tool={s.tool}" if s.tool else "approval" if s.approval else "step")
315
+ lines.append(f"{prefix} [{s.id}] ({target_str})")
316
+ if s.agent and s.agent in ir.agents:
317
+ agent = ir.agents[s.agent]
318
+ if agent.tools:
319
+ lines.append(f" │ tools: {', '.join(agent.tools)}")
320
+ if s.depends_on:
321
+ lines.append(f" │ depends_on: {', '.join(s.depends_on)}")
322
+ if wf.edges:
323
+ lines.append(" Edges:")
324
+ for e in wf.edges:
325
+ cond = f" [if {e.condition}]" if e.condition else ""
326
+ lines.append(f" {e.from_step} ──>{cond} {e.to_step}")
327
+ else:
328
+ lines.append("\nAgents:")
329
+ for ak, agent in ir.agents.items():
330
+ lines.append(f" [{ak}] model={agent.model}")
331
+ if agent.tools:
332
+ lines.append(f" tools: {', '.join(agent.tools)}")
333
+
334
+ return "\n".join(lines)
335
+
336
+
337
+ @app.command("compile")
338
+ def cmd_compile(
339
+ input: Path = typer.Argument(..., help="Path to AgentsML YAML file."),
340
+ target: str = typer.Option(..., "--target", "-t", help="Target name (e.g. langgraph, mastra)."),
341
+ out: Path = typer.Option(Path("generated"), "--out", "-o", help="Output directory."),
342
+ schema: Optional[Path] = typer.Option(None, "--schema", help="Optional schema path."),
343
+ dry_run: bool = typer.Option(False, "--dry-run", help="Print files without writing."),
344
+ overwrite: bool = typer.Option(True, "--overwrite/--no-overwrite"),
345
+ ):
346
+ """Compile an AgentsML document to target-specific agent code (alias for generate)."""
347
+ return cmd_generate(
348
+ input=input,
349
+ target=target,
350
+ out=out,
351
+ schema=schema,
352
+ dry_run=dry_run,
353
+ overwrite=overwrite,
354
+ )
355
+
356
+
357
+ @app.command("graph")
358
+ def cmd_graph(
359
+ input: Path = typer.Argument(..., help="Path to AgentsML YAML file."),
360
+ format: str = typer.Option("mermaid", "--format", "-f", help="Output format: mermaid or ascii."),
361
+ workflow: Optional[str] = typer.Option(None, "--workflow", "-w", help="Workflow name to graph."),
362
+ out: Optional[Path] = typer.Option(None, "--out", "-o", help="Optional output file."),
363
+ schema: Optional[Path] = typer.Option(None, "--schema"),
364
+ ):
365
+ """Render a visual execution graph (Mermaid flowchart or ASCII DAG) from an AgentsML document."""
366
+ ir, ds = _load_ir(input, schema)
367
+ fmt = format.lower()
368
+ if fmt == "mermaid":
369
+ rendered = _render_mermaid_graph(ir, workflow)
370
+ elif fmt == "ascii":
371
+ rendered = _render_ascii_graph(ir, workflow)
372
+ else:
373
+ err_console.print(f"[red]Unsupported format:[/] {format}. Choose 'mermaid' or 'ascii'.")
374
+ raise typer.Exit(1)
375
+
376
+ if out:
377
+ out.parent.mkdir(parents=True, exist_ok=True)
378
+ out.write_text(rendered, encoding="utf-8")
379
+ console.print(f"[green]✓ Graph written to[/] {out}")
380
+ else:
381
+ console.print(rendered, markup=False)
382
+
383
+
384
+ @app.command("run")
385
+ def cmd_run(
386
+ input: Path = typer.Argument(..., help="Path to AgentsML YAML file."),
387
+ target: str = typer.Option(..., "--target", "-t", help="Target name (e.g. langgraph, mastra)."),
388
+ query: str = typer.Option("Hello!", "--query", "-q", help="Input query to run."),
389
+ out: Path = typer.Option(Path("generated"), "--out", "-o", help="Output directory."),
390
+ schema: Optional[Path] = typer.Option(None, "--schema"),
391
+ ):
392
+ """Compile an AgentsML document and execute the target runner."""
393
+ import os
394
+ import shutil
395
+ import subprocess
396
+ import sys
397
+ from agentsml_impl.targets.registry import get_target
398
+ from agentsml_impl.compiler.planner import build_plan
399
+ from agentsml_impl.compiler.semantic_validation import validate_semantics
400
+ from agentsml_impl.compiler.capabilities import analyze_capabilities
401
+
402
+ ir, ds = _load_ir(input, schema)
403
+ validate_semantics(ir, ds)
404
+ analyze_capabilities(ir, target, ds)
405
+ plan = build_plan(ir, target, ds)
406
+
407
+ # First compile
408
+ cmd_generate(input=input, target=target, out=out, schema=schema, dry_run=False, overwrite=True)
409
+
410
+ target_dir = out / plan.package_name / target
411
+ tgt_info = get_target(target) or {}
412
+ maturity = tgt_info.get("maturity", "runnable")
413
+
414
+ if maturity == "export":
415
+ console.print(f"\n[cyan]Target '{target}' is an export target. Artifacts generated in {target_dir}.[/]")
416
+ return
417
+
418
+ console.rule(f"[bold green]Running {target}[/]")
419
+
420
+ lang = tgt_info.get("language", "python")
421
+ if lang == "python":
422
+ runner_candidates = [
423
+ target_dir / "src" / plan.package_name / "run.py",
424
+ target_dir / plan.package_name / "run.py",
425
+ target_dir / "src" / plan.package_name / "main.py",
426
+ target_dir / plan.package_name / "main.py",
427
+ target_dir / "run.py",
428
+ ]
429
+ runner_path = next((p for p in runner_candidates if p.exists()), None)
430
+ if not runner_path:
431
+ err_console.print(f"[red]No executable entrypoint found in {target_dir}[/]")
432
+ raise typer.Exit(1)
433
+
434
+ env = os.environ.copy()
435
+ pythonpath = [str(target_dir / "src"), str(target_dir)]
436
+ if "PYTHONPATH" in env:
437
+ pythonpath.append(env["PYTHONPATH"])
438
+ env["PYTHONPATH"] = os.pathsep.join(pythonpath)
439
+
440
+ cmd = [sys.executable, str(runner_path), query]
441
+ console.print(f"[dim]Executing: {' '.join(cmd)}[/]\n")
442
+ res = subprocess.run(cmd, env=env)
443
+ if res.returncode != 0:
444
+ raise typer.Exit(res.returncode)
445
+
446
+ elif lang == "typescript":
447
+ node_path = shutil.which("node")
448
+ if not node_path:
449
+ err_console.print("[red]Node.js is required to run TypeScript targets.[/]")
450
+ raise typer.Exit(1)
451
+
452
+ index_candidates = [
453
+ target_dir / "src" / "index.ts",
454
+ target_dir / "src" / "index.js",
455
+ target_dir / "index.ts",
456
+ ]
457
+ index_path = next((p for p in index_candidates if p.exists()), None)
458
+ if not index_path:
459
+ err_console.print(f"[red]No index entrypoint found in {target_dir}[/]")
460
+ raise typer.Exit(1)
461
+
462
+ cmd = [node_path, "--experimental-strip-types", str(index_path), query]
463
+ console.print(f"[dim]Executing: {' '.join(cmd)}[/]\n")
464
+ res = subprocess.run(cmd, cwd=str(target_dir))
465
+ if res.returncode != 0:
466
+ raise typer.Exit(res.returncode)
467
+ else:
468
+ console.print(f"[yellow]Automated runner not configured for language '{lang}'. See {target_dir}/README.md[/]")
469
+
470
+
471
+ if __name__ == "__main__":
472
+ app()
@@ -0,0 +1 @@
1
+ """Compiler package."""