AAWEA.ORG
AAWEA.ORG
AAWEA.ORG
🤖 AI Tool Reviews

Agent

Jul 01, 2026 10 Views
AI Agent 到底是什么?手把手教你造一个自己的
所有人都在聊 AI Agent。但如果你随便拉一个人问“Agent 到底是什么”,十有八九你会听到一个模糊的答案——“就是能自己干活的 AI 呗”。
真相比这个有意思多了。Agent 不是一个类别,它是一条光谱。
这篇文章会跟你讲清楚:不同 AI 工具到底落在这条光谱的哪个位置,一个普通的聊天对话和一个真正的 Agent 工作流之间差了什么,以及——怎么用 Claude Code 给自己搭一个 Telegram 机器人,全程不用你写一行代码。

聊天 vs Agent:差别不在模型,在结构

你打开 Claude,问一句“我今天该发点什么?”——这不叫 Agent,这叫聊天。
你跟 Claude 说:“找出 AI 圈现在最火的三个话题,挑一个最容易爆的,用我的风格写一篇帖子,存到文件里”——然后它自己一步步全做完,你碰都没碰——这才叫 Agent。
差在哪?不是模型。是模型外面那一层东西。
一个真正的 Agent 有三个东西,普通聊天没有:
第一,它会自己调用工具。 搜索网页、读写文件、执行代码、调外部 API——它自己决定什么时候用什么,不需要你一步一步指挥。
第二,它有记忆,而且是跨任务的。 不是只记住这一次聊天里的内容,而是这次做完的事,下次打开还能接着用。
第三,它有一个循环。 不是生成一句话就停。它会一直跑,直到任务真正完成,中间检查结果、修正错误、继续推进。
这三样东西你加得越多,你需要亲自参与的部分就越少。这就是 Agent 的本质。
你可以把它想象成一条线:
  • 最左端:基础聊天。 你问,AI 答,对话结束。没有工具,没有持续目标,没法对外部世界产生任何影响。
  • 往右一步:带工具的聊天。 AI 在回答之前自己决定去搜索网页、读附件、生成图片。你没有告诉它每一步怎么做,它自己判断需要什么。
  • 再往右:多步骤工作流。 你给一个目标,AI 自己拆成步骤,一步步执行,检查结果,最后给你成品。步骤之间你完全不用管。
  • 最右端:全自动 Agent。 按计划定时运行,自己监控输入,自己调用外部服务,完成复杂任务——人不在循环里。你只需要设一次目标,然后定期看结果。
从头到尾,模型是同一个。变的是模型周围的配置:能调的工具、能记住的上下文、能持续运行的循环。

Agent 能干什么?几种最常见的形态

给你几个真实的例子感受一下。这些不是天花板,而是起点——你可以根据自己的情况搭任何东西。
研究型 Agent: 你给它一个问题,它自己去搜集信息、读多个来源、提取关键内容、整理成一份结构清晰的报告。你原本要花几个小时手动干的活,它几分钟给你答案。
写作型 Agent: 按照你定义的系统来写东西。告诉它你的语气、格式、读者、主题,它自己搞定草稿、改写、编辑,你不需要逐句盯着。
代码型 Agent: 写代码、运行、读报错、修 bug、继续跑——全自动循环。你只需要描述这段代码应该实现什么功能,它自己搞定实现和调试。
商务型 Agent: 处理重复性的工作:写邮件草稿、处理客户请求、筛选潜在客户、生成报告。你定好规则之后它就自己跑。
个人助理型 Agent: 管日程、排任务、准备简报、处理你每天手动做的那些规划工作。

自己动手:0 代码搭一个 Telegram Agent

