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.
- agentsml_impl/__init__.py +3 -0
- agentsml_impl/cli.py +472 -0
- agentsml_impl/compiler/__init__.py +1 -0
- agentsml_impl/compiler/capabilities.py +330 -0
- agentsml_impl/compiler/conditions.py +177 -0
- agentsml_impl/compiler/diagnostics.py +112 -0
- agentsml_impl/compiler/durations.py +31 -0
- agentsml_impl/compiler/expressions.py +123 -0
- agentsml_impl/compiler/identifiers.py +60 -0
- agentsml_impl/compiler/ir.py +391 -0
- agentsml_impl/compiler/limits.py +28 -0
- agentsml_impl/compiler/loader.py +83 -0
- agentsml_impl/compiler/naming.py +87 -0
- agentsml_impl/compiler/planner.py +79 -0
- agentsml_impl/compiler/render.py +90 -0
- agentsml_impl/compiler/schema_validation.py +121 -0
- agentsml_impl/compiler/semantic_validation.py +424 -0
- agentsml_impl/protocols/__init__.py +1 -0
- agentsml_impl/runtime/__init__.py +1 -0
- agentsml_impl/runtime/events.py +59 -0
- agentsml_impl/runtime/json_schema.py +138 -0
- agentsml_impl/runtime/tools.py +145 -0
- agentsml_impl/schemas/agentsml.schema.json +406 -0
- agentsml_impl/schemas/v0.1/agentsml.schema.json +628 -0
- agentsml_impl/schemas/v0.2/agentsml.schema.json +363 -0
- agentsml_impl/schemas/v0.3/agentsml.schema.json +406 -0
- agentsml_impl/targets/__init__.py +1 -0
- agentsml_impl/targets/a2a/__init__.py +0 -0
- agentsml_impl/targets/a2a/adapter.py +94 -0
- agentsml_impl/targets/a2a/capabilities.yaml +25 -0
- agentsml_impl/targets/ag2/__init__.py +0 -0
- agentsml_impl/targets/ag2/adapter.py +655 -0
- agentsml_impl/targets/ag2/capabilities.yaml +37 -0
- agentsml_impl/targets/ag_ui/__init__.py +0 -0
- agentsml_impl/targets/ag_ui/adapter.py +123 -0
- agentsml_impl/targets/ag_ui/capabilities.yaml +25 -0
- agentsml_impl/targets/agno/__init__.py +0 -0
- agentsml_impl/targets/agno/adapter.py +191 -0
- agentsml_impl/targets/agno/capabilities.yaml +26 -0
- agentsml_impl/targets/ap2/__init__.py +0 -0
- agentsml_impl/targets/ap2/adapter.py +84 -0
- agentsml_impl/targets/ap2/capabilities.yaml +25 -0
- agentsml_impl/targets/base.py +157 -0
- agentsml_impl/targets/bedrock_agentcore/__init__.py +0 -0
- agentsml_impl/targets/bedrock_agentcore/adapter.py +592 -0
- agentsml_impl/targets/bedrock_agentcore/capabilities.yaml +26 -0
- agentsml_impl/targets/claude_agent_sdk/__init__.py +0 -0
- agentsml_impl/targets/claude_agent_sdk/adapter.py +178 -0
- agentsml_impl/targets/claude_agent_sdk/capabilities.yaml +26 -0
- agentsml_impl/targets/crewai/__init__.py +0 -0
- agentsml_impl/targets/crewai/adapter.py +441 -0
- agentsml_impl/targets/crewai/capabilities.yaml +30 -0
- agentsml_impl/targets/databricks/__init__.py +0 -0
- agentsml_impl/targets/databricks/adapter.py +427 -0
- agentsml_impl/targets/databricks/capabilities.yaml +26 -0
- agentsml_impl/targets/flowise/__init__.py +0 -0
- agentsml_impl/targets/flowise/adapter.py +71 -0
- agentsml_impl/targets/flowise/capabilities.yaml +26 -0
- agentsml_impl/targets/google_adk/__init__.py +0 -0
- agentsml_impl/targets/google_adk/adapter.py +589 -0
- agentsml_impl/targets/google_adk/capabilities.yaml +36 -0
- agentsml_impl/targets/langchain/__init__.py +1 -0
- agentsml_impl/targets/langchain/adapter.py +351 -0
- agentsml_impl/targets/langchain/capabilities.yaml +30 -0
- agentsml_impl/targets/langflow/__init__.py +0 -0
- agentsml_impl/targets/langflow/adapter.py +147 -0
- agentsml_impl/targets/langflow/capabilities.yaml +26 -0
- agentsml_impl/targets/langgraph/__init__.py +0 -0
- agentsml_impl/targets/langgraph/adapter.py +911 -0
- agentsml_impl/targets/langgraph/capabilities.yaml +33 -0
- agentsml_impl/targets/llamaindex/__init__.py +1 -0
- agentsml_impl/targets/llamaindex/adapter.py +406 -0
- agentsml_impl/targets/llamaindex/capabilities.yaml +31 -0
- agentsml_impl/targets/lyzr/__init__.py +0 -0
- agentsml_impl/targets/lyzr/adapter.py +146 -0
- agentsml_impl/targets/lyzr/capabilities.yaml +26 -0
- agentsml_impl/targets/mastra/__init__.py +0 -0
- agentsml_impl/targets/mastra/adapter.py +635 -0
- agentsml_impl/targets/mastra/capabilities.yaml +32 -0
- agentsml_impl/targets/mcp_server/__init__.py +0 -0
- agentsml_impl/targets/mcp_server/adapter.py +141 -0
- agentsml_impl/targets/mcp_server/capabilities.yaml +25 -0
- agentsml_impl/targets/microsoft_agent_framework/__init__.py +0 -0
- agentsml_impl/targets/microsoft_agent_framework/adapter.py +563 -0
- agentsml_impl/targets/microsoft_agent_framework/capabilities.yaml +26 -0
- agentsml_impl/targets/n8n/__init__.py +0 -0
- agentsml_impl/targets/n8n/adapter.py +139 -0
- agentsml_impl/targets/n8n/capabilities.yaml +26 -0
- agentsml_impl/targets/openai_agents/__init__.py +0 -0
- agentsml_impl/targets/openai_agents/adapter.py +175 -0
- agentsml_impl/targets/openai_agents/capabilities.yaml +27 -0
- agentsml_impl/targets/pydantic_ai/__init__.py +0 -0
- agentsml_impl/targets/pydantic_ai/adapter.py +922 -0
- agentsml_impl/targets/pydantic_ai/capabilities.yaml +37 -0
- agentsml_impl/targets/registry.py +290 -0
- agentsml_impl/targets/relevance_ai/__init__.py +0 -0
- agentsml_impl/targets/relevance_ai/adapter.py +66 -0
- agentsml_impl/targets/relevance_ai/capabilities.yaml +26 -0
- agentsml_impl/targets/smolagents/__init__.py +0 -0
- agentsml_impl/targets/smolagents/adapter.py +210 -0
- agentsml_impl/targets/smolagents/capabilities.yaml +27 -0
- agentsml_impl/targets/snowflake_cortex/__init__.py +0 -0
- agentsml_impl/targets/snowflake_cortex/adapter.py +167 -0
- agentsml_impl/targets/snowflake_cortex/capabilities.yaml +26 -0
- agentsml_impl/targets/spring_ai/__init__.py +1 -0
- agentsml_impl/targets/spring_ai/adapter.py +626 -0
- agentsml_impl/targets/spring_ai/capabilities.yaml +31 -0
- agentsml_impl/targets/strands_agents/__init__.py +1 -0
- agentsml_impl/targets/strands_agents/adapter.py +309 -0
- agentsml_impl/targets/strands_agents/capabilities.yaml +29 -0
- agentsml_impl/targets/support_matrix.py +91 -0
- agentsml_impl/targets/ucp/__init__.py +0 -0
- agentsml_impl/targets/ucp/adapter.py +86 -0
- agentsml_impl/targets/ucp/capabilities.yaml +25 -0
- agentsml_impl/targets/vercel_ai/__init__.py +1 -0
- agentsml_impl/targets/vercel_ai/adapter.py +349 -0
- agentsml_impl/targets/vercel_ai/capabilities.yaml +30 -0
- agentsml_impl/targets/vertex_agent_engine/__init__.py +0 -0
- agentsml_impl/targets/vertex_agent_engine/adapter.py +407 -0
- agentsml_impl/targets/vertex_agent_engine/capabilities.yaml +26 -0
- agentsml_impl/targets/zapier_agents/__init__.py +0 -0
- agentsml_impl/targets/zapier_agents/adapter.py +106 -0
- agentsml_impl/targets/zapier_agents/capabilities.yaml +26 -0
- agentsml_impl-0.2.0.dist-info/METADATA +109 -0
- agentsml_impl-0.2.0.dist-info/RECORD +129 -0
- agentsml_impl-0.2.0.dist-info/WHEEL +5 -0
- agentsml_impl-0.2.0.dist-info/entry_points.txt +3 -0
- agentsml_impl-0.2.0.dist-info/licenses/LICENSE +28 -0
- agentsml_impl-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
target: langgraph
|
|
2
|
+
kind: code
|
|
3
|
+
language: python
|
|
4
|
+
status: implemented
|
|
5
|
+
level: 1
|
|
6
|
+
version_tested: "1.2.20"
|
|
7
|
+
supports:
|
|
8
|
+
agents: native
|
|
9
|
+
tools: native
|
|
10
|
+
workflows: native
|
|
11
|
+
graph_edges: native
|
|
12
|
+
graph_conditions: native
|
|
13
|
+
cycles: native
|
|
14
|
+
parallel: native
|
|
15
|
+
human_approval: native
|
|
16
|
+
tool_approval: native
|
|
17
|
+
mcp: adapter
|
|
18
|
+
a2a: manual
|
|
19
|
+
ag_ui: adapter
|
|
20
|
+
structured_output: adapter
|
|
21
|
+
retry: native
|
|
22
|
+
on_timeout: native
|
|
23
|
+
reasoning: adapter
|
|
24
|
+
observability: adapter
|
|
25
|
+
artifacts:
|
|
26
|
+
- python_project
|
|
27
|
+
- diagnostics
|
|
28
|
+
- readme
|
|
29
|
+
notes: >
|
|
30
|
+
LangGraph maps AgentsML workflow steps to StateGraph nodes and edges.
|
|
31
|
+
Interrupt/resume maps to human approval. ToolNode handles tool dispatch.
|
|
32
|
+
MCP requires LangChain MCP adapter. A2A requires external wrapper.
|
|
33
|
+
Observability via LangSmith or OpenTelemetry adapter.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Target: llamaindex."""
|
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
"""LlamaIndex target adapter — Level 1 code generation.
|
|
2
|
+
|
|
3
|
+
Uses the preferred 2025 LlamaIndex multi-agent API:
|
|
4
|
+
- AgentWorkflow + FunctionAgent (replaces deprecated ReActAgent).
|
|
5
|
+
- ConcurrentFlow for parallel steps.
|
|
6
|
+
- VectorStoreIndex + QueryEngineTool for knowledge/RAG.
|
|
7
|
+
- ToolSpec grouping when agent has many tools.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
from agentsml_impl.compiler.identifiers import python_identifier_ir
|
|
14
|
+
from agentsml_impl.compiler.ir import AgentSystemIR, ModelIR
|
|
15
|
+
from agentsml_impl.compiler.diagnostics import DiagCode, DiagnosticSet
|
|
16
|
+
from agentsml_impl.compiler.planner import GenerationPlan
|
|
17
|
+
from agentsml_impl.compiler.render import toml_string, write_file
|
|
18
|
+
from agentsml_impl.runtime.json_schema import generate_models_source
|
|
19
|
+
from agentsml_impl.targets.base import TargetAdapter, GenerationResult
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class Adapter(TargetAdapter):
|
|
23
|
+
@property
|
|
24
|
+
def name(self) -> str:
|
|
25
|
+
return "llamaindex"
|
|
26
|
+
|
|
27
|
+
def analyze(self, ir: AgentSystemIR, diagnostics: DiagnosticSet) -> None:
|
|
28
|
+
from agentsml_impl.compiler.capabilities import analyze_capabilities
|
|
29
|
+
analyze_capabilities(ir, self.name, diagnostics)
|
|
30
|
+
for mk, model in ir.models.items():
|
|
31
|
+
p = model.provider.lower()
|
|
32
|
+
if p not in ("openai", "anthropic", "google", "gemini", "google-cloud",
|
|
33
|
+
"google_cloud", "azure", "azure-openai"):
|
|
34
|
+
diagnostics.add_warning(
|
|
35
|
+
DiagCode.LOSSY_MAPPING,
|
|
36
|
+
f"Model '{mk}' provider '{model.provider}' may need a custom LlamaIndex LLM wrapper.",
|
|
37
|
+
path=f"models.{mk}.provider",
|
|
38
|
+
recommendation="Use OpenAI, Anthropic, or Gemini providers for best LlamaIndex support.",
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
def generate(self, ir: AgentSystemIR, plan: GenerationPlan,
|
|
42
|
+
out_dir: Path, diagnostics: DiagnosticSet) -> GenerationResult:
|
|
43
|
+
ir = python_identifier_ir(ir)
|
|
44
|
+
out_dir.mkdir(parents=True, exist_ok=True)
|
|
45
|
+
files: list[str] = []
|
|
46
|
+
files += _write_pyproject(ir, plan, out_dir)
|
|
47
|
+
files += _write_schemas(ir, out_dir, diagnostics)
|
|
48
|
+
files += _write_tools(ir, out_dir, diagnostics)
|
|
49
|
+
files += _write_agent(ir, plan, out_dir, diagnostics)
|
|
50
|
+
files += _write_run(ir, plan, out_dir)
|
|
51
|
+
files += _write_init(out_dir)
|
|
52
|
+
files += _write_readme(ir, plan, out_dir)
|
|
53
|
+
return GenerationResult(target=self.name, out_dir=out_dir,
|
|
54
|
+
files_written=files, success=True)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# ---------------------------------------------------------------------------
|
|
58
|
+
# Model helpers
|
|
59
|
+
# ---------------------------------------------------------------------------
|
|
60
|
+
|
|
61
|
+
def _llm_init(model: ModelIR) -> tuple[str, str]:
|
|
62
|
+
"""Return (import_line, llm_init_expr)."""
|
|
63
|
+
p = model.provider.lower()
|
|
64
|
+
n = model.name
|
|
65
|
+
if p == "openai":
|
|
66
|
+
return ("from llama_index.llms.openai import OpenAI",
|
|
67
|
+
f'OpenAI(model="{n}")')
|
|
68
|
+
if p == "anthropic":
|
|
69
|
+
return ("from llama_index.llms.anthropic import Anthropic",
|
|
70
|
+
f'Anthropic(model="{n}")')
|
|
71
|
+
if p in ("google", "gemini", "google-cloud", "google_cloud"):
|
|
72
|
+
return ("from llama_index.llms.google_genai import GoogleGenAI",
|
|
73
|
+
f'GoogleGenAI(model="{n}")')
|
|
74
|
+
if p in ("azure", "azure-openai"):
|
|
75
|
+
return ("from llama_index.llms.azure_openai import AzureOpenAI",
|
|
76
|
+
f'AzureOpenAI(engine="{n}") # set AZURE_OPENAI_* env vars')
|
|
77
|
+
# Fallback
|
|
78
|
+
return ("from llama_index.llms.openai import OpenAI",
|
|
79
|
+
f'OpenAI(model="{n}") # TODO: check provider {p!r}')
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
# ---------------------------------------------------------------------------
|
|
83
|
+
# File generators
|
|
84
|
+
# ---------------------------------------------------------------------------
|
|
85
|
+
|
|
86
|
+
def _write_pyproject(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
|
|
87
|
+
has_knowledge = any(a.knowledge for a in ir.agents.values())
|
|
88
|
+
rag_deps = ""
|
|
89
|
+
if has_knowledge:
|
|
90
|
+
rag_deps = """
|
|
91
|
+
"llama-index-vector-stores-faiss",
|
|
92
|
+
"llama-index-embeddings-openai","""
|
|
93
|
+
|
|
94
|
+
c = f'''\
|
|
95
|
+
[build-system]
|
|
96
|
+
requires = ["setuptools>=68"]
|
|
97
|
+
build-backend = "setuptools.build_meta"
|
|
98
|
+
|
|
99
|
+
[project]
|
|
100
|
+
name = "{plan.package_name}"
|
|
101
|
+
version = "{ir.metadata.version or '0.1.0'}"
|
|
102
|
+
description = {toml_string(ir.metadata.description or plan.project_name)}
|
|
103
|
+
requires-python = ">=3.11"
|
|
104
|
+
dependencies = [
|
|
105
|
+
"llama-index>=0.11.0",
|
|
106
|
+
"llama-index-agent-openai",
|
|
107
|
+
"llama-index-llms-openai",
|
|
108
|
+
"llama-index-llms-anthropic",
|
|
109
|
+
"python-dotenv",
|
|
110
|
+
"pydantic>=2.7",{rag_deps}
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
[tool.setuptools.packages.find]
|
|
114
|
+
where = ["."]
|
|
115
|
+
'''
|
|
116
|
+
write_file(out_dir, "pyproject.toml", c)
|
|
117
|
+
return ["pyproject.toml"]
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _write_schemas(ir: AgentSystemIR, out_dir: Path, ds: DiagnosticSet) -> list[str]:
|
|
121
|
+
schemas = {f"{k}_output": v.output_schema for k, v in ir.agents.items() if v.output_schema}
|
|
122
|
+
if not schemas:
|
|
123
|
+
return []
|
|
124
|
+
c = generate_models_source(schemas, ds)
|
|
125
|
+
write_file(out_dir, "models.py", c)
|
|
126
|
+
return ["models.py"]
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _write_tools(ir: AgentSystemIR, out_dir: Path, ds: DiagnosticSet) -> list[str]:
|
|
130
|
+
if not ir.tools:
|
|
131
|
+
return []
|
|
132
|
+
|
|
133
|
+
lines = [
|
|
134
|
+
'"""LlamaIndex tool stubs — auto-generated by agentsml-impl."""',
|
|
135
|
+
"from __future__ import annotations",
|
|
136
|
+
"from typing import Any",
|
|
137
|
+
"from llama_index.core.tools import FunctionTool",
|
|
138
|
+
"",
|
|
139
|
+
]
|
|
140
|
+
tool_names: list[str] = []
|
|
141
|
+
for k, tool in ir.tools.items():
|
|
142
|
+
desc = tool.description.replace('"', '\\"')
|
|
143
|
+
lines.append(f'''\
|
|
144
|
+
def _{k}_impl(**kwargs: Any) -> Any:
|
|
145
|
+
"""{desc}"""
|
|
146
|
+
# TODO: implement
|
|
147
|
+
raise NotImplementedError("{k}")
|
|
148
|
+
|
|
149
|
+
{k}_tool = FunctionTool.from_defaults(
|
|
150
|
+
fn=_{k}_impl,
|
|
151
|
+
name="{k}",
|
|
152
|
+
description="{desc}",
|
|
153
|
+
)
|
|
154
|
+
''')
|
|
155
|
+
tool_names.append(k)
|
|
156
|
+
|
|
157
|
+
# Export all tools list
|
|
158
|
+
lines.append(f"ALL_TOOLS = [{', '.join(f'{k}_tool' for k in tool_names)}]")
|
|
159
|
+
|
|
160
|
+
write_file(out_dir, "tools.py", "\n".join(lines))
|
|
161
|
+
return ["tools.py"]
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
def _write_agent(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path, ds: DiagnosticSet) -> list[str]:
|
|
165
|
+
wf = ir.workflows.get(plan.main_workflow_key)
|
|
166
|
+
steps = wf.steps if wf else []
|
|
167
|
+
agent_steps = [s for s in steps if s.agent and s.agent in ir.agents]
|
|
168
|
+
is_multi = len(agent_steps) > 1
|
|
169
|
+
has_parallel = any(s.depends_on for s in steps)
|
|
170
|
+
|
|
171
|
+
if is_multi and has_parallel:
|
|
172
|
+
ds.add_info(DiagCode.REQUIRES_ADAPTER,
|
|
173
|
+
"Parallel agent steps detected. Generating ConcurrentFlow.",
|
|
174
|
+
path=f"workflows.{plan.main_workflow_key}")
|
|
175
|
+
|
|
176
|
+
for step in steps:
|
|
177
|
+
_add_workflow_step_diagnostic(step, plan.main_workflow_key, ds)
|
|
178
|
+
|
|
179
|
+
# LLM imports
|
|
180
|
+
llm_imports: set[str] = set()
|
|
181
|
+
llm_inits: list[str] = []
|
|
182
|
+
model_keys: dict[str, str] = {} # agent_key -> llm var name
|
|
183
|
+
|
|
184
|
+
for i, (ak, agent) in enumerate(ir.agents.items()):
|
|
185
|
+
model = ir.models.get(agent.model)
|
|
186
|
+
if model:
|
|
187
|
+
imp, expr = _llm_init(model)
|
|
188
|
+
llm_imports.add(imp)
|
|
189
|
+
var = f"{ak}_llm"
|
|
190
|
+
model_keys[ak] = var
|
|
191
|
+
llm_inits.append(f"{var} = {expr}")
|
|
192
|
+
else:
|
|
193
|
+
llm_imports.add("from llama_index.llms.openai import OpenAI")
|
|
194
|
+
var = f"{ak}_llm"
|
|
195
|
+
model_keys[ak] = var
|
|
196
|
+
llm_inits.append(f"{var} = OpenAI(model='gpt-4o')")
|
|
197
|
+
|
|
198
|
+
# Build FunctionAgent blocks
|
|
199
|
+
agent_defs: list[str] = []
|
|
200
|
+
for ak, agent in ir.agents.items():
|
|
201
|
+
tools_list = f"[{', '.join(f'{t}_tool' for t in agent.tools if t in ir.tools)}]" if agent.tools else "[]"
|
|
202
|
+
knowledge_tool = ""
|
|
203
|
+
if agent.knowledge:
|
|
204
|
+
ds.add_info(DiagCode.REQUIRES_ADAPTER,
|
|
205
|
+
f"Agent '{ak}' has knowledge config. Generated RAG query engine tool stub.",
|
|
206
|
+
path=f"agents.{ak}.knowledge")
|
|
207
|
+
knowledge_tool = f", {ak}_rag_tool"
|
|
208
|
+
|
|
209
|
+
sys_prompt = agent.instructions.replace('"""', "'''")
|
|
210
|
+
desc = agent.description or f"{ak} agent"
|
|
211
|
+
|
|
212
|
+
agent_defs.append(f'''\
|
|
213
|
+
{ak}_function_agent = FunctionAgent(
|
|
214
|
+
name="{ak}",
|
|
215
|
+
description="""{desc}""",
|
|
216
|
+
system_prompt="""{sys_prompt}""",
|
|
217
|
+
llm={model_keys.get(ak, "OpenAI()")},
|
|
218
|
+
tools={tools_list}{knowledge_tool},
|
|
219
|
+
)''')
|
|
220
|
+
|
|
221
|
+
# Knowledge (RAG) stubs
|
|
222
|
+
rag_stubs: list[str] = []
|
|
223
|
+
for ak, agent in ir.agents.items():
|
|
224
|
+
if agent.knowledge:
|
|
225
|
+
rag_stubs.append(f'''\
|
|
226
|
+
# RAG stub for {ak} — replace with your actual data source
|
|
227
|
+
{ak}_index = VectorStoreIndex.from_documents([]) # TODO: load documents
|
|
228
|
+
{ak}_query_engine = {ak}_index.as_query_engine()
|
|
229
|
+
{ak}_rag_tool = QueryEngineTool.from_defaults(
|
|
230
|
+
query_engine={ak}_query_engine,
|
|
231
|
+
name="{ak}_knowledge",
|
|
232
|
+
description="{agent.knowledge.get('description', 'Knowledge base for ' + ak) if isinstance(agent.knowledge, dict) else 'Knowledge base'}",
|
|
233
|
+
)''')
|
|
234
|
+
|
|
235
|
+
# AgentWorkflow composition
|
|
236
|
+
if is_multi:
|
|
237
|
+
agent_list = ", ".join(f"{ak}_function_agent" for ak in ir.agents.keys())
|
|
238
|
+
root_agent = next(iter(ir.agents.keys()))
|
|
239
|
+
workflow_block = f'''\
|
|
240
|
+
{plan.package_name}_workflow = AgentWorkflow(
|
|
241
|
+
agents=[{agent_list}],
|
|
242
|
+
root_agent="{root_agent}",
|
|
243
|
+
)'''
|
|
244
|
+
else:
|
|
245
|
+
primary = next(iter(ir.agents.keys()))
|
|
246
|
+
workflow_block = f'''\
|
|
247
|
+
{plan.package_name}_workflow = AgentWorkflow(
|
|
248
|
+
agents=[{primary}_function_agent],
|
|
249
|
+
root_agent="{primary}",
|
|
250
|
+
)'''
|
|
251
|
+
|
|
252
|
+
has_rag = any(a.knowledge for a in ir.agents.values())
|
|
253
|
+
rag_imports = """from llama_index.core import VectorStoreIndex
|
|
254
|
+
from llama_index.core.tools import QueryEngineTool""" if has_rag else ""
|
|
255
|
+
|
|
256
|
+
if ir.tools:
|
|
257
|
+
tools_list_str = ", ".join(f"{k}_tool" for k in ir.tools.keys())
|
|
258
|
+
tools_import = f"try:\n from .tools import {tools_list_str}\nexcept (ImportError, ValueError):\n from tools import {tools_list_str}"
|
|
259
|
+
else:
|
|
260
|
+
tools_import = ""
|
|
261
|
+
|
|
262
|
+
schemas_import = ""
|
|
263
|
+
if any(v.output_schema for v in ir.agents.values()):
|
|
264
|
+
schemas_list_str = ", ".join(f"{k.capitalize()}Output" for k, v in ir.agents.items() if v.output_schema)
|
|
265
|
+
schemas_import = f"try:\n from .models import {schemas_list_str}\nexcept (ImportError, ValueError):\n from models import {schemas_list_str}"
|
|
266
|
+
|
|
267
|
+
c = f'''\
|
|
268
|
+
"""LlamaIndex AgentWorkflow for {plan.project_name}.
|
|
269
|
+
|
|
270
|
+
Auto-generated by agentsml-impl. Uses AgentWorkflow + FunctionAgent (preferred 2025 API).
|
|
271
|
+
Re-run to regenerate.
|
|
272
|
+
"""
|
|
273
|
+
from __future__ import annotations
|
|
274
|
+
from llama_index.core.agent.workflow import AgentWorkflow, FunctionAgent
|
|
275
|
+
from llama_index.core.tools import FunctionTool
|
|
276
|
+
{chr(10).join(sorted(llm_imports))}
|
|
277
|
+
{rag_imports}
|
|
278
|
+
{tools_import}
|
|
279
|
+
{schemas_import}
|
|
280
|
+
|
|
281
|
+
# ── LLM instances ─────────────────────────────────────────────────────────────
|
|
282
|
+
{chr(10).join(llm_inits)}
|
|
283
|
+
|
|
284
|
+
# ── RAG tools ─────────────────────────────────────────────────────────────────
|
|
285
|
+
{chr(10).join(rag_stubs) or "# No RAG tools"}
|
|
286
|
+
|
|
287
|
+
# ── Agent definitions ─────────────────────────────────────────────────────────
|
|
288
|
+
{chr(10).join(agent_defs)}
|
|
289
|
+
|
|
290
|
+
# ── Workflow ──────────────────────────────────────────────────────────────────
|
|
291
|
+
{workflow_block}
|
|
292
|
+
'''
|
|
293
|
+
write_file(out_dir, "agent.py", c)
|
|
294
|
+
return ["agent.py"]
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def _add_workflow_step_diagnostic(step: "StepIR", workflow_key: str, ds: DiagnosticSet) -> None:
|
|
298
|
+
"""Report workflow step kinds that LlamaIndex AgentWorkflow does not emit."""
|
|
299
|
+
path_prefix = f"workflows.{workflow_key}.steps.{step.id}"
|
|
300
|
+
|
|
301
|
+
if step.tool:
|
|
302
|
+
ds.add_warning(
|
|
303
|
+
DiagCode.LOSSY_MAPPING,
|
|
304
|
+
f"Tool step '{step.id}' is omitted from LlamaIndex AgentWorkflow generation.",
|
|
305
|
+
path=f"{path_prefix}.tool",
|
|
306
|
+
recommendation="Move the tool onto an agent or add a custom workflow wrapper.",
|
|
307
|
+
)
|
|
308
|
+
return
|
|
309
|
+
|
|
310
|
+
if step.workflow:
|
|
311
|
+
ds.add_info(
|
|
312
|
+
DiagCode.REQUIRES_ADAPTER,
|
|
313
|
+
f"Nested workflow step '{step.id}' requires a custom LlamaIndex adapter.",
|
|
314
|
+
path=f"{path_prefix}.workflow",
|
|
315
|
+
recommendation="Implement nested workflow handling outside the generated AgentWorkflow.",
|
|
316
|
+
)
|
|
317
|
+
return
|
|
318
|
+
|
|
319
|
+
if step.a2a_agent:
|
|
320
|
+
ds.add_info(
|
|
321
|
+
DiagCode.REQUIRES_ADAPTER,
|
|
322
|
+
f"A2A step '{step.id}' requires a custom LlamaIndex adapter.",
|
|
323
|
+
path=f"{path_prefix}.a2a_agent",
|
|
324
|
+
recommendation="Wrap the remote A2A agent in a custom LlamaIndex integration.",
|
|
325
|
+
)
|
|
326
|
+
return
|
|
327
|
+
|
|
328
|
+
if step.is_approval_only():
|
|
329
|
+
ds.add_info(
|
|
330
|
+
DiagCode.REQUIRES_ADAPTER,
|
|
331
|
+
f"Approval-only step '{step.id}' is omitted from LlamaIndex AgentWorkflow generation.",
|
|
332
|
+
path=f"{path_prefix}.approval",
|
|
333
|
+
recommendation="Implement approval gating in surrounding application logic.",
|
|
334
|
+
)
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
def _write_run(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
|
|
338
|
+
c = f'''\
|
|
339
|
+
"""Runner for {plan.project_name} (LlamaIndex AgentWorkflow). Auto-generated."""
|
|
340
|
+
from __future__ import annotations
|
|
341
|
+
import asyncio
|
|
342
|
+
import sys
|
|
343
|
+
from .agent import {plan.package_name}_workflow
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
async def run_async(question: str) -> str:
|
|
347
|
+
handler = {plan.package_name}_workflow.run(user_msg=question)
|
|
348
|
+
async for event in handler.stream_events():
|
|
349
|
+
pass # process streaming events if needed
|
|
350
|
+
response = await handler
|
|
351
|
+
return str(response)
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
def main() -> None:
|
|
355
|
+
q = " ".join(sys.argv[1:]) or "Hello!"
|
|
356
|
+
print(asyncio.run(run_async(q)))
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
if __name__ == "__main__":
|
|
360
|
+
main()
|
|
361
|
+
'''
|
|
362
|
+
write_file(out_dir, "run.py", c)
|
|
363
|
+
return ["run.py"]
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
def _write_init(out_dir: Path) -> list[str]:
|
|
367
|
+
c = '"""Package initialization for LlamaIndex project."""\n'
|
|
368
|
+
write_file(out_dir, "__init__.py", c)
|
|
369
|
+
return ["__init__.py"]
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
def _write_readme(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
|
|
373
|
+
agents_md = "\n".join(f"- `{k}`: {v.description or ''}" for k, v in ir.agents.items())
|
|
374
|
+
c = f"""\
|
|
375
|
+
# {plan.project_name} — LlamaIndex
|
|
376
|
+
|
|
377
|
+
> Auto-generated by `agentsml-impl`.
|
|
378
|
+
|
|
379
|
+
## Agents
|
|
380
|
+
{agents_md or "None"}
|
|
381
|
+
|
|
382
|
+
## Architecture
|
|
383
|
+
|
|
384
|
+
Uses `AgentWorkflow` + `FunctionAgent` (LlamaIndex 0.11+ preferred API).
|
|
385
|
+
Each agent is a `FunctionAgent` with its own LLM and tools.
|
|
386
|
+
Multi-agent coordination is handled by `AgentWorkflow` with a root agent.
|
|
387
|
+
|
|
388
|
+
## Quickstart
|
|
389
|
+
```bash
|
|
390
|
+
pip install -e .
|
|
391
|
+
export OPENAI_API_KEY="your-key"
|
|
392
|
+
python run.py "Your question here"
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
## RAG (if applicable)
|
|
396
|
+
Populate the `VectorStoreIndex` in `agent.py` with your documents:
|
|
397
|
+
```python
|
|
398
|
+
from llama_index.core import SimpleDirectoryReader
|
|
399
|
+
documents = SimpleDirectoryReader("./data").load_data()
|
|
400
|
+
index = VectorStoreIndex.from_documents(documents)
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
> See `diagnostics.yaml` for portability warnings.
|
|
404
|
+
"""
|
|
405
|
+
write_file(out_dir, "README.md", c)
|
|
406
|
+
return ["README.md"]
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
target: llamaindex
|
|
2
|
+
kind: code
|
|
3
|
+
language: python
|
|
4
|
+
status: implemented
|
|
5
|
+
level: 1
|
|
6
|
+
version_tested: "0.11.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: unsupported
|
|
20
|
+
observability: unsupported
|
|
21
|
+
artifacts:
|
|
22
|
+
- python_project
|
|
23
|
+
- diagnostics
|
|
24
|
+
- readme
|
|
25
|
+
notes: >
|
|
26
|
+
Maps to LlamaIndex AgentWorkflow + FunctionAgent. Tool generation is native.
|
|
27
|
+
Workflow structure is flattened into an AgentWorkflow root-agent composition;
|
|
28
|
+
dependency edges are only partially represented, and parallel/cycle semantics
|
|
29
|
+
are not emitted by the adapter.
|
|
30
|
+
profiles:
|
|
31
|
+
agentsml-rag: adapter
|
|
File without changes
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""Lyzr target adapter — Level 1 code generation (JSON export / flow_data)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
import json
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from agentsml_impl.compiler.ir import AgentSystemIR
|
|
9
|
+
from agentsml_impl.compiler.diagnostics import DiagCode, DiagnosticSet
|
|
10
|
+
from agentsml_impl.compiler.planner import GenerationPlan
|
|
11
|
+
from agentsml_impl.compiler.render import write_file
|
|
12
|
+
from agentsml_impl.targets.base import TargetAdapter, GenerationResult
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Adapter(TargetAdapter):
|
|
16
|
+
@property
|
|
17
|
+
def name(self) -> str:
|
|
18
|
+
return "lyzr"
|
|
19
|
+
|
|
20
|
+
def analyze(self, ir: AgentSystemIR, diagnostics: DiagnosticSet) -> None:
|
|
21
|
+
from agentsml_impl.compiler.capabilities import analyze_capabilities
|
|
22
|
+
analyze_capabilities(ir, "lyzr", diagnostics)
|
|
23
|
+
|
|
24
|
+
def generate(self, ir: AgentSystemIR, plan: GenerationPlan,
|
|
25
|
+
out_dir: Path, diagnostics: DiagnosticSet) -> GenerationResult:
|
|
26
|
+
out_dir.mkdir(parents=True, exist_ok=True)
|
|
27
|
+
|
|
28
|
+
files: list[str] = []
|
|
29
|
+
files += _write_lyzr_json(ir, plan, out_dir)
|
|
30
|
+
files += _write_readme(ir, plan, out_dir)
|
|
31
|
+
|
|
32
|
+
return GenerationResult(
|
|
33
|
+
target=self.name, out_dir=out_dir, files_written=files, success=True
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _write_lyzr_json(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
|
|
38
|
+
# Lyzr Enterprise flow_data format requires exactly one trigger node
|
|
39
|
+
nodes: list[dict[str, Any]] = [
|
|
40
|
+
{
|
|
41
|
+
"id": "trigger-start",
|
|
42
|
+
"name": "Trigger",
|
|
43
|
+
"type": "lyzr-nodes-base.trigger",
|
|
44
|
+
"typeVersion": 1,
|
|
45
|
+
"parameters": {},
|
|
46
|
+
"position": [100, 300],
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
connections: dict[str, Any] = {}
|
|
51
|
+
prev_node_name = "Trigger"
|
|
52
|
+
x = 340
|
|
53
|
+
|
|
54
|
+
wf = ir.workflows.get(plan.main_workflow_key)
|
|
55
|
+
if wf and wf.steps:
|
|
56
|
+
for step in wf.steps:
|
|
57
|
+
agent = ir.agents.get(step.agent) if step.agent else None
|
|
58
|
+
instructions = agent.instructions if agent else f"Execute step {step.id}"
|
|
59
|
+
tools = agent.tools if agent and agent.tools else []
|
|
60
|
+
node_name = f"step_{step.id}"
|
|
61
|
+
nodes.append({
|
|
62
|
+
"id": f"node_{step.id}",
|
|
63
|
+
"name": node_name,
|
|
64
|
+
"type": "lyzr-nodes-base.agent",
|
|
65
|
+
"typeVersion": 1,
|
|
66
|
+
"parameters": {
|
|
67
|
+
"instructions": instructions,
|
|
68
|
+
"tools": tools,
|
|
69
|
+
},
|
|
70
|
+
"position": [x, 300],
|
|
71
|
+
})
|
|
72
|
+
connections[prev_node_name] = {
|
|
73
|
+
"main": [
|
|
74
|
+
[{"node": node_name, "type": "main", "index": 0}]
|
|
75
|
+
]
|
|
76
|
+
}
|
|
77
|
+
prev_node_name = node_name
|
|
78
|
+
x += 240
|
|
79
|
+
else:
|
|
80
|
+
for ak, agent in ir.agents.items():
|
|
81
|
+
node_name = f"agent_{ak}"
|
|
82
|
+
nodes.append({
|
|
83
|
+
"id": f"node_{ak}",
|
|
84
|
+
"name": node_name,
|
|
85
|
+
"type": "lyzr-nodes-base.agent",
|
|
86
|
+
"typeVersion": 1,
|
|
87
|
+
"parameters": {
|
|
88
|
+
"instructions": agent.instructions,
|
|
89
|
+
"tools": agent.tools or [],
|
|
90
|
+
},
|
|
91
|
+
"position": [x, 300],
|
|
92
|
+
})
|
|
93
|
+
connections[prev_node_name] = {
|
|
94
|
+
"main": [
|
|
95
|
+
[{"node": node_name, "type": "main", "index": 0}]
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
prev_node_name = node_name
|
|
99
|
+
x += 240
|
|
100
|
+
|
|
101
|
+
flow_data = {
|
|
102
|
+
"name": plan.project_name,
|
|
103
|
+
"nodes": nodes,
|
|
104
|
+
"connections": connections,
|
|
105
|
+
"settings": {},
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export = {
|
|
109
|
+
"flow_name": plan.project_name,
|
|
110
|
+
"flow_data": flow_data,
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
c = json.dumps(export, indent=2)
|
|
114
|
+
rel = "lyzr.json"
|
|
115
|
+
write_file(out_dir, rel, c)
|
|
116
|
+
return [rel]
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _write_readme(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
|
|
120
|
+
c = f"""\
|
|
121
|
+
# {plan.project_name} — Lyzr Enterprise Workflow
|
|
122
|
+
|
|
123
|
+
Generated by `agentsml-impl`.
|
|
124
|
+
|
|
125
|
+
## Overview
|
|
126
|
+
This export produces a verified Lyzr Enterprise `flow_data` definition for importing into Lyzr Studio or executing via the Lyzr Enterprise API.
|
|
127
|
+
|
|
128
|
+
## Deployment & Execution
|
|
129
|
+
|
|
130
|
+
### 1. Lyzr Enterprise Workflow API
|
|
131
|
+
Import or execute the workflow using the Lyzr API:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
curl -X POST "https://inference.studio.lyzr.ai/api/workflows" \\
|
|
135
|
+
-H "Content-Type: application/json" \\
|
|
136
|
+
-H "x-api-key: $LYZR_API_KEY" \\
|
|
137
|
+
-d @lyzr.json
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### 2. Lyzr Studio UI
|
|
141
|
+
1. Navigate to your Lyzr Studio workspace.
|
|
142
|
+
2. Go to **Workflows / Superflow**.
|
|
143
|
+
3. Import `lyzr.json`.
|
|
144
|
+
"""
|
|
145
|
+
write_file(out_dir, "README.md", c)
|
|
146
|
+
return ["README.md"]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
target: lyzr
|
|
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: unsupported
|
|
12
|
+
graph_conditions: unsupported
|
|
13
|
+
cycles: unsupported
|
|
14
|
+
parallel: unsupported
|
|
15
|
+
human_approval: adapter
|
|
16
|
+
mcp: adapter
|
|
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 Lyzr Enterprise workflow definition (flow_data).
|
|
File without changes
|