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,349 @@
|
|
|
1
|
+
"""Vercel AI SDK target adapter — Level 1 code generation (TypeScript).
|
|
2
|
+
|
|
3
|
+
Generates TypeScript using the Vercel AI SDK:
|
|
4
|
+
- generateText / streamText for text agents.
|
|
5
|
+
- generateObject for structured output agents.
|
|
6
|
+
- tool() with Zod schemas for tools.
|
|
7
|
+
- maxSteps for multi-step agentic loops.
|
|
8
|
+
- experimental_createMCPClient for MCP tools.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
import json
|
|
14
|
+
|
|
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 write_file
|
|
19
|
+
from agentsml_impl.compiler.naming import camel_identifier, pascal_identifier
|
|
20
|
+
from agentsml_impl.targets.base import TargetAdapter, GenerationResult
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class Adapter(TargetAdapter):
|
|
24
|
+
@property
|
|
25
|
+
def name(self) -> str:
|
|
26
|
+
return "vercel-ai"
|
|
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
|
+
if len(ir.agents) > 1:
|
|
32
|
+
diagnostics.add_warning(
|
|
33
|
+
DiagCode.LOSSY_MAPPING,
|
|
34
|
+
"Vercel AI SDK v4 doesn't have a native multi-agent network primitive. "
|
|
35
|
+
"Generated code composes agents via function calls. "
|
|
36
|
+
"Consider Mastra (createNetwork) for richer multi-agent orchestration.",
|
|
37
|
+
path="agents",
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
def generate(self, ir: AgentSystemIR, plan: GenerationPlan,
|
|
41
|
+
out_dir: Path, diagnostics: DiagnosticSet) -> GenerationResult:
|
|
42
|
+
out_dir.mkdir(parents=True, exist_ok=True)
|
|
43
|
+
src = out_dir / "src"
|
|
44
|
+
src.mkdir(parents=True, exist_ok=True)
|
|
45
|
+
|
|
46
|
+
files: list[str] = []
|
|
47
|
+
files += _write_package_json(ir, plan, out_dir)
|
|
48
|
+
files += _write_tsconfig(out_dir)
|
|
49
|
+
files += _write_tools(ir, src, out_dir, diagnostics)
|
|
50
|
+
files += _write_agent(ir, plan, src, out_dir, diagnostics)
|
|
51
|
+
files += _write_index(ir, plan, src, 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 _vercel_model_import_and_expr(model: ModelIR) -> tuple[str, str]:
|
|
62
|
+
"""Return (import_line, model_expr)."""
|
|
63
|
+
p = model.provider.lower()
|
|
64
|
+
n = model.name
|
|
65
|
+
if p == "openai":
|
|
66
|
+
return "import { openai } from '@ai-sdk/openai';", f"openai('{n}')"
|
|
67
|
+
if p == "anthropic":
|
|
68
|
+
return "import { anthropic } from '@ai-sdk/anthropic';", f"anthropic('{n}')"
|
|
69
|
+
if p in ("google", "gemini"):
|
|
70
|
+
return "import { google } from '@ai-sdk/google';", f"google('{n}')"
|
|
71
|
+
if p in ("azure", "azure-openai"):
|
|
72
|
+
return "import { openai } from '@ai-sdk/openai';", f"openai('{n}') // Azure: set AZURE_OPENAI_* env vars"
|
|
73
|
+
if p == "groq":
|
|
74
|
+
return "import { groq } from '@ai-sdk/groq';", f"groq('{n}')"
|
|
75
|
+
if p == "mistral":
|
|
76
|
+
return "import { mistral } from '@ai-sdk/mistral';", f"mistral('{n}')"
|
|
77
|
+
# Fallback
|
|
78
|
+
return "import { openai } from '@ai-sdk/openai';", f"openai('{n}') // TODO: check provider {p!r}"
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# ---------------------------------------------------------------------------
|
|
82
|
+
# File generators
|
|
83
|
+
# ---------------------------------------------------------------------------
|
|
84
|
+
|
|
85
|
+
def _write_package_json(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
|
|
86
|
+
has_mcp = any(t.is_mcp() for t in ir.tools.values())
|
|
87
|
+
mcp_dep = ',\n "ai": "^4.0.0"' if has_mcp else ""
|
|
88
|
+
c = f'''\
|
|
89
|
+
{{
|
|
90
|
+
"name": "{plan.package_name}",
|
|
91
|
+
"version": "{ir.metadata.version or '0.1.0'}",
|
|
92
|
+
"type": "module",
|
|
93
|
+
"scripts": {{
|
|
94
|
+
"dev": "tsx watch src/index.ts",
|
|
95
|
+
"start": "tsx src/index.ts"
|
|
96
|
+
}},
|
|
97
|
+
"dependencies": {{
|
|
98
|
+
"ai": "^4.0.0",
|
|
99
|
+
"@ai-sdk/openai": "^1.0.0",
|
|
100
|
+
"@ai-sdk/anthropic": "^1.0.0",
|
|
101
|
+
"@ai-sdk/google": "^1.0.0",
|
|
102
|
+
"@ai-sdk/groq": "^1.0.0",
|
|
103
|
+
"zod": "^3.22.4"
|
|
104
|
+
}},
|
|
105
|
+
"devDependencies": {{
|
|
106
|
+
"typescript": "^5.0.0",
|
|
107
|
+
"@types/node": "^20.0.0",
|
|
108
|
+
"tsx": "^4.0.0"
|
|
109
|
+
}}
|
|
110
|
+
}}
|
|
111
|
+
'''
|
|
112
|
+
write_file(out_dir, "package.json", c)
|
|
113
|
+
return ["package.json"]
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _write_tsconfig(out_dir: Path) -> list[str]:
|
|
117
|
+
c = '''\
|
|
118
|
+
{
|
|
119
|
+
"compilerOptions": {
|
|
120
|
+
"target": "ES2022",
|
|
121
|
+
"module": "ESNext",
|
|
122
|
+
"moduleResolution": "bundler",
|
|
123
|
+
"strict": true,
|
|
124
|
+
"esModuleInterop": true,
|
|
125
|
+
"skipLibCheck": true,
|
|
126
|
+
"outDir": "./dist"
|
|
127
|
+
},
|
|
128
|
+
"include": ["src/**/*"]
|
|
129
|
+
}
|
|
130
|
+
'''
|
|
131
|
+
write_file(out_dir, "tsconfig.json", c)
|
|
132
|
+
return ["tsconfig.json"]
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _json_schema_to_zod(schema: dict | None) -> str:
|
|
136
|
+
"""Convert JSON schema to Zod expression (best-effort)."""
|
|
137
|
+
if not schema:
|
|
138
|
+
return "z.any()"
|
|
139
|
+
t = schema.get("type")
|
|
140
|
+
if t == "string":
|
|
141
|
+
return "z.string()"
|
|
142
|
+
if t == "number":
|
|
143
|
+
return "z.number()"
|
|
144
|
+
if t == "integer":
|
|
145
|
+
return "z.number().int()"
|
|
146
|
+
if t == "boolean":
|
|
147
|
+
return "z.boolean()"
|
|
148
|
+
if t == "array":
|
|
149
|
+
items = schema.get("items", {})
|
|
150
|
+
return f"z.array({_json_schema_to_zod(items)})"
|
|
151
|
+
if t == "object":
|
|
152
|
+
props = schema.get("properties", {})
|
|
153
|
+
if not props:
|
|
154
|
+
return "z.record(z.any())"
|
|
155
|
+
fields = ", ".join(f"{json.dumps(k)}: {_json_schema_to_zod(v)}" for k, v in props.items())
|
|
156
|
+
return f"z.object({{ {fields} }})"
|
|
157
|
+
return "z.any()"
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def _write_tools(ir: AgentSystemIR, src: Path, out_dir: Path, ds: DiagnosticSet) -> list[str]:
|
|
161
|
+
if not ir.tools:
|
|
162
|
+
return []
|
|
163
|
+
|
|
164
|
+
has_mcp = any(t.is_mcp() for t in ir.tools.values())
|
|
165
|
+
local_tools = {k: v for k, v in ir.tools.items() if not v.is_mcp()}
|
|
166
|
+
|
|
167
|
+
blocks: list[str] = []
|
|
168
|
+
for k, tool_ir in local_tools.items():
|
|
169
|
+
tool_var = camel_identifier(k, prefix="tool") + "Tool"
|
|
170
|
+
desc = tool_ir.description.replace('"', '\\"')
|
|
171
|
+
param_schema = _json_schema_to_zod(tool_ir.input_schema)
|
|
172
|
+
blocks.append(f'''\
|
|
173
|
+
export const {tool_var} = tool({{
|
|
174
|
+
description: "{desc}",
|
|
175
|
+
parameters: {param_schema},
|
|
176
|
+
execute: async (params) => {{
|
|
177
|
+
// TODO: implement {k}
|
|
178
|
+
throw new Error("{k}: not implemented");
|
|
179
|
+
}},
|
|
180
|
+
}});
|
|
181
|
+
''')
|
|
182
|
+
|
|
183
|
+
mcp_section = ""
|
|
184
|
+
if has_mcp:
|
|
185
|
+
mcp_tools = {k: v for k, v in ir.tools.items() if v.is_mcp()}
|
|
186
|
+
mcp_servers: set[str] = set()
|
|
187
|
+
for t in mcp_tools.values():
|
|
188
|
+
if t.mcp_server:
|
|
189
|
+
mcp_servers.add(t.mcp_server)
|
|
190
|
+
mcp_section = f'''
|
|
191
|
+
// MCP Tool integration
|
|
192
|
+
// Note: experimental_createMCPClient is available in Vercel AI SDK v4+
|
|
193
|
+
// Uncomment and configure your MCP server:
|
|
194
|
+
// import {{ experimental_createMCPClient }} from 'ai';
|
|
195
|
+
// const mcpClient = await experimental_createMCPClient({{ transport: ... }});
|
|
196
|
+
// const mcpTools = await mcpClient.tools();
|
|
197
|
+
'''
|
|
198
|
+
ds.add_info(DiagCode.REQUIRES_ADAPTER,
|
|
199
|
+
f"MCP tools detected. See tools.ts for experimental_createMCPClient setup.",
|
|
200
|
+
path="tools")
|
|
201
|
+
|
|
202
|
+
c = f'''\
|
|
203
|
+
/**
|
|
204
|
+
* Vercel AI SDK tools for {out_dir.name}.
|
|
205
|
+
* Auto-generated by agentsml-impl.
|
|
206
|
+
*/
|
|
207
|
+
import {{ tool }} from 'ai';
|
|
208
|
+
import {{ z }} from 'zod';
|
|
209
|
+
|
|
210
|
+
{chr(10).join(blocks)}
|
|
211
|
+
{mcp_section}
|
|
212
|
+
'''
|
|
213
|
+
rel = "src/tools.ts"
|
|
214
|
+
write_file(out_dir, rel, c)
|
|
215
|
+
return [rel]
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def _write_agent(ir: AgentSystemIR, plan: GenerationPlan, src: Path, out_dir: Path, ds: DiagnosticSet) -> list[str]:
|
|
219
|
+
provider_imports: set[str] = set()
|
|
220
|
+
agent_fns: list[str] = []
|
|
221
|
+
|
|
222
|
+
tools_import = (
|
|
223
|
+
f"import {{ {', '.join(camel_identifier(k, prefix='tool') + 'Tool' for k in ir.tools.keys() if not ir.tools[k].is_mcp())} }} from './tools.js';"
|
|
224
|
+
if ir.tools else ""
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
for ak, agent in ir.agents.items():
|
|
228
|
+
model = ir.models.get(agent.model)
|
|
229
|
+
if model:
|
|
230
|
+
pimp, pexpr = _vercel_model_import_and_expr(model)
|
|
231
|
+
provider_imports.add(pimp)
|
|
232
|
+
else:
|
|
233
|
+
pimp = "import { openai } from '@ai-sdk/openai';"
|
|
234
|
+
pexpr = "openai('gpt-4o')"
|
|
235
|
+
provider_imports.add(pimp)
|
|
236
|
+
|
|
237
|
+
sys_prompt = agent.instructions.replace('`', '\\`')
|
|
238
|
+
tools_list = ", ".join(
|
|
239
|
+
camel_identifier(t, prefix="tool") + "Tool"
|
|
240
|
+
for t in agent.tools if t in ir.tools and not ir.tools[t].is_mcp()
|
|
241
|
+
)
|
|
242
|
+
run_name = "run" + pascal_identifier(ak, prefix="Agent")
|
|
243
|
+
has_output = bool(agent.output_schema)
|
|
244
|
+
|
|
245
|
+
if has_output:
|
|
246
|
+
out_schema = _json_schema_to_zod(agent.output_schema)
|
|
247
|
+
fn_body = f'''\
|
|
248
|
+
export async function {run_name}(userMessage: string) {{
|
|
249
|
+
const result = await generateObject({{
|
|
250
|
+
model: {pexpr},
|
|
251
|
+
system: `{sys_prompt}`,
|
|
252
|
+
prompt: userMessage,
|
|
253
|
+
schema: {out_schema},
|
|
254
|
+
}});
|
|
255
|
+
return result.object;
|
|
256
|
+
}}'''
|
|
257
|
+
agent_fns.append(fn_body)
|
|
258
|
+
else:
|
|
259
|
+
fn_body = f'''\
|
|
260
|
+
export async function {run_name}(userMessage: string) {{
|
|
261
|
+
const result = await generateText({{
|
|
262
|
+
model: {pexpr},
|
|
263
|
+
system: `{sys_prompt}`,
|
|
264
|
+
prompt: userMessage,
|
|
265
|
+
tools: {{ {tools_list} }},
|
|
266
|
+
maxSteps: 10, // enable multi-step agentic loop
|
|
267
|
+
}});
|
|
268
|
+
return result.text;
|
|
269
|
+
}}'''
|
|
270
|
+
agent_fns.append(fn_body)
|
|
271
|
+
|
|
272
|
+
import_fns = "generateText, generateObject" if any(
|
|
273
|
+
a.output_schema for a in ir.agents.values()
|
|
274
|
+
) else "generateText"
|
|
275
|
+
zod_import = "import { z } from 'zod';" if any(
|
|
276
|
+
a.output_schema for a in ir.agents.values()
|
|
277
|
+
) else ""
|
|
278
|
+
|
|
279
|
+
c = f'''\
|
|
280
|
+
/**
|
|
281
|
+
* Vercel AI SDK agent functions for {plan.project_name}.
|
|
282
|
+
* Auto-generated by agentsml-impl. Re-run to regenerate.
|
|
283
|
+
*/
|
|
284
|
+
import {{ {import_fns} }} from 'ai';
|
|
285
|
+
{zod_import}
|
|
286
|
+
{chr(10).join(sorted(provider_imports))}
|
|
287
|
+
{tools_import}
|
|
288
|
+
|
|
289
|
+
{chr(10).join(agent_fns)}
|
|
290
|
+
'''
|
|
291
|
+
rel = "src/agent.ts"
|
|
292
|
+
write_file(out_dir, rel, c)
|
|
293
|
+
return [rel]
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def _write_index(ir: AgentSystemIR, plan: GenerationPlan, src: Path, out_dir: Path) -> list[str]:
|
|
297
|
+
first_ak = next(iter(ir.agents.keys()), None)
|
|
298
|
+
fn_name = "run" + pascal_identifier(first_ak, prefix="Agent") if first_ak else "runAgent"
|
|
299
|
+
c = f'''\
|
|
300
|
+
/**
|
|
301
|
+
* Entry point for {plan.project_name} (Vercel AI SDK).
|
|
302
|
+
*/
|
|
303
|
+
import {{ {fn_name} }} from './agent.js';
|
|
304
|
+
|
|
305
|
+
const q = process.argv.slice(2).join(" ") || "Hello!";
|
|
306
|
+
const result = await {fn_name}(q);
|
|
307
|
+
console.log(result);
|
|
308
|
+
'''
|
|
309
|
+
rel = "src/index.ts"
|
|
310
|
+
write_file(out_dir, rel, c)
|
|
311
|
+
return [rel]
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
def _write_readme(ir: AgentSystemIR, plan: GenerationPlan, out_dir: Path) -> list[str]:
|
|
315
|
+
agents_md = "\n".join(f"- `{k}`: {v.description or ''}" for k, v in ir.agents.items())
|
|
316
|
+
c = f"""\
|
|
317
|
+
# {plan.project_name} — Vercel AI SDK
|
|
318
|
+
|
|
319
|
+
> Auto-generated by `agentsml-impl`.
|
|
320
|
+
|
|
321
|
+
## Agents
|
|
322
|
+
{agents_md or "None"}
|
|
323
|
+
|
|
324
|
+
## Architecture
|
|
325
|
+
|
|
326
|
+
- **Text generation**: `generateText` with `maxSteps` for multi-step agentic loops
|
|
327
|
+
- **Structured output**: `generateObject` with Zod schema
|
|
328
|
+
- **Tools**: `tool()` with Zod parameter schemas and `execute` function
|
|
329
|
+
- **MCP**: `experimental_createMCPClient` (see `src/tools.ts`)
|
|
330
|
+
|
|
331
|
+
## Quickstart
|
|
332
|
+
```bash
|
|
333
|
+
npm install
|
|
334
|
+
export OPENAI_API_KEY="your-key"
|
|
335
|
+
npm run dev "Your question here"
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
## Streaming (React/Next.js)
|
|
339
|
+
Use `streamText` + `useChat` hook for streaming UI:
|
|
340
|
+
```typescript
|
|
341
|
+
import {{ streamText }} from 'ai';
|
|
342
|
+
const result = await streamText({{ model: openai('gpt-4o'), prompt: '...' }});
|
|
343
|
+
for await (const chunk of result.textStream) process.stdout.write(chunk);
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
> See `diagnostics.yaml` for portability warnings.
|
|
347
|
+
"""
|
|
348
|
+
write_file(out_dir, "README.md", c)
|
|
349
|
+
return ["README.md"]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
target: vercel_ai
|
|
2
|
+
kind: code
|
|
3
|
+
language: typescript
|
|
4
|
+
status: implemented
|
|
5
|
+
level: 1
|
|
6
|
+
version_tested: "4.0.0"
|
|
7
|
+
supports:
|
|
8
|
+
agents: native
|
|
9
|
+
tools: native
|
|
10
|
+
workflows: lossy
|
|
11
|
+
graph_edges: lossy
|
|
12
|
+
graph_conditions: lossy
|
|
13
|
+
cycles: lossy
|
|
14
|
+
parallel: unsupported
|
|
15
|
+
human_approval: unsupported
|
|
16
|
+
mcp: adapter
|
|
17
|
+
a2a: unsupported
|
|
18
|
+
ag_ui: unsupported
|
|
19
|
+
structured_output: native
|
|
20
|
+
observability: unsupported
|
|
21
|
+
artifacts:
|
|
22
|
+
- node_project
|
|
23
|
+
- diagnostics
|
|
24
|
+
- readme
|
|
25
|
+
notes: >
|
|
26
|
+
Vercel AI SDK maps cleanly to single-agent generateText/streamText and
|
|
27
|
+
generateObject flows. Multi-agent composition is function-call based rather
|
|
28
|
+
than a native graph primitive, so graph edges and cycles are lossy. MCP is
|
|
29
|
+
exposed through experimental_createMCPClient and human approval relies on
|
|
30
|
+
external confirmation hooks.
|
|
File without changes
|