AgentSkillsCN

ai-agent-builder

打造可在网站上自主运行、与 API 交互、执行自动化任务的 AI 智能体。无论是浏览器自动化代理、API 驱动机器人、交易型智能体、社交媒体自动化工具,还是数据爬虫代理,抑或任何需要与 Web 服务深度交互的自主系统,此技能都能助你轻松驾驭。触发条件包括:“AI 智能体”、“自主机器人”、“Web 自动化”、“浏览器代理”、“API 代理”、“交易机器人”、“数据爬虫”、“自主系统”,或任何需要 AI 独立操作网站或服务的任务。

SKILL.md
--- frontmatter
name: ai-agent-builder
description: Build autonomous AI agents that operate on websites, interact with APIs, and perform automated tasks. Use when creating browser automation agents, API-driven bots, trading agents, social media automation, data scraping agents, or any autonomous system that needs to interact with web services. Triggers on requests for "AI agent", "autonomous bot", "web automation", "browser agent", "API agent", "trading bot", "scraper", "autonomous system", or any task requiring an AI to independently operate on websites or services.

AI Agent Builder

Build production-ready autonomous AI agents that interact with websites, APIs, and blockchain.

Architecture

Every agent has 5 layers:

code
agent/
├── perception/     # How agent sees (browser, API, WebSocket, chain)
├── brain/          # How agent thinks (LLM integration)
├── actions/        # What agent can do (click, type, transact)
├── memory/         # What agent remembers (context, patterns)
└── orchestrator/   # Decision loop (ReAct pattern)

Build Workflow

  1. Define objective — What should agent accomplish autonomously?
  2. Choose perception — Browser (Playwright), API polling, WebSockets, or hybrid
  3. Design actions — What operations can agent perform?
  4. Select brain — Which LLM and reasoning pattern
  5. Implement memory — Short-term context + optional long-term learning
  6. Build orchestrator — The ReAct loop tying everything together
  7. Add safeguards — Max steps, confirmations, error handling

Perception Layer

TargetToolUse When
Modern web appsPlaywrightJS-heavy, SPAs, auth required
Static sitesCheerio + fetchSimple scraping, speed priority
APIsfetch/axiosDirect API access available
Real-time dataWebSocketsLive feeds, trading, notifications
Blockchain@solana/web3.js, ethersOn-chain data, wallet ops

See references/perception.md for implementation patterns.

Brain Layer

ProviderModelBest For
AnthropicClaude 3.5/4Complex reasoning, tool use
OpenAIGPT-4oGeneral tasks, vision
GroqLlama/MixtralSpeed-critical
LocalOllamaPrivacy, no API costs

See references/brain.md for LLM integration and prompt patterns.

Action Layer

Actions are tools the LLM can call:

javascript
const tools = [
  { name: "navigate", description: "Go to URL", input: { url: "string" } },
  { name: "click", description: "Click element", input: { selector: "string" } },
  { name: "type", description: "Type text", input: { selector: "string", text: "string" } },
  { name: "extract", description: "Get text from element", input: { selector: "string" } },
  { name: "screenshot", description: "Capture page state" },
  { name: "wait", description: "Wait milliseconds", input: { ms: "number" } },
  { name: "complete", description: "Mark task done", input: { summary: "string" } },
];

See references/actions.md for full action catalog.

Memory Layer

Short-term: Sliding window of recent actions + observations (fits in context)

Long-term (optional): SQLite/JSON for pattern persistence across sessions

javascript
class Memory {
  constructor(maxHistory = 20) {
    this.history = [];
    this.maxHistory = maxHistory;
  }

  add(entry) {
    this.history.push({ ...entry, timestamp: Date.now() });
    if (this.history.length > this.maxHistory) this.history.shift();
  }

  getContext() {
    return this.history.map((h) => `[${h.type}] ${h.content}`).join("\n");
  }
}

See references/memory.md for advanced patterns.

Orchestrator (ReAct Loop)

The core decision loop:

javascript
async function agentLoop(objective, maxSteps = 50) {
  const memory = new Memory();

  for (let step = 0; step < maxSteps; step++) {
    // 1. Build prompt with objective + memory
    const prompt = buildPrompt(objective, memory.getContext());

    // 2. Get LLM decision (tool call)
    const decision = await brain.decide(prompt, tools);

    // 3. Execute action
    const result = await executeAction(decision.tool, decision.input);

    // 4. Store in memory
    memory.add({ type: "action", content: `${decision.tool}: ${JSON.stringify(decision.input)}` });
    memory.add({ type: "observation", content: result });

    // 5. Check completion
    if (decision.tool === "complete") {
      return { success: true, summary: decision.input.summary };
    }
  }

  return { success: false, reason: "max_steps_exceeded" };
}

Quick Start Template

Use assets/templates/general-agent/ for a working foundation:

bash
cp -r assets/templates/general-agent ./my-agent
cd my-agent
npm install
# Edit config in agent.js
node agent.js "Your objective here"

Safety Rules

  1. Max steps — Always set a limit (default: 50)
  2. Confirmation — Require human approval for destructive actions
  3. Rate limiting — Don't hammer APIs/sites
  4. Error recovery — Graceful handling, retry with backoff
  5. Logging — Record all actions for debugging
  6. Scope limits — Restrict domains/actions agent can access

Reference Files

  • references/perception.md — Browser, API, WebSocket, blockchain patterns
  • references/brain.md — LLM integration, prompts, tool calling
  • references/actions.md — Full action catalog with examples
  • references/memory.md — Context management, persistence
  • references/use-cases.md — Complete implementations: trading bots, scrapers, social agents