用 OpenClaw 搞了个自动赚钱的 AI 助手:每月躺赚 3000+,代码全开源

14 阅读1分钟

从手动搬砖到 AI 自动赚钱,我如何用开源工具搭建了一套被动收入系统

引言:从“人肉”到“AI”的赚钱之路

去年这个时候,我还在手动操作三个副业项目:商品价格监控、社交媒体内容同步、竞品数据追踪。每天下班后还要花 2-3 小时重复这些机械劳动,月收入却只有 1000 多元。直到我发现了 OpenClaw——一个开源的 AI Agent 框架。

三个月前,我用 OpenClaw 搭建了第一个自动化 Agent,现在这个系统每月为我带来 3000+ 的被动收入,而我的时间投入几乎为零。更重要的是,整个系统的搭建成本极低,核心代码完全开源。

今天我就把这套方法完整分享出来,包括核心代码、变现路径和避坑指南。

一、OpenClaw 是什么?为什么它能帮你赚钱?

1.1 不只是另一个 AI 框架

OpenClaw 与其他 AI 框架最大的不同在于它的 “抓取-决策-执行”闭环设计。简单来说,它不仅能理解你的指令,还能主动获取信息、分析决策、执行操作,最后反馈结果。

核心架构包含三个模块:

  • 感知层:通过浏览器自动化、API 调用等方式获取实时数据
  • 决策层:基于 LLM(大语言模型)分析数据并制定行动计划
  • 执行层:自动执行网页操作、API 调用、文件处理等任务

1.2 低成本高回报的技术栈

技术栈组成:
- 核心框架:OpenClaw (Python)
- AI 模型:GPT-3.5/4、Claude、本地模型(按需选择)
- 自动化:Playwright/Selenium
- 部署:Docker + 云服务器(最低配置即可)
- 监控:Prometheus + Grafana(可选)

月成本估算:
- 云服务器:50元(基础配置)
- AI API 调用:20-100元(取决于使用频率)
- 总计:最低 70元/月

二、实战案例:搭建商品差价监控 Agent

下面我以“跨境电商价差监控”为例,展示如何从零搭建一个赚钱的 AI Agent。

2.1 项目需求分析

痛点:同一商品在不同平台(淘宝、拼多多、京东、亚马逊)存在价格差,但人工比价效率极低。

解决方案:OpenClaw Agent 自动监控指定商品,发现价差超过阈值时自动下单低价商品,在高价平台转卖。

2.2 核心代码实现

# 商品监控 Agent 核心代码
import asyncio
from openclaw import Agent, Tool
from openclaw.tools import BrowserTool, APITool, CalculatorTool
from datetime import datetime
import json

class PriceMonitorAgent(Agent):
    def __init__(self):
        super().__init__(
            name="商品价差监控Agent",
            description="自动监控多平台商品价格,发现套利机会",
            model="gpt-3.5-turbo"  # 可替换为更低成本的模型
        )
        
        # 注册工具
        self.register_tool(BrowserTool())
        self.register_tool(APITool())
        self.register_tool(CalculatorTool())
        
        # 监控配置
        self.target_products = [
            {"name": "Apple AirPods Pro", "sku": "B09JQMJHXY"},
            {"name": "Kindle Paperwhite", "sku": "B08N38XPQG"}
        ]
        self.platforms = ["taobao", "pinduoduo", "jd", "amazon"]
        self.profit_threshold = 50  # 最低利润阈值(元)
    
    async def monitor_prices(self):
        """核心监控逻辑"""
        price_data = {}
        
        for product in self.target_products:
            product_name = product["name"]
            price_data[product_name] = {}
            
            for platform in self.platforms:
                # 使用浏览器工具获取价格
                price = await self.get_price_from_platform(
                    platform, 
                    product["sku"]
                )
                
                if price:
                    price_data[product_name][platform] = {
                        "price": price,
                        "timestamp": datetime.now().isoformat(),
                        "url": await self.get_product_url(platform, product["sku"])
                    }
            
            # 分析价差
            arbitrage_opportunities = await self.analyze_arbitrage(
                price_data[product_name]
            )
            
            if arbitrage_opportunities:
                await self.execute_arbitrage(arbitrage_opportunities)
    
    async def get_price_from_platform(self, platform, sku):
        """从不同平台获取价格"""
        browser_tool = self.get_tool("browser")
        
        # 这里简化了实际代码,真实项目需要处理登录、反爬等
        if platform == "taobao":
            url = f"https://item.taobao.com/item.htm?id={sku}"
            price_xpath = "//*[@id='J_StrPrice']//em[@class='tb-rmb-num']"
        
        elif platform == "amazon":
            url = f"https://www.amazon.cn/dp/{sku}"
            price_xpath = "//span[@class='a-price-whole']"
        
        # 使用浏览器自动化获取价格
        price_text = await browser_tool.extract_text(url, price_xpath)
        return self.parse_price(price_text)
    
    async def analyze_arbitrage(self, price_data):
        """使用 LLM 分析套利机会"""
        prompt = f"""
        分析以下商品在不同平台的价格数据,找出套利机会:
        {json.dumps(price_data, indent=2, ensure_ascii=False)}
        
        要求:
        1. 计算各平台价差
        2. 考虑平台手续费(淘宝2%、拼多多1%、京东3%、亚马逊15%)
        3. 利润需超过{self.profit_threshold}元才值得操作
        4. 返回JSON格式:{{"buy_platform": "", "sell_platform": "", "estimated_profit": 0}}
        """
        
        response = await self.llm_call(prompt)
        return json.loads(response)
    
    async def execute_arbitrage(self, opportunity):
        """执行套利操作"""
        # 1. 在低价平台下单
        buy_result = await self.place_order(
            opportunity["buy_platform"],
            opportunity["product_info"]
        )
        
        if buy_result["success"]:
            # 2. 在高价平台创建销售列表
            sell_result = await self.create_listing(
                opportunity["sell_platform"],
                buy_result["order_id"]
            )
            
            # 3. 记录交易
            await self.log_transaction({
                "buy": buy_result,
                "sell": sell_result,
                "estimated_profit": opportunity["estimated_profit"],
                "timestamp": datetime.now().isoformat()
            })
            
            # 4. 发送通知
            await self.send_notification(
                f"✅ 套利交易完成!预计利润:{opportunity['estimated_profit']}元"
            )

