kira-agent 是从 kira-be 拆出的独立 AI agent 服务(公网 agentapi.kira.art,浏览器直连)。一次 agent run 由 POST /task 启动,agent 类的 PostHog 事件全部在这里发。
源:kira-agent/src/ai/agents/index.ts(chat_started)+ kira-agent/src/analytics/index.ts(chat_completion / tool_usage / sub_call)。
全部用 posthog-node,host us.i.posthog.com,带 disableGeoip: true,distinctId = userId。
字段语义约定
kira-agent 严格区分这几个字段(同一语义同时喂 PostHog props 和 Dash0 OTel attrs):
model = 具体的 provider 模型 id 字符串,永远不是 tier。例:qwen3.7-plus、gemini-3.1-flash-lite。
kira_model = Kira 套餐 tier,永远不是 provider id:lite | nova | ultra。
provider = 厂商:dashscope | vertex | byteplus | wavespeed | fal …
task_id = 单次 agent run(一个 POST /task),关联 chat_started ↔ chat_completion ↔ tool_usage。
thread_id = 对话,一个 thread 有多个 task_id。
所有 tier 都解析到同一个 provider 模型 qwen3.7-plus —— lite / nova / ultra 在 resolveBuildOptions() 里全部返回 QWEN_AGENT_MODEL_ID = "qwen3.7-plus",直连 DashScope International(不走 Vercel AI Gateway,这样 submit 才能带 X-DashScope-DataInspection: disable header)。thinking 默认开启。所以 chat_completion.model 当前恒为 qwen3.7-plus,靠 kira_model 区分 tier。
chat_started
agent run 启动信号(PostHog 产品漏斗)。在 buildAgent() 里同步发,跟 chat_completion 用同一个 task_id 配对。
| 属性 | 类型 | 说明 |
|---|
thread_id | string | 对话线程 ID |
task_id | string? | 本次 agent run 的 id(POST /task) |
model | string | provider 模型 id(当前 qwen3.7-plus) |
kira_model | lite|nova|ultra | 套餐 tier |
chat_started 有、chat_completion 无(同 task_id)= 这次 run 在 onFinish 前崩了/断连了。同一个 start 计数也写进 Dash0 的 OTel counter ai.chat.count。
chat_completion
主 agent 完成时触发(ToolLoopAgent 的 onFinish 回调),记录 token 用量(不计算金额)。
| 属性 | 类型 | 说明 |
|---|
thread_id | string | 对话线程 ID |
task_id | string? | agent run id(配对 chat_started) |
model | string | provider 模型 id(当前 qwen3.7-plus) |
kira_model | lite|nova|ultra | 套餐 tier |
input_tokens | number | 输入 token |
output_tokens | number | 输出 token |
cached_input_tokens | number | 命中 context cache 的输入 token(是 input_tokens 的子集;缺省 0) |
reasoning_tokens | number | thinking / CoT token(按 output 计费;缺省 0) |
total_tokens | number | input_tokens + output_tokens |
duration_ms | number | 耗时 (ms) |
tool_calls | number | 本次 run 累计工具调用次数 |
step_count | number? | agent 循环步数(steps.length) |
finish_reason | string? | 末步 finish reason(stop|tool-calls|length…) |
hit_step_cap | boolean? | 是否撞到 stepCountIs() 上限(当前 STEP_LIMIT = 10) |
hit_step_cap = true 是个信号:模型卡住了 / 步数不够,应被关注。
每个 agent 工具完成时触发。success 由各 tool 自身返回决定;失败由 withTracking wrapper 统一捕获并带 error_type 分类。
| 属性 | 类型 | 说明 |
|---|
thread_id | string | 对话线程 ID |
task_id | string? | agent run id(关联同一次 run 的 chat_*) |
tool_name | string | 工具名称 |
kira_model | lite|nova|ultra | 套餐 tier |
model | string? | provider 模型 id(工具实际用的模型,可选) |
provider | string? | 厂商(可选) |
success | boolean | 是否成功 |
duration_ms | number | 耗时 (ms) |
credits_consumed | number? | 消耗 credits |
以上即 trackToolUsage() 实际 posthog.capture 的全部属性(源 kira-agent/src/analytics/index.ts)。
失败工具不会把 error_type / error_message 发进 PostHog —— tool_usage 事件只带 success: false。错误分类(error_type)由 withTracking wrapper 记到 Dash0 的 ai.tool.duration{error_type} metric + ERROR 日志,不进埋点事件。tool_usage 也没有 ...extra 透传字段。
sub_call(utility LLM 子调用)
agent 工具内部触发的 utility LLM 调用完成后发,记录 token 用量(不计算金额)。
Utility 模型:gemini-3.1-flash-lite,直连 Google Vertex(BYOK,location=global),provider: "vertex"。
| 属性 | 类型 | 说明 |
|---|
thread_id | string | 对话线程 ID |
tool_name | string | 触发子调用的工具名 |
model | string | utility provider 模型 id(gemini-3.1-flash-lite) |
provider | string? | 厂商(utility 跑在 vertex) |
input_tokens | number | 输入 token |
output_tokens | number | 输出 token |
total_tokens | number | input + output |
duration_ms | number | 耗时 (ms) |
kira-agent 版 sub_call 比 kira-be 版多一个 provider 字段。两个服务各发各的,事件名相同。
一次 agent run 的事件链
task_id 把这一整条链串起来;同一 thread_id 下可有多条(多次 run)。