Skip to main content

智能体生成

通过自然语言描述创建智能体。平台自动生成人格档案、传记和种子记忆。

生成并创建智能体

一步到位:用自然语言描述智能体,获得一个完整配置好人格、传记和种子记忆的智能体。

import { Sonzai } from "@sonzai-labs/agents";

const client = new Sonzai({ apiKey: "sk-..." });

const agent = await client.agents.generation.generateAndCreate({
name: "Luna",
description: "A cheerful and curious AI assistant who loves helping developers debug code.",
language: "en",
});

幂等更新

如果提供了 agentId 且智能体已存在,generateAndCreate 会更新现有智能体而不是创建副本。

生成角色档案

生成完整的人格档案而不创建智能体。适合在确认前预览。

const profile = await client.agents.generation.generateCharacter({
name: "Atlas",
description: "A stoic, wise mentor who speaks in metaphors and values patience above all.",
fields: ["big5", "dimensions", "preferences", "behaviors"],
});

生成传记

为现有智能体生成或重新生成传记。

const bio = await client.agents.generation.generateBio("agent-id", {
description: "A friendly barista who remembers every customer's order",
style: "warm and conversational",
});
console.log(bio.bio);

生成种子记忆

根据人格生成并可选地存储背景故事记忆。

const memories = await client.agents.generation.generateSeedMemories("agent-id", {
agentName: "Luna",
trueInterests: ["astronomy", "poetry", "hiking"],
trueDislikes: ["loud noises", "dishonesty"],
generateOriginStory: true,
generatePersonalizedMemories: true,
storeMemories: true,
});
console.log(memories.memories.length);

生成图像

使用 AI 从文本提示生成图像。

const image = await client.agents.generation.generateImage("agent-id", {
prompt: "A serene mountain landscape at sunset",
});
console.log(image.url);

实际应用

生成对伴侣(大规模角色创建)和 AI 员工(基于角色的智能体模板) 最有价值。对于企业,生成通常是一次性的配置步骤。

generateAndCreate 作为你的入职流程。 让用户在文本框中 描述他们的伴侣。调用 API。向他们展示生成的角色。如果他们不满意, 重新生成。这是目前最好的首次使用体验。

const agent = await client.agents.generation.generateAndCreate({
  name: userInput.name,
  description: userInput.description,
  language: "en",
});

generateCharacter 预览后再确认。 如果你希望用户在 保存之前审批人格档案,使用 generateCharacter 预览, 然后只在确认时 create

生成种子记忆以获得可信的背景故事。 一个在用户到来之前 就"记得"往事的伴侣感觉更真实。

On this page