配合 AI agent 使用
把这些文档交给 Claude Code、Cursor 或任何编程 agent,再用一段提示词把 Lyrelog 加进你的项目。
这里的每个页面同时也是纯 Markdown,编程 agent 可以直接读文档,而不必凭记忆猜测。对 Lyrelog 这样的新服务,它凭记忆往往会猜错。
给 agent 的文件
| 地址 | 内容 |
|---|---|
/llms.txt | 所有页面的索引,附带各页的描述,每一项都链接到对应的 Markdown。这是 agent 会查找的 llms.txt 格式。 |
/llms-full.txt | 所有页面合成一个文件,可以一次性把整套文档放进 agent 的上下文。 |
/<page>.md | 单个页面,例如 /sdks/go.md。 |
每个页面的标题下方还有 Copy Markdown,以及用于发送到 ChatGPT、Claude 或 Cursor 的 Open。
把 Lyrelog 加进项目的提示词
把它粘贴给你的 agent,并用你的采集密钥替换 lyr_ing_...(在项目的 API keys 页面,参见密钥;它只能写入,所以可以放心地打包进应用)。如果你不想让密钥出现在代码仓库里,可以把它放进环境变量,再告诉 agent 变量名。
Add Lyrelog logging to this project. Read https://docs.lyrelog.com/llms.txt first, then the
page of the SDK for this project's language (or the HTTP API page if there's no SDK for it).
Don't rely on what you remember about Lyrelog: follow the docs.
1. Install the SDK and start it once, where the app or service starts, with the ingest key
lyr_ing_... (or from the environment variable LYRELOG_KEY). Keep the default endpoint.
2. Make sure queued events are sent before the process ends: flush or close the client as the
SDK page says for this kind of program (server, CLI, serverless function, app).
3. Capture errors: unhandled ones the way the SDK page shows, and the places in this code that
catch an error and carry on.
4. Log a few events where something happens to a person: sign in, a payment, a sync, a failed
request. Use a stable snake_case name as the message (payment_declined), a level, an area
(category) and attributes with the details to filter by.
5. Identify the person with our own user id (setUser or the SDK's equivalent), never an email
address, and clear it on sign-out.
6. Never put passwords, tokens, keys, cookies, full request bodies or personal data in messages,
attributes or payloads.
7. Tell me which environment the events will arrive under, so I can pick it in the dashboard.SDK 尚未发布,所以 agent 目前还无法安装它们:等发布之后,这段提示词才能用。在此之前,agent 可以通过 HTTP API 发送事件。
让 agent 读取你的事件
借助命令行工具,编程 agent 可以以你的身份搜索事件、查看错误、跟随某个用户走完一次会话。由 agent 运行时,它会输出 JSON。你只需用 lyrelog login 登录一次;agent 无法自行登录。参见供 agent 和脚本使用,那里还有一段用于排查错误的提示词。
小贴士
- 指明页面。 “Read https://docs.lyrelog.com/sdks/python.md and add Lyrelog to the FastAPI app”比让它自己搜索更快也更准确。
- 让它发一个测试事件。 让 agent 在应用启动时记录一个事件,运行一下,确认它已到达(参见快速开始):这是发现密钥或环境配置错误最快的办法。
- 检查它记录了什么。 agent 往往会记录太多日志。每件发生的事对应一个事件,并使用固定的名称,这样比每次函数调用都记一行更容易搜索、绘图,费用也更低。