跳转到正文
文档导航: 决策模型 / 编程智能体设置

编程智能体设置

RightNow AI决策模型编程智能体设置 更新于

本页内容

先安装 SDK,然后为编程智能体提供技能和带有 API 密钥的服务器环境。

安装 SDK

从环境变量 RIGHTNOW_API_KEY 读取 API 密钥。把这些调用留在你的服务器上。

使用 API keys 页面上的密钥时,SDK 只调用 POST /v1/decisions:它的模型列表、决策查询和流需要以 rnsk_ 开头的密钥,并且它会在发送请求之前拒绝 attachments。SDK 没有调用开放模型的方法:请用同一个密钥通过 HTTP 调用它们。

Node 22 或更高版本,ES 模块,仅限服务器端。Python 3.10 或更高版本,仅限服务器端。

TypeScript 软件包 README (opens in a new tab) 和 Python 软件包 README (opens in a new tab)。

install.sh
npm install @rightnowai/rightnow@0.5.1

从 0.5.0 起,软件包为 @rightnowai/rightnow 和 rightnow-sdk;旧的软件包名称仍然可用。

工具选择:RightNow 决策模型从你的工具中选出下一步要调用的工具,或者一个都不选,并为每个工具给出概率。它不编写参数或消息,也不运行工具。

文本、PDF 和视频允许 9 个工具和“不选”,必须使用工具时允许 10 个;图像或音频允许 25 个工具和“不选”,必须使用工具时允许 26 个。

使用 toolQuestions / tool_questions 和 selectTool / select_tool。见工具选择 (opens in a new tab)。

首次调用

发送一个状态和一个命名的问题,然后读取答案。

decide.ts
import { RightNowClient } from '@rightnowai/rightnow';

const client = new RightNowClient({
  apiKey: process.env.RIGHTNOW_API_KEY,
  baseURL: "https://api.rightnowai.co/v1",
});
const reply = await client.decide({
  "model": "rightnow-decision",
  "state": "The blender I ordered arrived with a cracked jar.",
  "questions": {
    "damaged": {
      "type": "boolean",
      "instructions": "Did the item arrive damaged?"
    }
  }
});
console.log(JSON.stringify(reply, null, 2));

// Set RIGHTNOW_API_KEY to your API key before running this example.
// Run this example on your server.
// SDK defaults: The default is 5 retries, also the maximum, with 150 seconds
// per attempt and a 60-second total retry budget. A single wait longer than 60
// seconds raises the last error.
// Use Retry-After-Ms, or Retry-After when milliseconds are absent. The wait is
// never shorter than a random backoff floor: a random fraction of 0.5 seconds
// doubled for each attempt, capped at 8 seconds.

32 KB 或以上的请求体,如果 gzip 压缩能让它至少缩小百分之 10,就会以 gzip 压缩发送;传入 compressRequests: false / compress_requests=False 可关闭此功能。

请求成功时,读取 answers.damaged。

SDK 重试

规则行为
上限默认重试 5 次,这也是上限;每次尝试 150 秒,重试总预算为 60 秒。单次等待超过 60 秒时,会抛出最后一个错误。
重试标志已标记表示 error.retryable 为 true,或 x-should-retry 响应头为 true。任一标志明确为 false 时,不会重试。
429capacity_exhausted、rate_limit_exceeded、concurrency_limit_exceeded 或 workspace_limit_exceeded。
5xx504 和维护除外,包括 service_unavailable 和 model_unavailable。
409idempotency_conflict。
传输带键的 POST 或 GET 在收到任何响应字节之前,也可以重试符合条件的连接失败或超时,即使请求已经发出。收到响应字节之后的失败从不重试。身份验证和权限类型的错误从不重试。
等待使用 Retry-After-Ms;没有毫秒值时使用 Retry-After。等待时间从不短于一个随机退避下限:0.5 秒的一个随机比例,每次尝试翻倍,上限为 8 秒。
冷启动冷池会返回已标记的 503 model_unavailable,并在 Retry-After 中给出等待时间。SDK 会用同一个幂等密钥重试同一个请求体。重试标志明确为 false 时,会停止重试。
智能体设置
Text
智能体设置的图示。

把文档和任务交给智能体。把密钥留在你的服务器上。

提示词

把这段说明粘贴到你的编程智能体中。

agent-prompt.md
Text
Add the RightNow decision model API to this project. Follow the skill at https://www.rightnowai.co/docs/decision-model/SKILL.md. Read the key from the RIGHTNOW_API_KEY environment variable, and never write the key into a file, a commit or a log.

技能

在添加集成之前,阅读 SKILL.md或下载它。

密钥

在应用运行的地方设置 RIGHTNOW_API_KEY。绝不要把密钥粘贴到提示词、源代码、提交或日志中。

下一步:对照快速入门检查生成的集成。