接下来你会用 Claude Code 搭一个 Telegram 机器人。它跑在远程服务器上,用 Claude 当大脑。Claude Code 帮你写所有代码,你只需要用大白话描述你想要什么。搭好之后,所有和机器人的交流都直接在 Telegram 里完成。
整个流程大约 10-20 分钟。你不需要会编程。
下面第二步的 Prompt 里,你需要描述你想要什么样的 Agent。下面是几个做好的模板,挑一个适合你的,复制粘贴到第二步里“这个 Agent 应该是什么样”的地方。可以根据自己情况改细节。
研究 Agent 模板:
plaintext
You are a research agent. Your job is to gather, analyze, and synthesize information on any topic I give you.

When given a research task:
1. Identify the 3-5 most important sub-questions to answer
2. Search for information on each one
3. Evaluate the quality and relevance of each source
4. Extract only what directly answers the question
5. Deliver a structured summary with: key findings, supporting evidence, and gaps you could not fill

Format: Use headers, bullet points, and clear sections.
If you are uncertain about something, say so explicitly.
Do not add filler. Every sentence should contain information.
写作 Agent 模板:
plaintext
You are a writing agent. You write content in my voice and style.

My style:
- Conversational, direct, no corporate language
- Short sentences and paragraphs
- Specific numbers and examples over vague claims
- Always end with something the reader should do or think about

When given a writing task:
1. Ask for the topic, audience, and desired length if not provided
2. Write a first draft
3. Review it against my style rules
4. Deliver the final version ready to publish

Never add unnecessary introductions. Start with the most important point.
代码 Agent 模板:
plaintext
You are a code agent. Your job is to write, debug, and improve code.

When given a coding task:
1. Confirm your understanding of what the code should do
2. Write the solution with clear comments
3. Identify any edge cases or potential failures
4. If there are errors, debug them systematically before asking for help

Rules:
- Write clean, readable code with meaningful variable names
- Always include error handling
- Explain what each major section does in plain language
- If you are unsure about requirements, ask one clarifying question before proceeding
商务邮件 Agent 模板:
plaintext
You are a business email agent. You write professional emails on my behalf.

My communication style:
- Direct and respectful
- No unnecessary formalities
- Gets to the point in the first sentence
- Closes with a clear next step

When given an email task:
1. Identify the goal of the email (inform, request, follow up, confirm)
2. Write a subject line that reflects the email's purpose
3. Draft the email in 3-5 short paragraphs maximum
4. End with one clear action item or next step

Always write ready-to-send emails, not templates with blanks to fill in.
个人规划 Agent 模板:
plaintext
You are my personal planning agent. You help me organize my work, prioritize tasks, and plan my week.

When I share my tasks or goals:
1. Identify what is urgent vs. important
2. Suggest a realistic sequence based on dependencies
3. Estimate time required for each task
4. Flag anything that could be delegated or eliminated

When I describe a project:
- Break it into concrete next actions
- Identify the single most important thing to do first
- Create a simple checklist I can follow

Keep everything practical. No motivational filler. Just the plan.

准备工作:三样东西

开始之前你需要准备三样东西:
1. Claude API 密钥——去 申请。这是开发者用的密钥,按使用量付费,不是包月订阅。对个人机器人来说,一天发 50 条消息,一个月大概花 1-5 美元,取决于你选哪个模型。
2. Telegram Bot Token——在 Telegram 里找 BotFather,跟它说一声就能创建。
3. 一台跑 Linux 的 VPS(云服务器)。 个人 Telegram 机器人不需要什么性能——1 核 CPU、1GB 内存、20GB 存储绰绰有余。DigitalOcean、Hetzner、Vultr 的最基础套餐都够用,一个月大概 4-6 美元。
拿到服务器之后,在终端里运行 npm i -g -ai/claude-code 安装 Claude Code.

选哪个模型?花多少钱?

图像
对大多数个人机器人来说,Sonnet 4.6 是最合适的选择——能力足够强,日常使用也能承受。想省钱就用 Haiku 4.5。Opus 4.8 只在你要做复杂分析、答案质量至关重要的场景下才值得。

第一步:让机器人活起来

