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,123 @@
1
+ """AG-UI target adapter — Level 1 code generation."""
2
+
3
+ from __future__ import annotations
4
+ from pathlib import Path
5
+
6
+ from agentsml_impl.compiler.ir import AgentSystemIR
7
+ from agentsml_impl.compiler.diagnostics import DiagCode, DiagnosticSet
8
+ from agentsml_impl.compiler.planner import GenerationPlan
9
+ from agentsml_impl.compiler.render import write_file
10
+ from agentsml_impl.targets.base import TargetAdapter, GenerationResult
11
+
12
+
13
+ class Adapter(TargetAdapter):
14
+ @property
15
+ def name(self) -> str:
16
+ return "ag-ui"
17
+
18
+ def analyze(self, ir: AgentSystemIR, diagnostics: DiagnosticSet) -> None:
19
+ pass
20
+
21
+ def generate(self, ir: AgentSystemIR, plan: GenerationPlan,
22
+ out_dir: Path, diagnostics: DiagnosticSet) -> GenerationResult:
23
+ out_dir.mkdir(parents=True, exist_ok=True)
24
+ pkg = plan.package_name
25
+ src = out_dir / "src" / pkg
26
+ src.mkdir(parents=True, exist_ok=True)
27
+
28
+ files: list[str] = []
29
+ files += _write_pyproject(ir, plan, out_dir)
30
+ files += _write_server(ir, plan, src, out_dir)
31
+ files += _write_init(src, out_dir)
32
+ files += _write_readme(ir, plan, out_dir)
33
+
34
+ return GenerationResult(
35
+ target=self.name, out_dir=out_dir, files_written=files, success=True
36
+ )
37
+
38
+
39
+ def _write_pyproject(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
40
+ c = f'''\
41
+ [build-system]
42
+ requires = ["setuptools>=68"]
43
+ build-backend = "setuptools.build_meta"
44
+
45
+ [project]
46
+ name = "{plan.package_name}-agui"
47
+ version = "{ir.metadata.version or '0.1.0'}"
48
+ description = "AG-UI Event Bridge for {plan.project_name}"
49
+ requires-python = ">=3.11"
50
+ dependencies = [
51
+ "fastapi",
52
+ "uvicorn",
53
+ "sse-starlette"
54
+ ]
55
+
56
+ [tool.setuptools.packages.find]
57
+ where = ["src"]
58
+ '''
59
+ write_file(out_dir, "pyproject.toml", c)
60
+ return ["pyproject.toml"]
61
+
62
+
63
+ def _write_server(ir: AgentSystemIR, plan: GenerationPlan, src: Path, out_dir: Path) -> list[str]:
64
+ c = f'''\
65
+ """AG-UI Event Bridge for {plan.project_name}."""
66
+ from __future__ import annotations
67
+ import asyncio
68
+ import json
69
+ from fastapi import FastAPI, Request
70
+ from sse_starlette.sse import EventSourceResponse
71
+
72
+ app = FastAPI(title="AG-UI Bridge: {plan.project_name}")
73
+
74
+ async def event_generator():
75
+ """Mock generator emitting AG-UI protocol events."""
76
+ events = [
77
+ {{"type": "run_start", "run_id": "run-1"}},
78
+ {{"type": "step_start", "step_id": "step-1", "agent": "default"}},
79
+ {{"type": "message", "content": "Hello from {plan.project_name}!"}},
80
+ {{"type": "step_end", "step_id": "step-1"}},
81
+ {{"type": "run_end", "run_id": "run-1"}}
82
+ ]
83
+ for ev in events:
84
+ yield {{"data": json.dumps(ev)}}
85
+ await asyncio.sleep(1)
86
+
87
+ @app.get("/stream")
88
+ async def stream(request: Request):
89
+ """SSE Endpoint for AG-UI."""
90
+ return EventSourceResponse(event_generator())
91
+
92
+ def main():
93
+ import uvicorn
94
+ uvicorn.run(app, host="0.0.0.0", port=8000)
95
+
96
+ if __name__ == "__main__":
97
+ main()
98
+ '''
99
+ rel = f"src/{src.name}/server.py"
100
+ write_file(out_dir, rel, c)
101
+ return [rel]
102
+
103
+ def _write_init(src: Path, out_dir: Path) -> list[str]:
104
+ c = f'"""Package: {src.name}."""\n'
105
+ rel = f"src/{src.name}/__init__.py"
106
+ write_file(out_dir, rel, c)
107
+ return [rel]
108
+
109
+ def _write_readme(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
110
+ c = f"""\
111
+ # {plan.project_name} — AG-UI Event Bridge
112
+
113
+ Generated by `agentsml-impl`.
114
+
115
+ ## Quickstart
116
+ ```bash
117
+ pip install -e .
118
+ python -m {plan.package_name}.server
119
+ ```
120
+ Connect your AG-UI frontend to `http://localhost:8000/stream`.
121
+ """
122
+ write_file(out_dir, "README.md", c)
123
+ return ["README.md"]
@@ -0,0 +1,25 @@
1
+ target: ag_ui
2
+ kind: protocol
3
+ language: python
4
+ status: implemented
5
+ level: 1
6
+ version_tested: "1.0.0"
7
+ supports:
8
+ agents: unsupported
9
+ tools: unsupported
10
+ workflows: unsupported
11
+ graph_edges: unsupported
12
+ graph_conditions: unsupported
13
+ cycles: unsupported
14
+ parallel: unsupported
15
+ human_approval: unsupported
16
+ mcp: unsupported
17
+ a2a: unsupported
18
+ ag_ui: native
19
+ structured_output: unsupported
20
+ observability: unsupported
21
+ artifacts:
22
+ - python_project
23
+ - readme
24
+ notes: >
25
+ Generates an AG-UI Event Bridge scaffold for streaming UI states.
File without changes
@@ -0,0 +1,191 @@
1
+ """Agno target adapter — Level 1 code generation."""
2
+
3
+ from __future__ import annotations
4
+ from pathlib import Path
5
+
6
+ from agentsml_impl.compiler.identifiers import python_identifier_ir
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 toml_string, write_file
11
+ from agentsml_impl.runtime.tools import generate_tools_module
12
+ from agentsml_impl.targets.base import TargetAdapter, GenerationResult
13
+
14
+
15
+ class Adapter(TargetAdapter):
16
+ @property
17
+ def name(self) -> str:
18
+ return "agno"
19
+
20
+ def analyze(self, ir: AgentSystemIR, diagnostics: DiagnosticSet) -> None:
21
+ from agentsml_impl.compiler.capabilities import analyze_capabilities
22
+ analyze_capabilities(ir, self.name, diagnostics)
23
+
24
+ def generate(self, ir: AgentSystemIR, plan: GenerationPlan,
25
+ out_dir: Path, diagnostics: DiagnosticSet) -> GenerationResult:
26
+ ir = python_identifier_ir(ir)
27
+ out_dir.mkdir(parents=True, exist_ok=True)
28
+ pkg = plan.package_name
29
+ src = out_dir / "src" / pkg
30
+ src.mkdir(parents=True, exist_ok=True)
31
+
32
+ files: list[str] = []
33
+ files += _write_pyproject(ir, plan, out_dir)
34
+ files += _write_tools(ir, src, out_dir, diagnostics)
35
+ files += _write_agent(ir, plan, src, out_dir, diagnostics)
36
+ files += _write_run(plan, src, out_dir)
37
+ files += _write_init(src, out_dir)
38
+ files += _write_readme(ir, plan, out_dir)
39
+
40
+ return GenerationResult(
41
+ target=self.name, out_dir=out_dir, files_written=files, success=True
42
+ )
43
+
44
+
45
+ def _model_str(model: ModelIR) -> str:
46
+ p = model.provider.lower()
47
+ n = model.name
48
+ if p == "openai":
49
+ return f'OpenAIChat(id="{n}")'
50
+ if p in ("google", "gemini"):
51
+ return f'Gemini(id="{n}")'
52
+ if p == "anthropic":
53
+ return f'Claude(id="{n}")'
54
+ return f'OpenAIChat(id="{n}")'
55
+
56
+ def _provider_imports(ir: AgentSystemIR) -> str:
57
+ imports = set()
58
+ for ak, agent in ir.agents.items():
59
+ m = ir.models.get(agent.model)
60
+ if m:
61
+ p = m.provider.lower()
62
+ if p == "openai":
63
+ imports.add("from agno.models.openai import OpenAIChat")
64
+ elif p in ("google", "gemini"):
65
+ imports.add("from agno.models.google import Gemini")
66
+ elif p == "anthropic":
67
+ imports.add("from agno.models.anthropic import Claude")
68
+ else:
69
+ imports.add("from agno.models.openai import OpenAIChat")
70
+ return "\n".join(sorted(imports))
71
+
72
+ def _write_pyproject(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
73
+ c = f'''\
74
+ [build-system]
75
+ requires = ["setuptools>=68"]
76
+ build-backend = "setuptools.build_meta"
77
+
78
+ [project]
79
+ name = "{plan.package_name}"
80
+ version = "{ir.metadata.version or '0.1.0'}"
81
+ description = {toml_string(ir.metadata.description or plan.project_name)}
82
+ requires-python = ">=3.11"
83
+ dependencies = [
84
+ "agno",
85
+ "python-dotenv"
86
+ ]
87
+
88
+ [tool.setuptools.packages.find]
89
+ where = ["src"]
90
+ '''
91
+ write_file(out_dir, "pyproject.toml", c)
92
+ return ["pyproject.toml"]
93
+
94
+
95
+ def _write_tools(ir: AgentSystemIR, src: Path, out_dir: Path, ds: DiagnosticSet) -> list[str]:
96
+ if not ir.tools:
97
+ return []
98
+ c = generate_tools_module(ir.tools, ds, framework="agno")
99
+ rel = f"src/{src.name}/tools.py"
100
+ write_file(out_dir, rel, c)
101
+ return [rel]
102
+
103
+
104
+ def _write_agent(ir: AgentSystemIR, plan: GenerationPlan, src: Path, out_dir: Path, ds: DiagnosticSet) -> list[str]:
105
+ agent_blocks: list[str] = []
106
+ tools_import = f"from .tools import {', '.join(ir.tools.keys())}" if ir.tools else ""
107
+ prov_imports = _provider_imports(ir)
108
+
109
+ for ak, agent in ir.agents.items():
110
+ m = ir.models.get(agent.model)
111
+ mstr = _model_str(m) if m else 'OpenAIChat(id="gpt-4o")'
112
+ inst = agent.instructions.replace('"""', "'''")
113
+ tools_list = ", ".join(agent.tools) if agent.tools else ""
114
+
115
+ agent_blocks.append(f'''\
116
+ {ak}_agent = Agent(
117
+ name="{ak}",
118
+ model={mstr},
119
+ description="""{inst}""",
120
+ tools=[{tools_list}],
121
+ markdown=True
122
+ )''')
123
+
124
+ wf = ir.workflows.get(plan.main_workflow_key)
125
+ if wf and wf.edges:
126
+ ds.add_warning(
127
+ DiagCode.LOSSY_MAPPING,
128
+ "Workflow edges are mapped as manual logic.",
129
+ path=f"workflows.{plan.main_workflow_key}.edges"
130
+ )
131
+
132
+ c = f'''\
133
+ """Agno (Phidata) definitions for {plan.project_name}."""
134
+ from __future__ import annotations
135
+ from agno.agent import Agent
136
+ {prov_imports}
137
+ {tools_import}
138
+
139
+ {chr(10).join(agent_blocks)}
140
+ '''
141
+ rel = f"src/{src.name}/agent.py"
142
+ write_file(out_dir, rel, c)
143
+ return [rel]
144
+
145
+
146
+ def _write_run(plan: GenerationPlan, src: Path, out_dir: Path) -> list[str]:
147
+ c = f'''\
148
+ """Runner for {plan.project_name} (Agno)."""
149
+ from __future__ import annotations
150
+ import sys
151
+ from .agent import *
152
+
153
+ def main():
154
+ q = " ".join(sys.argv[1:]) or "Hello"
155
+ agents = [v for k, v in globals().items() if k.endswith("_agent")]
156
+ start_agent = agents[0] if agents else None
157
+
158
+ if not start_agent:
159
+ print("No agents found.")
160
+ return
161
+
162
+ start_agent.print_response(q, stream=True)
163
+
164
+ if __name__ == "__main__":
165
+ main()
166
+ '''
167
+ rel = f"src/{src.name}/run.py"
168
+ write_file(out_dir, rel, c)
169
+ return [rel]
170
+
171
+ def _write_init(src: Path, out_dir: Path) -> list[str]:
172
+ c = f'"""Package: {src.name}."""\n'
173
+ rel = f"src/{src.name}/__init__.py"
174
+ write_file(out_dir, rel, c)
175
+ return [rel]
176
+
177
+ def _write_readme(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
178
+ c = f"""\
179
+ # {plan.project_name} — Agno (Phidata)
180
+
181
+ Generated by `agentsml-impl`.
182
+
183
+ ## Quickstart
184
+ ```bash
185
+ pip install -e .
186
+ export OPENAI_API_KEY="your-key"
187
+ python -m {plan.package_name}.run
188
+ ```
189
+ """
190
+ write_file(out_dir, "README.md", c)
191
+ return ["README.md"]
@@ -0,0 +1,26 @@
1
+ target: agno
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: manual
13
+ cycles: lossy
14
+ parallel: unsupported
15
+ human_approval: adapter
16
+ mcp: adapter
17
+ a2a: manual
18
+ ag_ui: adapter
19
+ structured_output: manual
20
+ observability: native
21
+ artifacts:
22
+ - python_project
23
+ - diagnostics
24
+ - readme
25
+ notes: >
26
+ Maps to Agno (formerly Phidata).
File without changes
@@ -0,0 +1,84 @@
1
+ """AP2 target adapter — Level 1 code generation."""
2
+
3
+ from __future__ import annotations
4
+ from pathlib import Path
5
+ import json
6
+
7
+ from agentsml_impl.compiler.ir import AgentSystemIR
8
+ from agentsml_impl.compiler.diagnostics import 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 "ap2"
18
+
19
+ def analyze(self, ir: AgentSystemIR, diagnostics: DiagnosticSet) -> None:
20
+ pass
21
+
22
+ def generate(self, ir: AgentSystemIR, plan: GenerationPlan,
23
+ out_dir: Path, diagnostics: DiagnosticSet) -> GenerationResult:
24
+ out_dir.mkdir(parents=True, exist_ok=True)
25
+
26
+ files: list[str] = []
27
+ files += _write_ap2(ir, plan, out_dir)
28
+ files += _write_readme(ir, plan, out_dir)
29
+
30
+ return GenerationResult(
31
+ target=self.name, out_dir=out_dir, files_written=files, success=True
32
+ )
33
+
34
+
35
+ def _payment_currencies(ir: AgentSystemIR) -> list[str]:
36
+ currencies: set[str] = set()
37
+ for tool in ir.tools.values():
38
+ if tool.side_effect != "payment" or not tool.input_schema:
39
+ continue
40
+ properties = tool.input_schema.get("properties", {})
41
+ currency = properties.get("currency")
42
+ if not isinstance(currency, dict):
43
+ continue
44
+ if isinstance(currency.get("const"), str):
45
+ currencies.add(currency["const"])
46
+ enum = currency.get("enum")
47
+ if isinstance(enum, list):
48
+ currencies.update(value for value in enum if isinstance(value, str))
49
+ if isinstance(currency.get("default"), str):
50
+ currencies.add(currency["default"])
51
+ return sorted(currencies)
52
+
53
+
54
+ def _write_ap2(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
55
+ payment_tools = [t.key for t in ir.tools.values() if t.side_effect == "payment"]
56
+ currencies = _payment_currencies(ir)
57
+
58
+ ap2_card = {
59
+ "protocol": "AP2 (Agent-to-Agent Payments)",
60
+ "version": "1.0",
61
+ "entity": plan.project_name,
62
+ "mandate": {
63
+ "authorized_tools": payment_tools,
64
+ "max_amount": "0.00",
65
+ "currency": currencies[0] if len(currencies) == 1 else None,
66
+ }
67
+ }
68
+
69
+ rel = "ap2-mandate.json"
70
+ write_file(out_dir, rel, json.dumps(ap2_card, indent=2))
71
+ return [rel]
72
+
73
+
74
+ def _write_readme(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
75
+ c = f"""\
76
+ # {plan.project_name} — AP2 Export
77
+
78
+ Generated by `agentsml-impl`.
79
+
80
+ ## AP2 Mandate
81
+ The `ap2-mandate.json` file describes your payment execution bounds.
82
+ """
83
+ write_file(out_dir, "README.md", c)
84
+ return ["README.md"]
@@ -0,0 +1,25 @@
1
+ target: ap2
2
+ kind: protocol
3
+ language: json
4
+ status: implemented
5
+ level: 1
6
+ version_tested: "1.0.0"
7
+ supports:
8
+ agents: unsupported
9
+ tools: unsupported
10
+ workflows: unsupported
11
+ graph_edges: unsupported
12
+ graph_conditions: unsupported
13
+ cycles: unsupported
14
+ parallel: unsupported
15
+ human_approval: unsupported
16
+ mcp: unsupported
17
+ a2a: unsupported
18
+ ag_ui: unsupported
19
+ structured_output: unsupported
20
+ observability: unsupported
21
+ artifacts:
22
+ - json_export
23
+ - readme
24
+ notes: >
25
+ Generates an AP2 Payment Mandate.
@@ -0,0 +1,157 @@
1
+ """Base adapter protocol — contract all target adapters must implement."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from abc import ABC, abstractmethod
6
+ from dataclasses import dataclass, field
7
+ from pathlib import Path
8
+ from typing import Any, Literal, Optional
9
+
10
+ from agentsml_impl.compiler.diagnostics import DiagnosticSet
11
+ from agentsml_impl.compiler.ir import AgentSystemIR
12
+ from agentsml_impl.compiler.planner import GenerationPlan
13
+
14
+ TargetMaturity = Literal["runnable", "export", "scaffold"]
15
+ _MATURITY_VALUES: tuple[TargetMaturity, ...] = ("runnable", "export", "scaffold")
16
+
17
+
18
+ def _default_target_maturity(target: str) -> TargetMaturity:
19
+ from agentsml_impl.targets.registry import get_target_maturity
20
+
21
+ return get_target_maturity(target)
22
+
23
+
24
+ @dataclass
25
+ class GenerationResult:
26
+ target: str
27
+ out_dir: Path
28
+ files_written: list[str] = field(default_factory=list)
29
+ diagnostics_path: Optional[str] = None
30
+ success: bool = True
31
+ maturity: Optional[TargetMaturity] = None
32
+
33
+ def __post_init__(self) -> None:
34
+ if self.maturity is None:
35
+ self.maturity = _default_target_maturity(self.target)
36
+ elif self.maturity not in _MATURITY_VALUES:
37
+ allowed = ", ".join(_MATURITY_VALUES)
38
+ raise ValueError(f"Unsupported maturity {self.maturity!r}; expected one of {allowed}.")
39
+
40
+ if self.maturity == "scaffold":
41
+ self.success = False
42
+
43
+ @property
44
+ def is_runnable(self) -> bool:
45
+ return self.maturity == "runnable"
46
+
47
+ @property
48
+ def is_export(self) -> bool:
49
+ return self.maturity == "export"
50
+
51
+ @property
52
+ def is_scaffold(self) -> bool:
53
+ return self.maturity == "scaffold"
54
+
55
+
56
+ class TargetAdapter(ABC):
57
+ """Abstract base class for all AgentsML target adapters."""
58
+
59
+ @property
60
+ def maturity(self) -> TargetMaturity:
61
+ """Canonical maturity for this adapter."""
62
+ from agentsml_impl.targets.registry import get_target_maturity
63
+
64
+ return get_target_maturity(self.name)
65
+
66
+ @property
67
+ @abstractmethod
68
+ def name(self) -> str:
69
+ """Canonical target name, e.g. 'langgraph'."""
70
+
71
+ def load_capabilities(self) -> dict[str, Any]:
72
+ """Load capabilities.yaml for this target. Returns {} if not found."""
73
+ from agentsml_impl.compiler.capabilities import load_capabilities
74
+
75
+ return load_capabilities(self.name)
76
+
77
+ @abstractmethod
78
+ def analyze(self, ir: AgentSystemIR, diagnostics: DiagnosticSet) -> None:
79
+ """Run target-specific analysis against IR and emit diagnostics."""
80
+
81
+ @abstractmethod
82
+ def generate(
83
+ self,
84
+ ir: AgentSystemIR,
85
+ plan: GenerationPlan,
86
+ out_dir: Path,
87
+ diagnostics: DiagnosticSet,
88
+ ) -> GenerationResult:
89
+ """Generate all artifacts into out_dir. Return result with file list."""
90
+
91
+
92
+ class StubAdapter(TargetAdapter):
93
+ """Stub adapter used for unimplemented targets — emits target_not_implemented."""
94
+
95
+ def __init__(self, target_name: str) -> None:
96
+ self._name = target_name
97
+
98
+ @property
99
+ def name(self) -> str:
100
+ return self._name
101
+
102
+ @property
103
+ def maturity(self) -> TargetMaturity:
104
+ return "scaffold"
105
+
106
+ def analyze(self, ir: AgentSystemIR, diagnostics: DiagnosticSet) -> None:
107
+ from agentsml_impl.compiler.diagnostics import DiagCode
108
+
109
+ diagnostics.add_warning(
110
+ DiagCode.TARGET_NOT_IMPLEMENTED,
111
+ f"Target '{self.name}' adapter is not yet implemented. Scaffold only.",
112
+ target=self.name,
113
+ recommendation="Check the agentsml-impl roadmap for implementation wave.",
114
+ )
115
+
116
+ def generate(
117
+ self,
118
+ ir: AgentSystemIR,
119
+ plan: GenerationPlan,
120
+ out_dir: Path,
121
+ diagnostics: DiagnosticSet,
122
+ ) -> GenerationResult:
123
+ from agentsml_impl.compiler.diagnostics import DiagCode
124
+ from agentsml_impl.compiler.render import write_file
125
+
126
+ diagnostics.add_warning(
127
+ DiagCode.TARGET_NOT_IMPLEMENTED,
128
+ f"Target '{self.name}' is not yet implemented. Generated scaffold only.",
129
+ target=self.name,
130
+ )
131
+
132
+ out_dir.mkdir(parents=True, exist_ok=True)
133
+ files: list[str] = []
134
+
135
+ # Always write diagnostics.yaml
136
+ diag_path = "diagnostics.yaml"
137
+ write_file(out_dir, diag_path, diagnostics.to_yaml())
138
+ files.append(diag_path)
139
+
140
+ # Write a minimal README
141
+ readme = (
142
+ f"# {plan.project_name} — {self.name}\n\n"
143
+ f"> **Note**: Target `{self.name}` is not yet implemented.\n"
144
+ f"> This directory contains a scaffold only.\n\n"
145
+ f"See `diagnostics.yaml` for details.\n"
146
+ )
147
+ write_file(out_dir, "README.md", readme)
148
+ files.append("README.md")
149
+
150
+ return GenerationResult(
151
+ target=self.name,
152
+ out_dir=out_dir,
153
+ files_written=files,
154
+ diagnostics_path=diag_path,
155
+ success=False,
156
+ maturity=self.maturity,
157
+ )
File without changes