Skip to main content
Sonzai Docs

评估与模拟

评估智能体质量、运行多轮模拟、基准测试人格一致性。

评估响应

根据模板评分标准对智能体的响应进行评分。

const result = await client.agents.evaluate("agent-id", {
  templateId: "template-id",
  messages: [
    { role: "user", content: "I'm feeling really stressed about work" },
    { role: "assistant", content: "I hear you. Work stress can be overwhelming..." },
  ],
});

console.log(result.score);       // 0-100
console.log(result.feedback);    // detailed feedback
console.log(result.categories);  // per-category scores

评估模板

创建带加权类别的评分标准。

// Create a template
const template = await client.evalTemplates.create({
  name: "Empathy & Support",
  description: "Evaluates emotional intelligence and supportive responses",
  scoringRubric: "Score based on empathy, active listening, and actionable advice",
  categories: ["empathy", "active_listening", "actionable_advice"],
  judgeModel: "claude-sonnet-4-6",
  temperature: 0.3,
});

// List templates
const templates = await client.evalTemplates.list();

运行模拟

运行多轮模拟对话以大规模测试智能体行为。

for await (const event of client.agents.simulate("agent-id", {
  maxSessions: 3,
  maxTurnsPerSession: 10,
  simulatedDurationHours: 24,
  enableProactive: true,
  enableConsolidation: true,
  userPersonas: [
    {
      name: "Alex",
      background: "College student struggling with math",
      personalityTraits: ["anxious", "eager to learn"],
      communicationStyle: "casual, uses slang",
    },
  ],
})) {
  console.log(`[${event.type}] ${event.message}`);
  if (event.totalCostUsd) {
    console.log(`Cost so far: $${event.totalCostUsd}`);
  }
}

模拟 + 评估(runEval)

一步结合模拟和评估。

for await (const event of client.agents.runEval("agent-id", {
  templateId: "template-id",
  maxSessions: 5,
  maxTurnsPerSession: 8,
})) {
  if (event.type === "evaluation") {
    console.log("Score:", event.score);
  }
}

评估运行

跟踪和管理模拟运行。

// List runs
const runs = await client.evalRuns.list({ agentId: "agent-id" });

// Get a specific run
const run = await client.evalRuns.get("run-id");

// Reconnect to a streaming run
for await (const event of client.evalRuns.streamEvents("run-id")) {
  console.log(event.type, event.message);
}

异步模拟

模拟支持通过 simulateAsync() 进行异步模式,立即返回 RunRef,允许您稍后轮询或重新连接。