
所有人都在谈 AI agents。但如果你问大多数人,agent 到底是什么,你得到的往往是一个含糊回答:“能自主做事的 AI。”
真实情况比这更有用。Agents 不是一个类别。它们是一条谱系。
这篇指南会解释,不同 AI 工具在这条谱系上分别处于什么位置,基础 LLM 交互和真正的 agent 式工作流之间有什么区别,以及如何用 Claude Code 构建你自己的 agent,并把它接到 Telegram 上,而且不需要你自己写代码。
开始之前,欢迎在 X 上关注我,并加入我刚创建的 Telegram 频道。我每天都会在那里发布更多 AI 内容。两者都是免费的。
X - https://x.com/AnatoliKopadze
Telegram - https://t.me/kopadzemp
什么让一个东西成为 Agent
问 Claude “我今天应该发什么?”不是 agent。那只是聊天。
告诉 Claude “找出现在 AI 领域最热门的三个话题,选出最有互动潜力的一个,用我的风格起草一篇帖子,并保存到文件里”,然后它在你什么都不用碰的情况下完成所有这些,这才是 agent。
区别不在模型。而在模型周围的结构。
Agent 拥有普通聊天没有的三样东西。它能自己调用的工具:搜索、文件系统、代码执行、外部 API。能跨任务持续存在的记忆,而不只是一次会话内的上下文。以及一个会持续运行直到任务完成的循环,而不是生成一条回复就结束。
你加入这三样东西越多,自己介入得就越少。这就是核心想法。
谱系:从聊天到 Agent
一端是基础聊天。你提问,Claude 回答,会话结束。没有工具,没有持续目标,也没有在现实世界中行动的能力。
往上一档:启用工具的 Claude。当 Claude 在回答前搜索网页、读取附件文件,或者生成图片时,它就已经有一点 agentic 了。你没有一步步告诉它做这些事,它自己判断需要这么做。
再往上:多步骤工作流。你给出目标,Claude 把目标拆成步骤,逐步执行,检查结果,并交付完成品。步骤之间不需要你介入。
最高处:完全自主的 agents。Agent 按计划运行,监控输入,调用外部服务,并在没有人类介入的情况下完成复杂任务。你只需设定一次目标,然后检查输出。
底部和顶部之间的区别,不是换了一个模型。而是模型周围有什么:它能调用的工具、能承载上下文的记忆,以及会一直运行到任务完成的循环。
今天你可以构建的 Agent 类型
为了让你了解今天的 agents 实际可以长什么样,我在下面整理了几个例子。这些不是限制;你可以根据自己的具体情况构建任何适合你的东西。**
研究 agent:** 收集某个主题的信息,阅读多个来源,提取重要内容,并交付结构化摘要。你给它一个问题。它给你一个答案,而这个答案如果手动整理,可能要花好几个小时。
写作 agent: 按照你定义的系统写内容。给它你的语气、格式、受众和主题。它会处理初稿、改写和编辑,不需要你管理每一句话。
代码 agent: 写代码、运行代码、读取错误、修复错误,并继续推进。你描述代码应该做什么。Agent 处理实现和调试循环。
业务 agent: 处理重复性的业务任务:起草邮件、处理客户请求、筛选线索、生成报告。只要定义好规则,它就能自动运行。
个人 agent: 管理你的日程,整理任务,准备简报,并处理你每天手动做的规划工作。
构建你的第一个 Agent:从这里开始
你将使用 Claude Code 构建一个 Telegram bot。它运行在远程服务器上,并使用 Claude 作为大脑。Claude Code 会为你写所有代码,你只需要用普通英文描述自己想要什么。设置完成后,所有和 bot 的沟通都会直接通过 Telegram 发生。
整个设置大约需要 10–20 分钟。你不需要懂代码。
系统提示词模板:粘贴到 Prompt 2 中
当你运行下面设置流程中的 Prompt 2 时,需要描述你想要哪种 agent。这些是现成模板。复制适合你的那一个,把它粘贴到 Prompt 2 里 “The agent should be:” 的位置,Claude Code 就会构建对应的 agent。你可以按自己的情况调整任何细节。
研究 Agent
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
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
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
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
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 - 一个来自 console.anthropic.com 的 Claude API key。这是开发者 key,按使用量付费,不是固定月费。对于一个每天发送 50 条消息的个人 bot,成本大约是每月 1–5 美元,具体取决于你选择哪个模型。
2- 一个来自 BotFather 的 Telegram bot token。
3 - 一台运行 Linux 的 VPS。对于个人 Telegram bot,你不需要多强的机器——1 个 CPU、1GB RAM 和 20GB 存储就足够了。DigitalOcean、Hetzner 或 Vultr 的任何基础套餐都可以,费用大约每月 4 到 6 美元。拿到服务器后,在终端里运行 *** npm i -g @anthropic-ai/claude-code*** 安装 Claude Code。
你的 bot 应该用哪个 Claude 模型,以及实际成本是多少:

