ワンクリックで
serverless-optimizer
Analyze Vercel serverless functions, identify expensive code, and optimize it via Kai Evolve
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Analyze Vercel serverless functions, identify expensive code, and optimize it via Kai Evolve
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Inspect and analyze codebases using pygount for LOC counting, language breakdown, and code-vs-comment ratios. Use when asked to check lines of code, repo size, language composition, or codebase stats.
Set up GitHub authentication for the agent using git (universally available) or the gh CLI. Covers HTTPS tokens, SSH keys, credential helpers, and gh auth — with a detection flow to pick the right method automatically.
Production-grade PR review with execution-verified suggestions. Reads repository conventions, history, and security surfaces before reviewing. For every suggested fix, attempts to compile and test it in the sandbox — the comment includes proof. Modelled on GitHub Copilot's agentic architecture with one critical advantage: the sandbox is already running.
Create, manage, triage, and close GitHub issues. Search existing issues, add labels, assign people, and link to PRs. Works with gh CLI or falls back to git + GitHub REST API via curl.
Open and manage GitHub pull requests through Kai MCP tools — propose changes, monitor CI, iterate on failures, and merge. No git tokens are shared to the sandbox; every GitHub operation goes through the backend via the workspace's GitHub App installation.
Clone, create, fork, configure, and manage GitHub repositories. Manage remotes, secrets, releases, and workflows. Works with gh CLI or falls back to git + GitHub REST API via curl.
| name | serverless-optimizer |
| description | Analyze Vercel serverless functions, identify expensive code, and optimize it via Kai Evolve |
| version | 2.0.0 |
| author | kai-agent |
| metadata | {"kai":{"tags":["kai","vercel","serverless","cost","optimization"],"related_skills":["optimization-workflow","evaluator-creation","aws-cost-optimizer"]}} |
Analyze Vercel serverless functions, identify expensive code paths, and optimize them using Kai's evolutionary optimization engine. Findings become GitHub issues with before/after code from real optimization runs.
kai_activate_category(category="optimization")
Vercel tools are first-party vercel_* tools in the serverless category —
activate them with kai_activate_category(category="serverless"). They call
Vercel's REST API via the workspace's marketplace OAuth token; Vercel is NOT a
proxy MCP (mcp.vercel.com is allowlist-only), so it does NOT appear in
kai_list_integrations and the tools are named vercel_*, not mcp_vercel_*.
vercel_list_projects()
Pick projects by: most deployments, highest build times, or user request.
(These are first-party vercel_* tools from the backend's serverless
category — not an upstream MCP. If you don't see them, run
kai_activate_category(category="serverless") or find_tools(query="vercel").)
vercel_get_function_metrics(projectId)
Extract:
vercel_list_functions(projectId)
Note runtime, memory, region for each function.
The Vercel project must have its backing repo added to the workspace. Use repo tools:
browse_repository_files(workspaceId, repoId)
read_repository_files(workspaceId, repoId, paths=["src/app/api/...", "pages/api/..."])
For each API route / serverless function, look for patterns from references/optimization-patterns.md:
Rank optimization candidates by impact. Only proceed with candidates where:
For each optimization candidate, run through the Kai optimization pipeline.
Write a Python evaluator targeting the specific serverless function. See the evaluator-creation skill for full details.
Serverless-specific evaluator patterns:
For cold start / bundle size optimization:
import ast
import sys
def evaluate(module):
"""Score on code size and import count (proxy for bundle size)."""
source = inspect.getsource(module)
tree = ast.parse(source)
import_count = sum(1 for node in ast.walk(tree) if isinstance(node, (ast.Import, ast.ImportFrom)))
line_count = len(source.splitlines())
# Fewer imports and lines = smaller bundle = faster cold start
# Penalize heavily for known-heavy imports
heavy_imports = ['pandas', 'numpy', 'scipy', 'tensorflow', 'torch']
heavy_penalty = sum(50 for node in ast.walk(tree)
if isinstance(node, ast.ImportFrom) and node.module and any(h in node.module for h in heavy_imports))
return max(0, 200 - import_count * 5 - line_count * 0.1 - heavy_penalty)
For response latency optimization:
import time
import statistics
def evaluate(module):
"""Score API handler on response latency with mock request."""
times = []
for _ in range(10):
start = time.perf_counter()
# Call the handler with a realistic mock request
module.handler(mock_request)
elapsed = time.perf_counter() - start
times.append(elapsed)
median_ms = statistics.median(times) * 1000
return max(0, 1000 / (median_ms + 1))
Upload the evaluator in one step:
create_evaluator_from_code(workspaceId, repoId, code=evaluator_code, name="Serverless: /api/X latency")
# → returns { evaluatorId }
config = {
"llm": {"models": [{"name": "openai/gpt-4o", "weight": 1.0}]},
"prompt": {"systemMessage": "Optimize this Vercel handler for cold start / latency. Keep the HTTP contract unchanged."},
}
scopes = [{"path": "src/app/api/X/route.ts", "fromLine": 1, "toLine": 120}]
start_code_optimization(workspaceId, repoId, config, scopes, evaluatorId)
Use scopes[].path / fromLine / toLine (not filePath / startLine / endLine),
config.llm.models as an array, and config.prompt.systemMessage (not goal).
get_code_optimization_progress(optimizationId)
get_optimization_iterations(optimizationId)
Report milestones to the user as they happen.
get_optimized_programs(optimizationId)
Verify:
For each successful optimization, create a GitHub issue with:
references/vercel-pricing.mdUse the template from references/issue-template.md.
Present a summary to the user:
Profile: {framework} | {N} functions | {region} | avg build {X}s
| # | Function | Finding | Optimization | Improvement |
|---|---|---|---|---|
| 1 | /api/feed | SSR → ISR | optimizationId: X | 2.3x fewer invocations |
| 2 | /api/health | Serverless → Edge | manual (config) | ~200ms cold start eliminated |
| 3 | /api/export | Heavy imports | optimizationId: Y | 1.4x faster cold start |
Estimated monthly savings: $X — $Y (depending on traffic)
workspace_learnings_add(category="optimization", content="Vercel project [name]: optimized [N] functions. Key finding: [pattern]. Evaluator [id] measured [metric].")
kai_create_pull_request (activate the integrations category first). For broader config decisions that need team input, file an issue via kai_create_github_issue with labels=["serverless", "performance"]. Don't run a Kai Evolve optimization on pure config — it's the wrong tool for the job.