SDK

概览

iagenify 在一个软件包中提供两部分:平台客户端和智能体引擎。执行循环在你的进程中运行,服务器负责模型调用、存储和其他服务。

iagenify 0.5.4Apache-2.0Node ≥ 18 · 浏览器 · Workers

这是什么

大多数 AI SDK 只是 HTTP API 的封装:你发送提示词,获得回答,再自行实现任务编排。本 SDK 已内置编排能力。api.agents.create({ runtime: "local" }) 会在你的进程中运行真正的智能体循环:规划、读取文件、搜索网页、运行命令、生成媒体,并在执行无法撤销的操作前征求许可。

这种设计会直接影响运行方式。工具在代码所在的环境中执行,因此智能体读取本机磁盘,无需上传磁盘内容。权限由你的回调函数决定,而不是由远端策略决定。服务器承担的模型调用,也正是必须由服务器执行的部分。

用一个示例了解整体结构

import { IaGenify } from "iagenify";

const api = new IaGenify({ apiKey: process.env.IAGENIFY_API_KEY });

// 1. A model session — stateful, remembers, structured output on demand
const assistant = await api.models.create({
  model: "gemini-3.5-flash",
  schema: { type: "object", properties: { risks: { type: "array", items: { type: "string" } } } },
});
const { outputs, usage } = await assistant.generate({
  inputs: [{ type: "text", content: "Three risks of shipping on a Friday." }],
});

// 2. An agent — the same account, working on this machine
const pc = await api.storage.get();
const agent = api.agents.create({
  runtime: "local",
  machine: pc,
  model: "gemini-3.5-flash",
  mode: "ask",
  budget: 200,
  onPermission: async ({ tool, category }) => (category === "send" ? "deny" : "once"),
});
await agent.run({ message: "Audit Notes/ and write Notes/audit.md.", onEvent: console.log });

// 3. The services the agent can also reach directly
await api.storage.create({ service: "object", label: "Assets" });
await api.hosts.create({ kind: "site", label: "Landing", slug: "landing" });
await api.domains.add("example.com");

await assistant.destroy();
import os
from iagenify import IaGenify

with IaGenify(api_key=os.environ["IAGENIFY_API_KEY"]) as api:
    assistant = api.models.create(
        model="gemini-3.5-flash",
        schema={"type": "object", "properties": {
            "risks": {"type": "array", "items": {"type": "string"}},
        }},
    )
    answer = assistant.generate(inputs=[
        {"type": "text", "content": "Three risks of shipping on a Friday."},
    ])

    machine = api.storage.get()
    agent = api.agents.create(
        runtime="local",
        machine=machine,
        model="gemini-3.5-flash",
        mode="ask",
        budget=200,
        on_permission=lambda request: "deny" if request["category"] == "send" else "once",
    )
    run = agent.run(message="Audit Notes/ and write Notes/audit.md.", on_event=print)

    api.storage.create(service="object", label="Assets")
    api.hosts.create(runtime="static", framework="html", label="Landing", slug="landing")
    api.domains.add("example.com")
    print(answer["outputs"], run["text"])

资源

所有资源都通过同一个客户端访问。每一行对应本参考文档的一个分支。

资源说明
api.models模型会话、结构化输出,以及原生支持工具调用的无状态调用。
api.agents本地智能体引擎,以及账户中的技能和子智能体。
api.toolssearch、fetch、screenshot、convert 可直接调用,无需智能体。
api.mcp已连接的 MCP 服务器。SDK 作为客户端,可使用任何符合该协议的服务器。
api.storage计算机、手机、IaGenify Cloud,以及已连接的 MongoDB / D1 / R2 / S3。
api.cloudIaGenify Cloud 存储的已用空间和附加服务。
api.files服务器端文件,以及同时写入磁盘的功能。
api.memory智能体在不同会话之间保留的简短笔记。
api.workflows持久化执行图:23 种步骤、4 种触发器、分支、人工审批和重试。
api.domainsAttached domains and their DNS, plus the current extension list.
api.computeIsolated cloud commands and persistent terminals.
api.mailMailboxes, messages, aliases and contacts on your own domains.
api.hostsPut a site, an app or a function online.
api.keysList and revoke API keys. Create keys in account settings.
api.authSessions and profile.

运行环境

一个软件包支持三种运行环境,并自动检测环境,无需手动配置。不同之处在于宿主能力:Node 进程可访问磁盘和 shell,浏览器两者都没有;Worker 也没有这两项能力,并且没有持久存储。

Node浏览器Workers
会话缓存~/.iagenify/sessionlocalStorage内存
智能体工作区~/.iagenify/files提供 files 接口提供 files 接口
Shell 与终端支持提供 shell 接口提供 shell 接口

调用费用

调用会消耗额度。每个结果都包含独立的 usage,由提供商在调用后测量,而不是在你的进程中估算。价格来自服务器,因此代码使用的价格不会偏离实际计费价格。

const prices = await api.catalogue();
// [{ model, service, provider, unit, credits, creditsInput, creditsOutput,
//    contextWindow, maxOutput, cachedInputRate, resolution, audio }]

const { credits } = await api.getUser();

try {
  await assistant.generate({ inputs });
} catch (err) {
  if (err instanceof NotEnoughCredits) {
    console.log(err.required, err.available);   // 402
  }
}
from iagenify import IaGenifyError, NotEnoughCredits

prices = api.catalogue()
user = api.get_user()

try:
    assistant.generate(inputs=inputs)
except NotEnoughCredits as error:
    print(error.required, error.available)  # insufficient-credit response
except IaGenifyError as error:
    print(error.status, error.code, error.message)

稳定性

该包的版本是 0.5.4,即尚未到 1.0。这里记录的结构在每次发布前都由自动化测试覆盖,任何不兼容的变更都会连同替代方案列入更新日志。请把未记录的字段视为内部字段:它可能会变化。