对大多数个人 bot 来说,Sonnet 4.6 是正确选择,足够强,可以处理任何任务,也适合日常使用的预算。如果你想尽量降低成本,就用 Haiku 4.5。Opus 4.8 只有在复杂分析型 agent、且答案质量非常关键时才有意义。
构建你的第一个 Agent:步骤 1
打开你的 VPS 终端并启动 Claude Code。粘贴这个提示词,让它构建所有东西。
给 agent 一个个性
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.
部署为后台服务
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.
在会话之间加入持久记忆
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.
给你的 Claude Code Bot 添加 Skills
Skills 是你可以逐步给 bot 添加的能力。每一个 skill 都是你给 Claude Code 的一个新提示词,然后它会写出代码,让这个能力可用。下面是最有用的几个。
**Skill:网页搜索 **你的 agent 可以查询实时信息,而不是只凭记忆回答。
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.
**Skill:保存笔记 **你的 agent 可以把你告诉它的任何东西保存到文件里——想法、任务、研究发现,并在之后取回。
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.
Skill:只允许你的账号使用 默认情况下,任何找到你 bot 的人都可以使用它,并消耗你的 API 额度。这个 skill 会把它限制为只有你能用。
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.
Skill:跟踪 API 成本 Claude API 按 token 收费。这个 skill 会添加一个简单的成本跟踪器,让你随时知道自己花了多少钱。
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.
**Skill:定时每日简报 **这个 agent 会每天早上主动给你发消息,不需要你开口。
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 的个性。打开主 bot 文件,找到顶部的系统提示词变量,修改它,保存文件,然后用 sudo systemctl restart your-bot-name 重启服务。新个性会立刻生效。
如何检查 bot 是否正在运行。在终端里运行 *** sudo systemctl status your-bot-name***。如果显示 “active (running)”,说明它正常工作。如果显示 “failed”,就检查日志。
如何读取日志。运行 *** journalctl -u your-bot-name -n 50*** 查看最近 50 行。这是出问题时查找错误消息的地方。
如何添加新 skill。在项目文件夹中打开 Claude Code,描述你想要什么:“Add X feature to the bot.” Claude Code 会读取你的现有代码,干净地添加新功能,并告诉你是否需要重启。
每个 Agent 都有的记忆问题
这是人们最常遇到的问题。Agent 会在会话之间、长任务中、消息过多之后丢失上下文,然后开始犯错,或者重复做已经做过的工作。
**这种情况有三种发生方式: ** 长任务最终会超过 Claude 的上下文限制,agent 开始丢失对话开头的信息:原始目标、已经做出的决定、你设定的约束。
当你关闭一个会话并打开新会话时,agent 会从零开始。-
如果 agent 在任务中途被打断,它没有办法知道自己停在哪里。
**有四件事可以解决这个问题: ** 让 agent 在每个主要步骤之后写一条进度记录:已经完成了什么、做出了什么决定、还有什么需要做。把这条记录粘贴到下一次会话开头,就能恢复完整上下文。
每过十到十五条消息,就让 agent 总结一下当前进展。这会迫使它在上下文溢出前压缩上下文。
在对话变得太长之前,让 agent 把所有重要内容压缩成一段简短总结,并从那里继续。线程仍然保持连续。
把你的 agent 总是需要的关键事实直接加入 bot 代码里的系统提示词。Claude 会在每次对话开始时读取这些内容,所以无论对话多长,这些信息都会始终在上下文里。
检查点提示词
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.
记忆文件提示词
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.
上下文恢复提示词
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.
滚动摘要提示词
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.
现在你已经知道 agents 是什么、它们能做什么,以及如何自己构建一个。希望这对你有用。
如果你想持续了解 AI 领域正在发生的一切,欢迎在 X 和 Telegram 上关注我。
X - https://x.com/AnatoliKopadze Telegram - https://t.me/kopadzemp