# AI Agents. What they are and how to Build Your Own Step by Step.
**作者**: Anatoli Kopadze
**日期**: 2026-06-08T14:04:50.000Z
**来源**: [https://x.com/AnatoliKopadze/status/2063985608381362576](https://x.com/AnatoliKopadze/status/2063985608381362576)
---

Everyone is talking about AI agents. But if you ask most people what an agent actually is, you get a vague answer about "AI that does things autonomously."
The real picture is more useful than that. Agents are not a category. They are a spectrum.
This guide explains where on that spectrum different AI tools sit, what separates a basic LLM interaction from a true agentic workflow, and how to build your own agent with Claude Code and connect it to Telegram, without writing code yourself.
Before we get into it, follow me on X and join my Telegram channel I just created where I post more AI content every day. Both are free.
X - https://x.com/AnatoliKopadze
Telegram - https://t.me/kopadzemp
## What Makes Something an Agent
Asking Claude "what should I post today?" is not an agent. That is a chat.
Telling Claude "find the three topics trending in AI right now, pick the one with the most engagement potential, draft a post in my style, and save it to a file" and having it do all of that without you touching anything, that is an agent.
The difference is not the model. It is the structure around it.
An agent has three things a regular chat does not. Tools it can call on its own: search, file systems, code execution, external APIs. Memory that persists across tasks, not just within one session. And a loop that keeps running until the task is finished, not until it generates one response.
The more of those three things you add, the less you are involved. That is the idea.
## The Spectrum: From Chat to Agent
At one end you have a basic chat. You ask, Claude answers, the session ends. No tools, no ongoing goal, no ability to act in the world.
One step up: Claude with tools enabled. When Claude searches the web before answering, reads an attached file, or generates an image, it is already slightly agentic. You did not tell it to do those things step by step, it decided on its own that it needed to.
Further up: multi-step workflows. You give a goal, Claude breaks it into steps, executes each one, checks the result, and delivers a finished output. You are not involved between steps.
At the top: fully autonomous agents. The agent runs on a schedule, monitors inputs, calls external services, and completes complex tasks without a human in the loop. You set the goal once and check the output.
The difference between the bottom and the top is not a different model. It is what surrounds the model, tools it can call, memory that carries context, and a loop that keeps running until the task is done.
## Types of Agents You Can Build Today
To give you a sense of what agents can actually look like today, I put together a few examples below. These are not limits you can build whatever fits your specific situation.
Research agent: gathers information on a topic, reads multiple sources, pulls out what matters, and delivers a structured summary. You give it a question. It gives you an answer that would have taken hours to compile manually.
Writing agent: writes content according to a system you define. Give it your tone, format, audience, and topic. It handles drafts, rewrites, and edits without you managing every sentence.
Code agent: writes code, runs it, reads the errors, fixes them, and keeps going. You describe what the code should do. The agent handles the implementation and debugging loop.
Business agent: Handles repetitive business tasks: drafting emails, processing customer requests, qualifying leads, generating reports. Runs on autopilot once you define the rules.
Personal agent: Manages your schedule, organizes tasks, prepares briefings, and handles the planning work you do manually every day.
## Building Your First Agent - Start Here
You will use Claude Code to build a Telegram bot that runs on a remote server and uses Claude as its brain. Claude Code writes all the code for you, you just describe what you want in plain English. Once it is set up, all communication with the bot happens directly through Telegram.
The whole setup takes about 10-20 minutes. You do not need to know how to code.
## System Prompt Templates - Paste Into Prompt 2
When you run Prompt 2 from the setup below, you need to describe what kind of agent you want. These are ready-made templates, copy the one that fits, paste it into Prompt 2 where it says "The agent should be:", and Claude Code will build that specific agent. Adjust any details to match your situation.
Research 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.
```
Writing 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.
```
Code 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
```
Business Email 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.
```
Personal Planning 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.
```
## What you need before starting
1 - a Claude API key from console.anthropic.com. This is a developer key, you pay per usage, not a fixed monthly fee. For a personal bot sending 50 messages a day, the cost is $1-5 per month depending on which model you choose.
2- a Telegram bot token from BotFather.
3 - a VPS running Linux. For a personal Telegram bot you do not need anything powerful - 1 CPU, 1GB RAM, and 20GB of storage is more than enough. Any basic plan from DigitalOcean, Hetzner, or Vultr will work, and costs around $4 to $6 per month. Once you have the server, install Claude Code by running npm i -g @anthropic-ai/claude-code in your terminal.
Which Claude model to use for your bot and what it actually costs:

For most personal bots Sonnet 4.6 is the right choice, strong enough for any task and affordable for daily use. Use Haiku 4.5 if you want to minimize cost. Opus 4.8 only makes sense for a complex analytical agent where answer quality is critical.
## Building Your First Agent - Step 1
Open your VPS terminal and launch Claude Code. Paste this prompt and let it build everything.
Give the agent a personality
```
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.
```
Deploy as a background service
```
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.
```
Add persistent memory between sessions
```
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.
```
## Adding Skills to Your Claude Code Bot
Skills are capabilities you add to your bot over time. Each one is a new prompt you give Claude Code, and it writes the code to make it work. Here are the most useful ones.
Skill: Web search
Your agent can look up real-time information instead of answering from memory only.
```
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: Save notes
Your agent can save anything you tell it to a file - ideas, tasks, research findings and retrieve them later.
```
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: Restrict to your account only
By default anyone who finds your bot can use it and consume your API credits. This locks it to just you.
```
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: Track API costs
Claude API charges per token. This adds a simple cost tracker so you always know what you are spending.
```
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: Scheduled daily briefing
The agent sends you a message every morning without you having to ask.
```
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.
```
## Useful Things to Know After Setup
How to update your agent's personality. Open the main bot file, find the system prompt variable at the top, change it, save the file, and restart the service with sudo systemctl restart your-bot-name. The new personality is live immediately.
How to check if the bot is running. Run sudo systemctl status your-bot-name in your terminal. If it says "active (running)" it is working. If it says "failed" check the logs.
How to read logs. Run journalctl -u your-bot-name -n 50 to see the last 50 lines. This is where you find error messages if something breaks.
How to add a new skill. Open Claude Code in your project folder and describe what you want: "Add X feature to the bot." Claude Code reads your existing code, adds the new feature cleanly, and tells you if a restart is needed.
## The Memory Problem Every Agent Has
This is the most common problem people run into. The agent loses context between sessions, across long tasks, after too many messages and starts making mistakes or repeating work it already did.
There are three ways this happens:
Long tasks eventually exceed Claude's context limit, and the agent starts losing the beginning of the conversation: the original goal, decisions already made, constraints you set.
When you close a session and open a new one, the agent starts from zero. -
If the agent is interrupted mid-task, it has no way to know where it stopped.
Four things can fix this:
Tell the agent to write a progress note after every major step: what was done, what was decided, what still needs to happen. Paste that note at the start of the next session to restore full context.
Every ten to fifteen messages, ask the agent to summarize where it is. This forces it to compress context before it overflows.
Before the conversation gets too long, ask the agent to compress everything into a short summary and continue from there. The thread stays intact.
Add the key facts your agent always needs directly to the system prompt in your bot code. Claude reads this at the start of every conversation, so that information is always in context no matter how long things get.
Checkpoint Prompt
```
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.
```
Memory File Prompt
```
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.
```
Context Recovery Prompt
```
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.
```
Rolling Summary Prompt
```
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.
```
You now know what agents are, what they can do, and how to build one yourself. I hope this was useful.
If you want to stay up to date with everything happening in AI, follow me on X and Telegram.
X - https://x.com/AnatoliKopadze
Telegram - https://t.me/kopadzemp
## 相关链接
- [Anatoli Kopadze](https://x.com/AnatoliKopadze)
- [@AnatoliKopadze](https://x.com/AnatoliKopadze)
- [217K](https://x.com/AnatoliKopadze/status/2063985608381362576/analytics)
- [https://x.com/AnatoliKopadze](https://x.com/AnatoliKopadze)
- [https://t.me/kopadzemp](https://t.me/kopadzemp)
- [console.anthropic.com](https://console.anthropic.com/)
- [@anthropic](https://x.com/@anthropic)
- [https://x.com/AnatoliKopadze](https://x.com/AnatoliKopadze)
- [https://t.me/kopadzemp](https://t.me/kopadzemp)
- [Upgrade to Premium](https://x.com/i/premium_sign_up)
- [10:04 PM · Jun 8, 2026](https://x.com/AnatoliKopadze/status/2063985608381362576)
- [217.6K Views](https://x.com/AnatoliKopadze/status/2063985608381362576/analytics)
- [View quotes](https://x.com/AnatoliKopadze/status/2063985608381362576/quotes)
---
*导出时间: 2026/6/9 13:45:51*
---
## 中文翻译
# AI Agent(智能体):它们是什么以及如何一步步构建你自己的 Agent
**作者**: Anatoli Kopadze
**日期**: 2026-06-08T14:04:50.000Z
**来源**: [https://x.com/AnatoliKopadze/status/2063985608381362576](https://x.com/AnatoliKopadze/status/2063985608381362576)
---

每个人都在谈论 AI Agent(智能体)。但如果你问大多数人 Agent 到底是什么,你会得到一个关于“能自主做事的 AI”的模糊答案。
真实的图景比那更有用。Agent 并不是一个分类,它是一个谱系。
本指南解释了不同的 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 拥有普通聊天所不具备的三样东西:
1. **工具**:它可以自主调用搜索、文件系统、代码执行、外部 API。
2. **记忆**:记忆在任务之间持久保存,而不仅仅是在一次会话中。
3. **循环**:循环会持续运行直到任务完成,而不是直到生成一个回复就停止。
你添加的这三样东西越多,你的介入就越少。这就是核心思想。
## 谱系:从聊天到 Agent
在一端是基础聊天。你提问,Claude 回答,会话结束。没有工具,没有持续的目标,没有在世界中行动的能力。
进阶一步:启用工具的 Claude。当 Claude 在回答前搜索网络、阅读附加文件或生成图片时,它已经略带 Agent 属性了。你没有让它一步步做这些事,它自己判定需要这么做。
再进阶:多步工作流。你给出一个目标,Claude 将其分解为步骤,执行每一步,检查结果,并交付最终输出。你不需要在步骤之间介入。
顶端:完全自主的 Agent。Agent 按计划运行,监控输入,调用外部服务,并在无人工干预的情况下完成复杂任务。你设定一次目标,然后检查输出。
低端和高端的区别不在于不同的模型。而在于围绕模型的一切:它可以调用的工具、承载上下文的记忆,以及持续运行直到任务完成的循环。
## 你今天可以构建的 Agent 类型
为了让你对 Agent 在现实中的样子有个概念,我在下面整理了几个例子。这些并不是限制,你可以构建任何适合你具体情况的东西。
**研究型 Agent(Research agent)**:收集关于某个主题的信息,阅读多个来源,提取关键内容,并交付结构化的摘要。你给出一个问题。它给你一个原本需要数小时手动整理才能得到的答案。
**写作型 Agent(Writing agent)**:按照你定义的系统撰写内容。给它你的语调、格式、受众和主题。它处理草稿、重写和编辑,无需你管理每一句话。
**代码型 Agent(Code agent)**:编写代码,运行它,阅读报错,修复错误,并继续推进。你描述代码应该做什么。Agent 处理实现和调试的循环。
**商务型 Agent(Business agent)**:处理重复性的商务任务:起草邮件、处理客户请求、筛选销售线索、生成报告。一旦定义了规则,它就会自动运行。
**私人 Agent(Personal agent)**:管理你的日程,组织任务,准备简报,并处理你每天手动做的规划工作。
## 构建你的第一个 Agent - 从这里开始
你将使用 Claude Code 构建一个运行在远程服务器上的 Telegram 机器人,并使用 Claude 作为它的大脑。Claude Code 会为你编写所有代码,你只需要用简单的英语描述你想要的东西。一旦设置完成,与机器人的所有沟通都直接通过 Telegram 进行。
整个设置大约需要 10-20 分钟。你不需要知道如何编写代码。
## 系统提示词模板 - 粘贴到提示词 2 中
当你运行下文设置中的“提示词 2”时,你需要描述你想要什么样的 Agent。以下是现成的模板,复制适合你的那个,粘贴到“提示词 2”中写有“The agent should be:”的地方,Claude Code 就会构建那个特定的 Agent。你可以根据你的情况调整任何细节。
**研究型 Agent**
```
你是一个研究型 Agent。你的工作是收集、分析和综合我给你的任何主题的信息。
当接到研究任务时:
1. 确定需要回答的 3-5 个最重要的子问题
2. 搜索每一个问题的信息
3. 评估每个来源的质量和相关性
4. 仅提取直接回答问题的内容
5. 提供结构化摘要,包括:关键发现、支持证据以及你无法填补的空白
格式:使用标题、要点和清晰的章节。
如果你对某些事情不确定,请明确说明。
不要添加填充内容。每句话都应包含信息。
```
**写作型 Agent**
```
你是一个写作型 Agent。你用我的声音和风格撰写内容。
我的风格:
- 对话式、直接、无官僚语言
- 短句和短段落
- 具体的数字和例子胜过模糊的声明
- 总是以读者应该做或思考的事情作为结尾
当接到写作任务时:
1. 如果未提供,询问主题、受众和期望长度
2. 写初稿
3. 根据我的风格规则进行审查
4. 准备好发布最终版本
永远不要添加不必要的介绍。从最重要的观点开始。
```
**代码型 Agent**
```
你是一个代码型 Agent。你的工作是编写、调试和改进代码。
当接到编码任务时:
1. 确认你对代码应做的事情的理解
2. 编写带有清晰注释的解决方案
3. 识别任何边缘情况或潜在故障
4. 如果有错误,在寻求帮助前系统地调试它们
规则:
- 编写整洁、可读的代码,使用有意义的变量名
- 始终包含错误处理
- 用通俗语言解释每个主要部分的作用
- 如果你对要求不确定,在继续之前问一个澄清性问题
```
**商务邮件 Agent**
```
你是一个商务邮件 Agent。你代表我撰写专业的邮件。
我的沟通风格:
- 直接且尊重
- 无不必要的客套
- 第一句话就直奔主题
- 以清晰的下一步行动结束
当接到邮件任务时:
1. 确定邮件的目标(通知、请求、跟进、确认)
2. 写一个反映邮件目的的主题行
3. 起草邮件,最多 3-5 个短段落
4. 以一个明确的行动项目或下一步结束
始终写好即可发送的邮件,而不是带有空白待填的模板。
```
**个人规划 Agent**
```
你是我的个人规划 Agent。你帮助我组织工作、确定任务优先级并规划我的一周。
当我分享我的任务或目标时:
1. 识别什么是紧急的,什么是重要的
2. 根据依赖关系建议现实的顺序
3. 估计每个任务所需的时间
4. 标记任何可以委派或消除的事情
当我描述一个项目时:
- 将其分解为具体的下一步行动
- 识别首先要做的唯一最重要的事情
- 创建一个我可以遵循的简单清单
保持一切实用。没有励志的填充内容。只有计划。
```
## 开始之前你需要什么
1 - 一个来自 console.anthropic.com 的 Claude API 密钥。这是一个开发者密钥,你是按使用量付费,而不是固定的月费。对于一个每天发送 50 条消息的个人机器人,费用大约是每月 1-5 美元,具体取决于你选择的模型。
2 - 一个来自 BotFather 的 Telegram 机器人令牌(token)。
3 - 一台运行 Linux 的 VPS(虚拟专用服务器)。对于个人 Telegram 机器人,你不需要任何强大的配置 —— 1 个 CPU、1GB 内存和 20GB 存储空间就绰绰有余。DigitalOcean、Hetzner 或 Vultr 的任何基础计划都可以,成本约为每月 4 到 6 美元。拿到服务器后,在终端中运行 `npm i -g @anthropic-ai/claude-code` 来安装 Claude Code。
为你的机器人选择哪个 Claude 模型以及实际成本:

对于大多数个人机器人,Sonnet 4.6 是正确的选择,它足够强大以应对任何任务,且足够便宜适合日常使用。如果你想最小化成本,请使用 Haiku 4.5。只有在答案质量至关重要的复杂分析型 Agent 中,Opus 4.8 才有意义。
## 构建你的第一个 Agent - 第 1 步
打开你的 VPS 终端并启动 Claude Code。粘贴这个提示词并让它构建所有内容。
**给 Agent 一个个性**
```
帮我构建一个使用 Claude API 作为大脑的 Telegram 机器人。
要求:
- 语言:Python
- Telegram 库:python-telegram-bot
- Claude 模型:claude-sonnet-4-6
- 机器人接收消息,将其发送给 Claude API,并将 Claude 的响应返回给 Telegram
- 为每个用户维护对话历史 —— 每个用户在会话中都有自己的上下文
- 添加一个 /start 命令来介绍机器人
- 添加一个 /clear 命令来重置该用户的对话历史
创建所有必要的文件:主机器人文件、requirements.txt 和一个用于 API 密钥的 .env 文件模板。
不要硬编码任何 API 密钥 —— 从环境变量中读取它们。
```
**部署为后台服务**
```
创建一个 systemd 服务文件,以便此机器人自动在我的 Linux VPS 上运行,并在崩溃时重启。
该服务应该:
- 在服务器启动时自动启动
- 崩溃时自动重启
- 从项目文件夹中的 .env 文件加载环境变量
- 将日志保存到我可以稍后检查的文件中
还要给我确切的终端命令来安装服务、启动它、检查它是否正在运行以及查看日志。
```
**在会话之间添加持久记忆**
```
机器人在重启时会丢失对话历史。修复这个问题。
每次消息后,将每个用户的对话历史保存到磁盘上的 JSON 文件中。在机器人启动时自动加载回来。
添加一个最大历史长度 —— 每个用户只保留最后 20 条消息,这样上下文窗口永远不会变得太长。
```
## 为你的 Claude Code 机器人添加技能
技能是你随时间添加给机器人的能力。每一个都是你给 Claude Code 的新提示词,它会编写代码使其工作。以下是最有用的一些。
**技能:网络搜索**
你的 Agent 可以查找实时信息,而不仅仅是从记忆中回答。
```
使用 Tavily API 为机器人添加网络搜索功能。
当用户询问需要当前信息的事情 —— 新闻、价格、近期事件时,机器人自动搜索网络并将结果包含在它的回复中。
机器人应该自己决定何时搜索以及何时从记忆中回答。将 TAVILY_API_KEY 添加到 .env 文件模板中。
使用 Claude 的工具使用功能来干净地实现这一点。
```
**技能:保存笔记**
你的 Agent 可以你告诉它的任何内容保存到文件 —— 想法、任务、研究发现 —— 并在以后检索。
```
为机器人添加笔记保存功能。
当用户说 "save this"(保存这个)、"remember this"(记住这个)或 "note:"(笔记:)时,机器人将内容连同时间戳一起保存到 notes.txt 文件中。
添加一个 /notes 命令,返回最后保存的 10 条笔记。
添加一个 /clearnotes 命令,删除所有保存的笔记。
```
**技能:仅限制为你的账户**
默认情况下,任何找到你机器人的人都可以使用它并消耗你的 API 额度。这会将它锁定为仅供你使用。
```
为机器人添加用户限制,以便只有我可以使用它。
将我的 Telegram 用户 ID 作为 ALLOWED_USER_ID 添加到 .env 文件中。
如果其他人给机器人发消息,它回复 "This bot is private."(此机器人是私有的)并忽略该用户的后续所有消息。
还要添加我如何找到自己的 Telegram 用户 ID —— 通过机器人本身或其他方法。
```
**技能:追踪 API 成本**
Claude API 按令牌收费。这会添加一个简单的成本追踪器,让你始终知道你在花什么钱。
```
为机器人添加基本的成本追踪。
在每次 Claude API 响应后,记录使用的输入令牌和输出令牌的数量。
在 costs.json 文件中保持一个运行总计。
添加一个 /costs 命令,显示:今天使用的总令牌数、历史上使用的总令牌数,以及基于 claude-sonnet-4-6 定价的估算成本(美元)。
```
**技能:每日简报**
Agent 每天早上给你发送一条消息,无需你询问。
```
为机器人添加每日简报。
每天早上 8:00,机器人给我发送一条消息,包含:
1. 一句励志的短语(简短,不要俗气)
2. 提醒我检查当天的首要任务
3. 一个关于生产力或 AI 的随机有用事实
将其发送到 .env 文件中的我的 Telegram 用户 ID。
使用 schedule 或 APScheduler 库来实现此功能。
```
## 设置后需要知道的有用事情
**如何更新你 Agent 的个性**
打开主机器人文件,找到顶部的系统提示词变量,修改它,保存文件,然后用 `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 并描述你想要什么:"Add X feature to the bot."(给机器人添加 X 功能)。Claude Code 会阅读你现有的代码,干净地添加新功能,并告诉你是否需要重启。
## 每个 Agent 都有的记忆问题
这是人们遇到的最常见问题。Agent 在会话之间、长时间任务中、过多消息后丢失上下文,并开始犯错或重复它已经做过的工作。
有三种情况会发生这种情况:
1. 长时间任务最终会超过 Claude 的上下文限制,Agent 开始丢失对话的开头:原始目标、已做出的决定、你设定的约束。
2. 当你关闭一个会话并打开一个新的会话时,Agent 从零开始。
3. 如果 Agent 在任务中途被打断,它没有办法知道它停在哪里。
有四件事可以解决这个问题:
1. 告诉 Agent 在每完成一个主要步骤后写一个进度笔记:做了什么,决定了什么,还需要发生什么。在下一个会话开始时粘贴该笔记以恢复完整的上下文。
2. 每隔十到十五条消息,让 Agent 总结一下它目前所处的状况。这会迫使它在上下文溢出之前进行压缩。
3. 在对话变得太长之前,让 Agent 将所有内容压缩成一个简短摘要并从那里继续。线索保持完整。
4. 将 Agent 始终需要的关键事实直接添加到机器人代码的系统提示词中。Claude 在每次对话开始时都会读取这个,所以无论对话变得多长,这些信息总是在上下文中。
**检查点提示词**
```
在继续之前,写一个简短的检查点:
1. 你到目前为止完成了什么?
2. 本次会话的关键决定或发现是什么?
3. 还需要做什么?
4. 在新会话中继续此任务需要什么上下文?
保持在 200 字以内。
```
**记忆文件提示词**
```
在完成每个主要步骤后,按以下格式写一条记忆笔记:
步骤完成:[做了什么]
关键决定:[做出的选择及原因]
当前状态:[任务目前所处的位置]
下一步:[接下来应该发生什么]
此笔记将用于在新会话中恢复任务而不丢失上下文。
```
**上下文恢复提示词**
```
我们正在从之前的会话中恢复任务。这是上下文:
[在此处粘贴你的记忆笔记]
基于此:
1. 确认你的理解