打开 VPS 终端,启动 Claude Code。把下面这段 Prompt 贴进去,让它帮你把所有东西搭好。记得给你的 Agent 一个性格。
plaintext
Build me a Telegram bot that uses the Claude API as its brain.

Requirements:
- Language: Python
- Library for Telegram: python-telegram-bot
- Claude model: claude-sonnet-4-6
- The bot receives a message, sends it to Claude API, and returns Claude's response to Telegram
- Maintain conversation history per user — each user has their own context within the session
- Add a /start command that introduces the bot
- Add a /clear command that resets conversation history for that user

Create all necessary files: main bot file, requirements.txt, and a .env file template for API keys.
Do not hardcode any API keys — read them from environment variables.
给中学生的翻译:这段 Prompt 是在告诉 Claude Code——“帮我在 Python 里写一个 Telegram 机器人,用 Claude 当大脑。每个用户有自己的对话记录,有 /start 介绍自己,有 /clear 清空聊天记录。把所有文件都建好,API 密钥不要写死在代码里,要从环境变量读。”

第二步:部署成后台服务

机器人代码写好了,但你不想每次手动启动它。用下面这段 Prompt 让它变成一个系统服务——服务器一开机就自动跑,崩了自动重启。
plaintext
Create a systemd service file so this bot runs automatically on my Linux VPS and restarts if it crashes.

The service should:
- Start automatically when the server boots
- Restart automatically if it crashes
- Load environment variables from the .env file in the project folder
- Save logs to a file I can check later

Also write me the exact terminal commands to install the service, start it, check if it is running, and view the logs.

第三步:加持久记忆

现在有个问题:机器人重启之后,之前的对话历史全丢了。用下面这段 Prompt 修复它——把对话记录存到文件里,重启自动加载。
plaintext
The bot loses conversation history when it restarts. Fix this.

Save each user's conversation history to a JSON file on disk after every message. Load it back automatically when the bot starts.

Add a maximum history length — keep only the last 20 messages per user so the context window never gets too long.

进阶技能:让你的 Agent 越来越强

“技能”就是你可以随着时间慢慢加到机器人身上的能力。每一个技能就是一段新的 Prompt,丢给 Claude Code,它帮你写代码实现。
技能一:联网搜索
让你的 Agent 能查实时信息,而不是只能靠记忆回答。
plaintext
Add web search capability to the bot using the Tavily API.

When the user asks something that requires current information — news, prices, recent events — the bot automatically searches the web and includes the results in its response.

The bot should decide on its own when to search and when to answer from memory. Add TAVILY_API_KEY to the .env file template.

Use Claude's tool use feature to implement this cleanly.
技能二:保存笔记
让你的 Agent 能把你说的东西存下来——想法、待办、调研结果——随时调取。
plaintext
Add a note-saving feature to the bot.

When the user says "save this", "remember this", or "note:", the bot saves the content to a notes.txt file with a timestamp.

Add a /notes command that returns the last 10 saved notes.
Add a /clearnotes command that deletes all saved notes.
技能三:锁定只有你能用
默认情况下,任何人找到你的机器人就能用它,消耗你的 API 额度。这段 Prompt 把它锁成只有你能用。
plaintext
Add user restriction to the bot so only I can use it.

Add my Telegram user ID to the .env file as ALLOWED_USER_ID.
If anyone else messages the bot, it responds with "This bot is private." and ignores all further messages from that user.

Also add how I can find my own Telegram user ID — either through the bot itself or another method.
技能四:追踪花费
Claude API 按 token 计费。这段 Prompt 加上一个简单的花费追踪器,让你随时知道花了多少钱。
plaintext
Add basic cost tracking to the bot.

After each Claude API response, log the number of input tokens and output tokens used.
Keep a running total in a costs.json file.

Add a /costs command that shows: total tokens used today, total tokens used all time, and an estimated cost in USD based on claude-sonnet-4-6 pricing.
技能五:定时每日简报
让 Agent 每天早上主动给你发消息,不用你问。
plaintext
Add a scheduled daily briefing to the bot.

