mirrorkit (Go)
A lightweight, drop-in production trace collector for LLM agents โ the Go
sibling of the Python mirrorkit and
TypeScript mirrorkit (npm) packages.
It does exactly one thing: take traces you hand it and send them to your
Mirrors backend โ batched in the background, non-blocking, and safe (it never
panics into your app after Init). It does not instrument SDKs and does
not run agents; you build the trace, it ships it.
Install
go get github.com/ai-singhal/mirrorkit-go
Requires Go โฅ 1.21. Zero dependencies (standard library only).
Usage
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"))
}
Each trace is enqueued and flushed to {endpoint}/api/collect by a background
goroutine (Authorization: Bearer <apiKey>, body {project, traces}).
Build tool-call and tool-result messages with the helpers:
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."),
})
Options
mirrorkit.Init(mirrorkit.Options{
APIKey: "mk_live_...",
Project: "my-agent",
Endpoint: "https://api.mirror.dev",
FlushInterval: 2 * time.Second,
MaxBatch: 50,
MaxQueue: 10_000,
Debug: false,
})
Endpoint resolution: Options.Endpoint โ MIRRORKIT_ENDPOINT โ MIRROR_ENDPOINT
โ the production default.
Lifecycle
mirrorkit.Flush(5 * time.Second)
mirrorkit.Shutdown(5 * time.Second)
Prefer one collector per process via the package-level Init / LogTrace /
Flush / Shutdown. For multiple independent collectors, use NewClient and
call LogTrace / Flush / Shutdown on the returned *Client.
Testing
cd mirrorkit-go && go vet ./... && go test ./...