mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-17 13:55:50 +00:00
feat: 添加对 langfuse 监控的支持 (#242)
* docs: 更新类型检查的 CLAUDE.md * feat: 添加模型 1M 上下文切换 * chore: remove prefetchOfficialMcpUrls call on startup * docs: 添加 git commit 规范 * feat: 第一次接入 langfuse * fix: 修复 generation 的计时的错误 * feat: 添加多 agent 的监控 * feat: 添加 /poor 省流模式,toggle 关闭 extract_memories 和 prompt_suggestion Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: 修复 lock 文件 * chore: 更新类型依赖 --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -57,6 +57,12 @@ import { clearSessionHooks } from '../../utils/hooks/sessionHooks.js'
|
||||
import { executeSubagentStartHooks } from '../../utils/hooks.js'
|
||||
import { createUserMessage } from '../../utils/messages.js'
|
||||
import { getAgentModel } from '../../utils/model/agent.js'
|
||||
import { getAPIProvider } from '../../utils/model/providers.js'
|
||||
import {
|
||||
createSubagentTrace,
|
||||
endTrace,
|
||||
isLangfuseEnabled,
|
||||
} from '../../services/langfuse/index.js'
|
||||
import type { ModelAlias } from '../../utils/model/aliases.js'
|
||||
import {
|
||||
clearAgentTranscriptSubdir,
|
||||
@@ -744,6 +750,25 @@ export async function* runAgent({
|
||||
// Track the last recorded message UUID for parent chain continuity
|
||||
let lastRecordedUuid: UUID | null = initialMessages.at(-1)?.uuid ?? null
|
||||
|
||||
// Create Langfuse sub-agent trace (no-op if not configured).
|
||||
// Sub-agent trace shares the same sessionId as the parent, so Langfuse
|
||||
// groups them under the same Session view.
|
||||
const subTrace = isLangfuseEnabled()
|
||||
? createSubagentTrace({
|
||||
sessionId: getSessionId(),
|
||||
agentType: agentDefinition.agentType,
|
||||
agentId,
|
||||
model: resolvedAgentModel,
|
||||
provider: getAPIProvider(),
|
||||
input: initialMessages,
|
||||
})
|
||||
: null
|
||||
|
||||
// Attach sub-agent trace to toolUseContext so query() reuses it
|
||||
if (subTrace) {
|
||||
agentToolUseContext.langfuseTrace = subTrace
|
||||
}
|
||||
|
||||
try {
|
||||
for await (const message of query({
|
||||
messages: initialMessages,
|
||||
@@ -814,6 +839,8 @@ export async function* runAgent({
|
||||
agentDefinition.callback()
|
||||
}
|
||||
} finally {
|
||||
// End Langfuse sub-agent trace (no-op if not configured)
|
||||
endTrace(subTrace)
|
||||
// Clean up agent-specific MCP servers (runs on normal completion, abort, or error)
|
||||
await mcpCleanup()
|
||||
// Clean up agent's session hooks
|
||||
|
||||
Reference in New Issue
Block a user