Every day at 8:00am, the bot sends me a message with:
1. A motivational one-liner (short, not cheesy)
2. A reminder to check my top priority for the day
3. One random useful fact about productivity or AI

Send it to my Telegram user ID from the .env file.
Use the schedule or APScheduler library to implement this.

日常维护:几个你可能会用到的操作

怎么改 Agent 的性格? 打开主机器人文件,找到顶部的 system prompt 变量,改了,保存,然后运行 sudo systemctl restart your-bot-name 重启服务。新性格立刻生效。
怎么检查机器人是不是在运行? 终端里跑 sudo systemctl status your-bot-name。如果显示 “active (running)” 就表示活着。如果显示 “failed”,去看日志。
怎么看日志?journalctl -u your-bot-name -n 50,看最近 50 行。出问题的时候错误信息都在这里。
怎么加新技能? 在项目文件夹里打开 Claude Code,直接描述你想要什么:“给机器人加上 XXX 功能。”Claude Code 会读你现有的代码,干净地把新功能加进去,然后告诉你需不需要重启。

最常踩的坑:上下文丢失

这是人们遇到最多的问题。Agent 在多次对话之间、长任务跑到一半、消息太多之后,开始“失忆”——忘记最初的目标、做过的决定、你设的限制,然后出错或者重复已经干完的活。
有三种情况会导致这个问题:
  1. 长任务超出上下文限制。 Claude 能记住的对话长度是有上限的。太长之后,它会丢掉对话开头的内容——最初的目标、已经做的决定、你设的约束,全忘。
  2. 关掉会话再打开。 Agent 从零开始,之前做的全白费。
  3. 中途被打断。 Agent 不知道上次停在哪了。
四个办法可以解决:
  1. 每完成一个重要步骤,让 Agent 写一条进度笔记。 记录做了什么、做了什么决定、接下来要干嘛。下次打开新会话时把笔记贴进去,上下文全回来了。
  2. 每 10-15 条消息,让 Agent 总结一下进度。 逼它在溢出之前压缩上下文。
  3. 对话变长之前,让 Agent 把所有东西压缩成一段简短总结,从那里继续。 对话线程不变。
  4. 把关键信息直接写进机器人代码的 system prompt 里。 Claude 每次对话开头都会读这个,所以这些信息永远在上下文里,不管聊多久。
下面是你可以直接用的几段 Prompt:
检查点 Prompt:
plaintext
Before we continue, write a brief checkpoint:
1. What have you completed so far?
2. What are the key decisions or findings from this session?
3. What still needs to be done?
4. What context would you need to continue this task in a new session?

Keep it under 200 words.
记忆文件 Prompt:
plaintext
After completing each major step, write a memory note in this format:

STEP COMPLETED: [what was done]
KEY DECISIONS: [choices made and why]
CURRENT STATE: [where the task stands now]
NEXT STEP: [what should happen next]

This note will be used to resume the task in a new session without losing context.
上下文恢复 Prompt:
plaintext
We are resuming a task from a previous session. Here is the context:

[paste your memory note here]

Based on this:
1. Confirm your understanding of where we are
2. Identify the next step
3. Ask any questions needed to continue

Do not repeat work that has already been completed.
滚动总结 Prompt:
plaintext
The conversation is getting long. Compress everything important into a summary:

1. Original goal
2. What has been done and what was found
3. Key decisions made
4. What still needs to happen

After writing the summary, continue from there. Treat this summary as the new starting point.

最后

你现在知道了 Agent 是什么、能干什么、怎么自己搭一个。它不是什么魔法——只是在模型外面加了工具、记忆和循环。但就这三样东西,能让你从一个“和 AI 聊天的人”变成“让 AI 替你干活的人”。
剩下的,就是动手了。
Author
James
James

Software Developer

0 Fans
1 Events
5 Posts
Share Now