# 启动 Agent
async def main():
    agent = PriceMonitorAgent()
    
    # 设置定时任务:每6小时运行一次
    while True:
        await agent.monitor_prices()
        await asyncio.sleep(6 * 3600)  # 6小时

if __name__ == "__main__":
    asyncio.run(main())

2.3 部署与优化

# Dockerfile 示例
FROM python:3.9-slim

# 安装 Chrome 和必要依赖
RUN apt-get update && apt-get install -y \
    wget \
    gnupg \
    unzip \
    && wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list \
    && apt-get update && apt-get install -y google-chrome-stable

# 复制代码
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .

# 启动脚本
CMD ["python", "main.py"]

优化技巧

  1. 使用无头浏览器减少资源占用
  2. 设置合理的请求间隔避免被封
  3. 实现失败重试机制
  4. 添加监控告警(价格异常、API 限额等)

三、更多变现路径:不止于商品监控

3.1 内容创作与分发 Agent

# 简化的内容创作 Agent
class ContentAgent(Agent):
    async def generate_and_publish(self, topic):
        # 1. 爬取热点话题
        trends = await self.scrape_trends()
        
        # 2. 生成多平台内容
        articles = await self.generate_content(trends)
        
        # 3. 自动发布到多个平台
        platforms = ["zhihu", "juejin", "csdn", "weixin"]
        for platform in platforms:
            await self.publish_to_platform(platform, articles)
            
        # 4. 统计阅读数据
        stats = await self.collect_stats()
        
        # 平台收益:
        # - 知乎致知计划:千次阅读 3-10元
        # - 掘金:流量分成 + 征文奖金
        # - 微信公众号:流量主 + 广告

收益模型

  • 平台分成:每月 500-2000 元
  • 接软文:每篇 200-1000 元
  • 引流私域:长期价值

3.2 社交媒体管理 Agent

帮助小型企业管理多个社交媒体账号:

  • 自动回复评论和私信
  • 定时发布内容
  • 分析互动数据
  • 生成运营报告

收费模式:每个账号 100-300 元/月

3.3 数据服务 Agent

# 数据服务示例:竞品监控
class CompetitorMonitor(Agent):
    async def monitor_competitors(self):
        # 监控竞品价格变化
        # 跟踪新品上架情况
        # 分析营销活动效果
        # 生成竞品分析报告
        
        # 输出格式化的报告
        report = await self.generate_report()
        
        # 自动发送给客户
        await self.send_to_customers(report)

目标客户:电商卖家、品牌方、市场分析师 收费标准:每月 300-1000 元/客户

四、避坑指南:我踩过的那些坑

4.1 技术坑

反爬虫应对

# 最佳实践
async def safe_scrape(self, url):
    strategies = [
        self.use_rotating_proxies,  # 代理池
        self.random_delay,           # 随机延迟
        self.mimic_human_behavior,   # 模拟人类行为
        self.use_headless_browser,   # 无头浏览器
        self.handle_captcha          # 验证码处理
    ]
    
    for strategy in strategies:
        try:
            return await strategy(url)
        except Exception as e:
            continue

4.2 商业坑

  1. 平台规则风险:所有自动化操作必须遵守平台 ToS
  2. 资金安全:使用第三方支付接口,不要存储用户支付信息
  3. 法律合规:特别是涉及数据爬取和跨境业务时
  4. 客户沟通:明确告知服务是 AI 驱动的,管理预期

4.3 运营坑

  • 不要过度承诺:AI 会有失误率
  • 设置熔断机制:错误率达到阈值时自动停止
  • 保留人工介入接口:关键决策需要人工确认
  • 定期更新模型:平台变化时需要调整策略

五、进阶玩法:从 Agent 到 Agent 网络

单个 Agent 的能力有限,但多个 Agent 协同工作就能产生质变:

# Agent 网络架构
class AgentNetwork:
    def __init__(self):
        self.agents = {
            "scraper": DataScraperAgent(),      # 数据采集
            "analyzer": DataAnalyzerAgent(),     # 数据分析
            "trader": TradingAgent(),           # 交易执行
            "reporter": ReportAgent(),          # 报告生成
            "monitor": SystemMonitorAgent()     # 系统监控
        }
    
    async def orchestrate(self, task):
        # Agent 间协同工作流
        raw_data = await self.agents["scraper"].collect(task)
        insights = await self.agents["analyzer"].process(raw_data)
        actions = await self.agents["trader"].decide(insights)
        report = await self.agents["reporter"].summarize(actions)
        
        # 监控整个流程
        await self.agents["monitor"].track_performance()
        
        return report

这种架构的扩展性极强,可以轻松增加新的 Agent 来处理更复杂的任务。

六、开始你的 AI 被动收入之旅

6.1 起步建议

  1. 从简单开始:先实现一个单一功能的 Agent
  2. 选择熟悉的领域:电商、内容、