에이전트 분석에서 로컬 및 기기 내 모델 추적

Ollama, LM Studio, llama.cpp 또는 localhost의 추론 서버와 같이 로컬 또는 기기 내 모델에서 실행되는 에이전트는 AI SDK의 수동 추적 방법을 통해 에이전트 분석에 도달합니다. AI SDK에는 로컬 모델을 위한 공급자 래퍼가 없으므로 각 사용자 메시지, 도구 호출 및 모델 응답을 직접 추적합니다. 그러면 세션, 내장 신호 및 평가기는 호스팅된 모델과 동일한 방식으로 작동합니다.

AI 코딩 에이전트로 설정(권장)

이 프롬프트를 Cursor, Claude Code, Windsurf, GitHub Copilot 또는 Codex와 같은 AI 코딩 에이전트에 붙여넣으십시오. 에이전트는 AI SDK를 설치하고, 번들로 제공되는 지침을 읽고, 모든 모델 호출을 찾아 계측합니다.

text
Instrument this app with Amplitude Agent Analytics using the Node SDK. Our agent runs on a local model, so track each user message, tool call, and model response with the manual tracking methods, and pass a cost of 0 on each response.
Fetch and follow https://raw.githubusercontent.com/amplitude/Amplitude-AI-Node/main/amplitude-ai.md
Then install the SDK as that guide says:
npm install @amplitude/ai @amplitude/analytics-node

제안되는 변경 사항을 검토한 다음 Verify의 단계에 따라 확인합니다.

이것이 여러분에게 의미하는 바

  • 호출 방법: 에이전트 세션 내에서 trackUserMessage, trackToolCall, trackAiMessage(Node) 또는 track_user_message, track_tool_call, track_ai_message(Python)을(를) 사용하세요.
  • Cost: 로컬 모델에는 가격이 없으므로 모든 응답에 0의 비용을 전달하십시오. 그러면 응답은 누락된 값 대신 0 비용을 기록합니다.
  • Tokens: 런타임이 입력 및 출력 토큰 카운트를 보고하는 경우 전달합니다. 이는 선택 사항입니다.
  • 실험: 로컬 모델을 호스팅된 모델과 비교할 때 할당을 세션에 experiments로 전달하여 차트가 [Agent] Experiment Variant를 기준으로 속성화할 수 있도록 하십시오. 실험 변형 기록을 참조하십시오.

로컬 모델 추적

typescript
await agent.session({ userId, sessionId }).run(async (s) => {
  s.trackUserMessage(userInput);
  const start = Date.now();
  const response = await localModel.complete(prompt);
  const latencyMs = Date.now() - start;
  s.trackAiMessage(response.text, "llama-3.2-3b", "local", latencyMs, {
    inputTokens: response.usage?.inputTokens,
    outputTokens: response.usage?.outputTokens,
    totalCostUsd: 0,
  });
});

trackToolCall(Node) 또는 track_tool_call(Python)을(를) 사용하여 동일한 방식으로 도구 호출을 추적하십시오. 전체 메소드 서명은 AI SDK 레퍼런스를 참조하십시오.

확인

npx -y -p @amplitude/ai amplitude-ai doctor (Node) 또는 amplitude-ai-doctor (Python)을 실행하십시오. local-model 프로젝트에서 doctor는 지원되는 공급자 패키지를 찾을 수 없기 때문에 provider_dependency보고합니다. 로컬 모델에 대해 해당 결과를 예상하고 무시합니다. 다른 모든 검사가 여전히 적용됩니다.

개인정보 보호

로컬 추론은 머신에 프롬프트를 유지하지만, AI SDK는 여전히 메시지 텍스트를 Amplitude로 전송하며, 여기에는 기본적으로 PII가 편집됩니다.

이 내용이 도움이 되었나요?

For AI agents: a documentation index is available at /docs/llms.txt. Append .md to any page URL for markdown, or send Accept: text/markdown.

이 페이지에서