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,351 @@
1
+ """LangChain / LCEL target adapter — Level 1 code generation.
2
+
3
+ Generates LangChain LCEL (LangChain Expression Language) chains using:
4
+ - ChatOpenAI / ChatAnthropic / ChatGoogleGenerativeAI for models.
5
+ - @tool decorated functions.
6
+ - create_agent (LangChain 1.x) for tool-using agents.
7
+ - create_retrieval_chain + FAISS for RAG/knowledge.
8
+ - LCEL pipe operator (|) for sequential chains.
9
+ """
10
+
11
+ from __future__ import annotations
12
+ from pathlib import Path
13
+
14
+ from agentsml_impl.compiler.identifiers import python_identifier_ir
15
+ from agentsml_impl.compiler.ir import AgentSystemIR, ModelIR
16
+ from agentsml_impl.compiler.diagnostics import DiagCode, DiagnosticSet
17
+ from agentsml_impl.compiler.planner import GenerationPlan
18
+ from agentsml_impl.compiler.render import toml_string, write_file
19
+ from agentsml_impl.runtime.json_schema import generate_models_source
20
+ from agentsml_impl.targets.base import TargetAdapter, GenerationResult
21
+
22
+
23
+ class Adapter(TargetAdapter):
24
+ @property
25
+ def name(self) -> str:
26
+ return "langchain"
27
+
28
+ def analyze(self, ir: AgentSystemIR, diagnostics: DiagnosticSet) -> None:
29
+ from agentsml_impl.compiler.capabilities import analyze_capabilities
30
+ analyze_capabilities(ir, self.name, diagnostics)
31
+
32
+ def generate(self, ir: AgentSystemIR, plan: GenerationPlan,
33
+ out_dir: Path, diagnostics: DiagnosticSet) -> GenerationResult:
34
+ ir = python_identifier_ir(ir)
35
+ out_dir.mkdir(parents=True, exist_ok=True)
36
+ files: list[str] = []
37
+ files += _write_pyproject(ir, plan, out_dir)
38
+ files += _write_schemas(ir, out_dir, diagnostics)
39
+ files += _write_tools(ir, out_dir, diagnostics)
40
+ files += _write_agent(ir, plan, out_dir, diagnostics)
41
+ files += _write_run(ir, plan, out_dir)
42
+ files += _write_readme(ir, plan, out_dir)
43
+ return GenerationResult(target=self.name, out_dir=out_dir,
44
+ files_written=files, success=True)
45
+
46
+
47
+ # ---------------------------------------------------------------------------
48
+ # Model helpers
49
+ # ---------------------------------------------------------------------------
50
+
51
+ def _lc_model_init(model: ModelIR) -> tuple[str, str]:
52
+ """Return (import_line, llm_init_expr)."""
53
+ p = model.provider.lower()
54
+ n = model.name
55
+ if p == "openai":
56
+ return ("from langchain_openai import ChatOpenAI",
57
+ f'ChatOpenAI(model="{n}", temperature=0)')
58
+ if p == "anthropic":
59
+ return ("from langchain_anthropic import ChatAnthropic",
60
+ f'ChatAnthropic(model="{n}")')
61
+ if p in ("google", "gemini", "google-cloud", "google_cloud"):
62
+ return ("from langchain_google_genai import ChatGoogleGenerativeAI",
63
+ f'ChatGoogleGenerativeAI(model="{n}")')
64
+ if p in ("azure", "azure-openai"):
65
+ return ("from langchain_openai import AzureChatOpenAI",
66
+ f'AzureChatOpenAI(deployment_name="{n}")')
67
+ if p == "anthropic":
68
+ return ("from langchain_anthropic import ChatAnthropic",
69
+ f'ChatAnthropic(model="{n}")')
70
+ # Fallback: use OpenAI
71
+ return ("from langchain_openai import ChatOpenAI",
72
+ f'ChatOpenAI(model="{n}") # TODO: check provider {p!r}')
73
+
74
+
75
+ # ---------------------------------------------------------------------------
76
+ # File generators
77
+ # ---------------------------------------------------------------------------
78
+
79
+ def _write_pyproject(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
80
+ has_knowledge = any(a.knowledge for a in ir.agents.values())
81
+ rag_deps = ""
82
+ if has_knowledge:
83
+ rag_deps = """
84
+ "langchain-community>=0.4.0",
85
+ "faiss-cpu>=1.8.0",
86
+ "langchain-text-splitters","""
87
+
88
+ c = f'''\
89
+ [build-system]
90
+ requires = ["setuptools>=68"]
91
+ build-backend = "setuptools.build_meta"
92
+
93
+ [project]
94
+ name = "{plan.package_name}"
95
+ version = "{ir.metadata.version or '0.1.0'}"
96
+ description = {toml_string(ir.metadata.description or plan.project_name)}
97
+ requires-python = ">=3.11"
98
+ dependencies = [
99
+ "langchain>=1.0",
100
+ "langchain-openai>=1.0",
101
+ "langchain-anthropic>=1.0",
102
+ "langchain-google-genai>=3.0",
103
+ "langgraph>=1.0",
104
+ "pydantic>=2.7",
105
+ "python-dotenv",{rag_deps}
106
+ ]
107
+
108
+ [tool.setuptools.packages.find]
109
+ where = ["."]
110
+ '''
111
+ write_file(out_dir, "pyproject.toml", c)
112
+ return ["pyproject.toml"]
113
+
114
+
115
+ def _write_schemas(ir: AgentSystemIR, out_dir: Path, ds: DiagnosticSet) -> list[str]:
116
+ schemas = {f"{k}_output": v.output_schema for k, v in ir.agents.items() if v.output_schema}
117
+ if not schemas:
118
+ return []
119
+ c = generate_models_source(schemas, ds)
120
+ write_file(out_dir, "models.py", c)
121
+ return ["models.py"]
122
+
123
+
124
+ def _write_tools(ir: AgentSystemIR, out_dir: Path, ds: DiagnosticSet) -> list[str]:
125
+ if not ir.tools:
126
+ return []
127
+
128
+ lines = [
129
+ '"""LangChain tools — auto-generated by agentsml-impl."""',
130
+ "from __future__ import annotations",
131
+ "from typing import Any",
132
+ "from langchain_core.tools import tool",
133
+ "",
134
+ ]
135
+ for k, tool_ir in ir.tools.items():
136
+ desc = tool_ir.description.replace('"', '\\"')
137
+ lines.append(f'''\
138
+ @tool
139
+ def {k}(**kwargs: Any) -> Any:
140
+ """{desc}"""
141
+ # TODO: implement
142
+ raise NotImplementedError("{k}")
143
+ ''')
144
+
145
+ write_file(out_dir, "tools.py", "\n".join(lines))
146
+ return ["tools.py"]
147
+
148
+
149
+ def _write_agent(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path, ds: DiagnosticSet) -> list[str]:
150
+ wf = ir.workflows.get(plan.main_workflow_key)
151
+ steps = wf.steps if wf else []
152
+
153
+ llm_imports: set[str] = set()
154
+ llm_inits: list[str] = []
155
+ agent_defs: list[str] = []
156
+
157
+ model_vars: dict[str, str] = {}
158
+ for ak, agent in ir.agents.items():
159
+ model = ir.models.get(agent.model)
160
+ if model:
161
+ imp, expr = _lc_model_init(model)
162
+ llm_imports.add(imp)
163
+ else:
164
+ imp = "from langchain_openai import ChatOpenAI"
165
+ expr = "ChatOpenAI(model='gpt-4o', temperature=0)"
166
+ llm_imports.add(imp)
167
+
168
+ var = f"{ak}_llm"
169
+ model_vars[ak] = var
170
+ llm_inits.append(f"{var} = {expr}")
171
+
172
+ # Knowledge / RAG stubs
173
+ rag_stubs: list[str] = []
174
+ rag_tools: dict[str, str] = {} # agent_key -> rag tool var name
175
+ has_rag = any(a.knowledge for a in ir.agents.values())
176
+ for ak, agent in ir.agents.items():
177
+ if agent.knowledge:
178
+ ds.add_info(DiagCode.REQUIRES_ADAPTER,
179
+ f"Agent '{ak}' has knowledge config. Generated FAISS RAG retriever stub.",
180
+ path=f"agents.{ak}.knowledge")
181
+ rag_stubs.append(f'''\
182
+ # RAG retriever stub for {ak}
183
+ from langchain_community.vectorstores import FAISS
184
+ from langchain_openai import OpenAIEmbeddings
185
+ from langchain_core.tools import create_retriever_tool
186
+ {ak}_vectorstore = FAISS.from_texts(
187
+ ["placeholder — load your documents here"],
188
+ embedding=OpenAIEmbeddings()
189
+ )
190
+ {ak}_retriever = {ak}_vectorstore.as_retriever()
191
+ {ak}_retriever_tool = create_retriever_tool(
192
+ {ak}_retriever,
193
+ name="{ak}_knowledge",
194
+ description="Search {ak} knowledge base.",
195
+ )''')
196
+ rag_tools[ak] = f"{ak}_retriever_tool"
197
+
198
+ for ak, agent in ir.agents.items():
199
+ sys_prompt = agent.instructions.replace('"""', "'''")
200
+ tools_list_parts = []
201
+ if agent.tools:
202
+ tools_list_parts.extend(f"{t}" for t in agent.tools if t in ir.tools)
203
+ if ak in rag_tools:
204
+ tools_list_parts.append(rag_tools[ak])
205
+
206
+ tools_list = f"[{', '.join(tools_list_parts)}]" if tools_list_parts else "[]"
207
+
208
+ has_output = bool(agent.output_schema)
209
+ if has_output:
210
+ out_cls = f"{ak.capitalize()}Output"
211
+ if tools_list_parts:
212
+ ds.add_warning(
213
+ DiagCode.LOSSY_MAPPING,
214
+ f"agent '{ak}' declares both output_schema and tools; the generated "
215
+ "with_structured_output chain does not call tools",
216
+ path=f"agents.{ak}",
217
+ target="langchain",
218
+ )
219
+ agent_defs.append(f'''\
220
+ # Structured output agent (LCEL with_structured_output)
221
+ from langchain_core.prompts import ChatPromptTemplate
222
+ from .models import {out_cls}
223
+
224
+ {ak}_prompt = ChatPromptTemplate.from_messages([
225
+ ("system", """{sys_prompt}"""),
226
+ ("human", "{{input}}"),
227
+ ])
228
+ {ak}_chain = {ak}_prompt | {model_vars[ak]}.with_structured_output({out_cls})
229
+ ''')
230
+ elif tools_list_parts:
231
+ agent_defs.append(f'''\
232
+ # Tool-using agent (LangChain 1.x create_agent -> compiled graph)
233
+ from langchain.agents import create_agent
234
+
235
+ {ak}_agent = create_agent(
236
+ model={model_vars[ak]},
237
+ tools={tools_list},
238
+ system_prompt="""{sys_prompt}""",
239
+ )
240
+ ''')
241
+ else:
242
+ agent_defs.append(f'''\
243
+ # Simple LCEL chain
244
+ from langchain_core.prompts import ChatPromptTemplate
245
+ from langchain_core.output_parsers import StrOutputParser
246
+
247
+ {ak}_prompt = ChatPromptTemplate.from_messages([
248
+ ("system", """{sys_prompt}"""),
249
+ ("human", "{{input}}"),
250
+ ])
251
+ {ak}_chain = {ak}_prompt | {model_vars[ak]} | StrOutputParser()
252
+ ''')
253
+
254
+ tools_import = "from .tools import " + ", ".join(ir.tools.keys()) if ir.tools else ""
255
+ schemas_import = ("from .models import " +
256
+ ", ".join(f"{k.capitalize()}Output" for k, v in ir.agents.items() if v.output_schema)
257
+ if any(v.output_schema for v in ir.agents.values()) else "")
258
+
259
+ rag_section = "\n".join(rag_stubs) if rag_stubs else "# No RAG tools"
260
+
261
+ c = f'''\
262
+ """LangChain / LCEL agent definitions for {plan.project_name}.
263
+
264
+ Auto-generated by agentsml-impl. Re-run to regenerate.
265
+ """
266
+ from __future__ import annotations
267
+ from typing import Any
268
+ {chr(10).join(sorted(llm_imports))}
269
+ {tools_import}
270
+ {schemas_import}
271
+
272
+ # ── LLM instances ─────────────────────────────────────────────────────────────
273
+ {chr(10).join(llm_inits)}
274
+
275
+ # ── RAG retrievers ────────────────────────────────────────────────────────────
276
+ {rag_section}
277
+
278
+ # ── Agent / chain definitions ─────────────────────────────────────────────────
279
+ {chr(10).join(agent_defs)}
280
+ '''
281
+ write_file(out_dir, "agent.py", c)
282
+ return ["agent.py"]
283
+
284
+
285
+ def _write_run(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
286
+ primary = next(iter(ir.agents.keys()), None)
287
+ # Determine chain var
288
+ if primary:
289
+ agent = ir.agents[primary]
290
+ # Structured-output agents are always emitted as `<agent>_chain` (see _write_agent).
291
+ if not agent.output_schema and (agent.tools or agent.knowledge):
292
+ invoke_expr = f"{primary}_agent.invoke({{\"messages\": [(\"user\", q)]}})[\"messages\"][-1].content"
293
+ else:
294
+ invoke_expr = f"{primary}_chain.invoke({{\"input\": q}})"
295
+ else:
296
+ invoke_expr = "\"No agents defined\""
297
+
298
+ c = f'''\
299
+ """Runner for {plan.project_name} (LangChain). Auto-generated."""
300
+ from __future__ import annotations
301
+ import sys
302
+ from .agent import *
303
+
304
+
305
+ def main() -> None:
306
+ q = " ".join(sys.argv[1:]) or "Hello!"
307
+ result = {invoke_expr}
308
+ print(result)
309
+
310
+
311
+ if __name__ == "__main__":
312
+ main()
313
+ '''
314
+ write_file(out_dir, "run.py", c)
315
+ return ["run.py"]
316
+
317
+
318
+ def _write_readme(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
319
+ agents_md = "\n".join(f"- `{k}`: {v.description or ''}" for k, v in ir.agents.items())
320
+ c = f"""\
321
+ # {plan.project_name} — LangChain / LCEL
322
+
323
+ > Auto-generated by `agentsml-impl`.
324
+
325
+ ## Agents
326
+ {agents_md or "None"}
327
+
328
+ ## Architecture
329
+
330
+ - **Simple agents**: LCEL pipe chain (`prompt | llm | StrOutputParser()`)
331
+ - **Tool-using agents**: `langchain.agents.create_agent` (invoke with a `messages` list)
332
+ - **Structured output**: `llm.with_structured_output(PydanticModel)`
333
+ - **RAG**: FAISS vector store + `create_retriever_tool`
334
+
335
+ ## Quickstart
336
+ ```bash
337
+ pip install -e .
338
+ export OPENAI_API_KEY="your-key"
339
+ python run.py "Your question here"
340
+ ```
341
+
342
+ ## LangSmith Observability
343
+ ```bash
344
+ export LANGCHAIN_TRACING_V2=true
345
+ export LANGCHAIN_API_KEY="your-langsmith-key"
346
+ ```
347
+
348
+ > See `diagnostics.yaml` for portability warnings.
349
+ """
350
+ write_file(out_dir, "README.md", c)
351
+ return ["README.md"]
@@ -0,0 +1,30 @@
1
+ target: langchain
2
+ kind: code
3
+ language: python
4
+ status: implemented
5
+ level: 1
6
+ version_tested: "1.5.0"
7
+ supports:
8
+ agents: native
9
+ tools: native
10
+ workflows: lossy
11
+ graph_edges: lossy
12
+ graph_conditions: lossy
13
+ cycles: unsupported
14
+ parallel: unsupported
15
+ human_approval: unsupported
16
+ mcp: unsupported
17
+ a2a: unsupported
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 LangChain LCEL chains and create_agent (LangChain 1.x) for
27
+ tool-using agents. Structured output is generated with with_structured_output.
28
+ Observability is available through the LangChain/LangSmith runtime hooks.
29
+ profiles:
30
+ agentsml-rag: adapter
File without changes
@@ -0,0 +1,147 @@
1
+ """Langflow 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 "langflow"
18
+
19
+ def analyze(self, ir: AgentSystemIR, diagnostics: DiagnosticSet) -> None:
20
+ from agentsml_impl.compiler.capabilities import analyze_capabilities
21
+ analyze_capabilities(ir, "langflow", 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_langflow_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_langflow_json(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
37
+ nodes = []
38
+ edges = []
39
+ prev_node_id = None
40
+ x = 100
41
+
42
+ wf = ir.workflows.get(plan.main_workflow_key)
43
+ if wf and wf.steps:
44
+ for step in wf.steps:
45
+ agent = ir.agents.get(step.agent) if step.agent else None
46
+ instructions = agent.instructions if agent else f"Execute step {step.id}"
47
+ node_id = f"AgentNode-{step.id}"
48
+ nodes.append({
49
+ "id": node_id,
50
+ "type": "AgentNode",
51
+ "position": {"x": x, "y": 200},
52
+ "data": {
53
+ "id": node_id,
54
+ "type": "AgentNode",
55
+ "node": {
56
+ "display_name": step.id,
57
+ "description": instructions,
58
+ "template": {
59
+ "instructions": {"value": instructions}
60
+ }
61
+ }
62
+ }
63
+ })
64
+ if prev_node_id:
65
+ edges.append({
66
+ "id": f"reactflow__edge-{prev_node_id}-{node_id}",
67
+ "source": prev_node_id,
68
+ "target": node_id,
69
+ "data": {
70
+ "sourceHandle": {"dataType": "AgentNode", "id": prev_node_id, "name": "response"},
71
+ "targetHandle": {"dataType": "AgentNode", "id": node_id, "name": "input"}
72
+ }
73
+ })
74
+ prev_node_id = node_id
75
+ x += 300
76
+ else:
77
+ for ak, agent in ir.agents.items():
78
+ node_id = f"AgentNode-{ak}"
79
+ nodes.append({
80
+ "id": node_id,
81
+ "type": "AgentNode",
82
+ "position": {"x": x, "y": 200},
83
+ "data": {
84
+ "id": node_id,
85
+ "type": "AgentNode",
86
+ "node": {
87
+ "display_name": ak,
88
+ "description": agent.instructions,
89
+ "template": {
90
+ "instructions": {"value": agent.instructions}
91
+ }
92
+ }
93
+ }
94
+ })
95
+ if prev_node_id:
96
+ edges.append({
97
+ "id": f"reactflow__edge-{prev_node_id}-{node_id}",
98
+ "source": prev_node_id,
99
+ "target": node_id,
100
+ "data": {
101
+ "sourceHandle": {"dataType": "AgentNode", "id": prev_node_id, "name": "response"},
102
+ "targetHandle": {"dataType": "AgentNode", "id": node_id, "name": "input"}
103
+ }
104
+ })
105
+ prev_node_id = node_id
106
+ x += 300
107
+
108
+ export = {
109
+ "name": plan.project_name,
110
+ "description": ir.metadata.description or "Exported from AgentsML",
111
+ "data": {
112
+ "nodes": nodes,
113
+ "edges": edges,
114
+ "viewport": {"x": 0, "y": 0, "zoom": 1}
115
+ }
116
+ }
117
+
118
+ c = json.dumps(export, indent=2)
119
+ rel = "langflow.json"
120
+ write_file(out_dir, rel, c)
121
+ return [rel]
122
+
123
+
124
+ def _write_readme(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
125
+ c = f"""\
126
+ # {plan.project_name} — Langflow Workflow
127
+
128
+ Generated by `agentsml-impl`.
129
+
130
+ ## Overview
131
+ This export produces a Langflow flow JSON definition conforming to the official Langflow flow graph schema.
132
+
133
+ ## Import Options
134
+
135
+ ### 1. Langflow Web UI
136
+ 1. Open Langflow.
137
+ 2. Go to **Projects** and click **Upload a flow** (or drag and drop `langflow.json`).
138
+
139
+ ### 2. Langflow API
140
+ ```bash
141
+ curl -X POST "http://localhost:7860/api/v1/flows/upload/" \\
142
+ -H "accept: application/json" \\
143
+ -F "file=@langflow.json"
144
+ ```
145
+ """
146
+ write_file(out_dir, "README.md", c)
147
+ return ["README.md"]
@@ -0,0 +1,26 @@
1
+ target: langflow
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 Langflow JSON export.
File without changes