关于 Mirrors
Mirrors 是 mirrorkit 的 Go 版本,用于将调用方提供的 LLM Agent 跟踪数据发送到 Mirrors 后端。它适合需要后台批量传输、但不需要 SDK 插桩或运行 Agent 的 Go 应用。
主要功能
- 01记录跟踪数据和工具调用消息
- 02在后台批量发送跟踪数据
- 03配置端点、队列和批次限制
- 04刷新或关闭收集器
- 05创建多个独立客户端
适用场景
- 01将 Go Agent 跟踪数据发送到 Mirrors 后端
- 02记录工具调用及其结果消息
- 03在应用关闭前排空待发送数据
配置
远程服务无需本地安装。选择你使用的客户端,复制配置或使用一键安装。
https://api.runmirrors.com/mcpclaude mcp add --transport http com-runmirrors-mirrors https://api.runmirrors.com/mcp{"mcpServers":{"com-runmirrors-mirrors":{"type":"http","url":"https://api.runmirrors.com/mcp"}}}在 Cursor 中打开{"servers":{"com-runmirrors-mirrors":{"type":"http","url":"https://api.runmirrors.com/mcp"}}}在 VS Code 中打开{"mcpServers":{"com-runmirrors-mirrors":{"type":"http","url":"https://api.runmirrors.com/mcp"}}}{"mcpServers":{"com-runmirrors-mirrors":{"serverUrl":"https://api.runmirrors.com/mcp"}}}命令在终端中运行;JSON 粘贴到对应客户端的 MCP 配置后重启。需要授权的服务会在首次连接时提示登录。
工具
详细介绍
mirrorkit(Go)
面向 LLM Agent 的轻量级、可直接替换使用的生产级追踪收集器——Python mirrorkit 和 TypeScript mirrorkit(npm)包的 Go 版本。
它只做一件事:接收你提供的追踪记录,并将其发送到你的 Mirrors 后端——在后台批量发送,不阻塞,且安全(调用 Init 后绝不会导致你的应用发生 panic)。它不会检测 SDK,也不会运行 Agent;追踪记录由你构建,它负责发送。
安装
go get github.com/ai-singhal/mirrorkit-go
需要 Go ≥ 1.21。零依赖(仅使用标准库)。
用法
package main
import (
"time"
mirrorkit "github.com/ai-singhal/mirrorkit-go"
)
func main() {
mirrorkit.Init(mirrorkit.Options{APIKey: "mk_live_...", Project: "my-agent"})
defer mirrorkit.Shutdown(5 * time.Second)
mirrorkit.LogTrace([]mirrorkit.Message{
mirrorkit.SystemMessage("You are a helpful assistant."),
mirrorkit.UserMessage("What's the weather in Paris?"),
mirrorkit.AssistantMessage("It's 18C and sunny."),
}, mirrorkit.WithModel("claude-opus-4-8"))
}
每条追踪记录都会排入队列,并由后台 goroutine 刷新至 {endpoint}/api/collect(Authorization: Bearer <apiKey>,请求体为 {project, traces})。
工具调用
使用辅助函数构建工具调用和工具结果消息:
mirrorkit.LogTrace([]mirrorkit.Message{
mirrorkit.UserMessage("Cancel booking BK-4471."),
mirrorkit.AssistantToolCalls(
mirrorkit.NewToolCall("call_1", "cancel_booking", map[string]any{"id": "BK-4471"}),
),
mirrorkit.ToolResult("call_1", `{"status":"cancelled"}`),
mirrorkit.AssistantMessage("Done — BK-4471 is cancelled."),
})
选项
mirrorkit.Init(mirrorkit.Options{
APIKey: "mk_live_...", // required
Project: "my-agent", // default "default"
Endpoint: "https://api.mirror.dev", // else MIRRORKIT_ENDPOINT / MIRROR_ENDPOINT / prod
FlushInterval: 2 * time.Second, // ms between background flushes
MaxBatch: 50, // max traces per POST
MaxQueue: 10_000, // in-memory cap; oldest dropped past this
Debug: false, // internal debug logs (or MIRRORKIT_DEBUG=1)
})
端点解析顺序:Options.Endpoint → MIRRORKIT_ENDPOINT → MIRROR_ENDPOINT
→ 生产环境默认值。
生命周期
mirrorkit.Flush(5 * time.Second) // block until the queue drains
mirrorkit.Shutdown(5 * time.Second) // stop the background goroutine (flushes first)
建议每个进程使用一个收集器,通过包级别的 Init / LogTrace /
Flush / Shutdown 操作。若需要多个相互独立的收集器,请使用 NewClient,并在返回的 *Client 上调用
LogTrace / Flush / Shutdown。
测试
cd mirrorkit-go && go vet ./... && go test ./...
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。