البدء

البدء السريع

أربع خطوات: ثبّت الحزمة، واحصل على مفتاح، وولّد محتوى، ثم دع وكيلًا ينفّذ عملًا فعليًا على جهازك. يستغرق ذلك نحو عشر دقائق ويستهلك بضعة أرصدة.

node ≥ 18المتصفحCloudflare Workers
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

1 · تثبيت الحزمة

npm install iagenify
# yarn add iagenify
python -m pip install iagenify

2 · إعداد مفتاح API

يُستبدل المفتاح بجلسة عند أول استدعاء، ولا يُرسل مجددًا بعد ذلك. احتفظ به على جانب الخادم.

import { IaGenify } from "iagenify";

const api = new IaGenify({
  apiKey: process.env.IAGENIFY_API_KEY,         // ia_...
  baseUrl: "https://api.iagenify.com",          // or set IAGENIFY_API_URL instead
});

console.log(api.env, api.framework);            // "node" "node"
console.log(await api.getUser());               // { id, email, credits, pack }
import os
from iagenify import IaGenify

api = IaGenify(
    api_key=os.environ["IAGENIFY_API_KEY"],
    base_url="https://api.iagenify.com",
)
print(api.env, api.framework)  # "python" "python"
print(api.get_user())
api.close()

3 · توليد محتوى

const assistant = await api.models.create({
  model: "gemini-3.5-flash",
  settings: { role: "Technical writer", instructions: "Answer in one paragraph." },
  memory: true,
});

const result = await assistant.generate({
  inputs: [{ type: "text", content: "What is an execution trail?" }],
});

console.log(result.outputs[0].content);
console.log(result.usage);        // { credits: 4, inputTokens: 38, outputTokens: 96 }

await assistant.destroy();
assistant = api.models.create(
    model="gemini-3.5-flash",
    settings={"role": "Technical writer", "instructions": "Answer in one paragraph."},
    memory=True,
)

result = assistant.generate(inputs=[
    {"type": "text", "content": "What is an execution trail?"},
])
print(result["outputs"][0]["content"])
print(result["usage"])
assistant.destroy()
احذف الجلسة التي أنشأتها في السكربت بعد الانتهاء

يؤدي الخيار memory: true إلى حفظ المحادثة. وإذا تركت سكربتات الاختبار جلساتها دون حذف، فسيمتلئ الحساب بمحادثات لا يفتحها أحد.

مخرجات منظّمة بدلًا من النص الحر

مرّر مخطط JSON Schema لتحصل على إجابة تطابق بنيته. ستكون outputs[0].content عندئذٍ سلسلة نصية بتنسيق JSON يمكنك تحليلها.

const extractor = await api.models.create({
  model: "gemini-3.5-flash",
  memory: false,
  schema: {
    type: "object",
    properties: {
      company: { type: "string" },
      amount:  { type: "number" },
      dueDate: { type: "string" },
    },
    required: ["company", "amount"],
  },
});

const { outputs } = await extractor.generate({
  inputs: [{ type: "text", content: invoiceText }],
});
const invoice = JSON.parse(outputs[0].content);
import json

extractor = api.models.create(
    model="gemini-3.5-flash",
    memory=False,
    schema={
        "type": "object",
        "properties": {
            "company": {"type": "string"},
            "amount": {"type": "number"},
            "dueDate": {"type": "string"},
        },
        "required": ["company", "amount"],
    },
)
response = extractor.generate(inputs=[{"type": "text", "content": invoice_text}])
invoice = json.loads(response["outputs"][0]["content"])

قراءة ملف أو صورة أو تسجيل

لكل مُدخل نوع محدد. تُقبل سبعة أنواع: text وimage وfile وvideo وaudio وspeech وpassages.

import { readFileSync } from "node:fs";

await assistant.generate({
  inputs: [
    { type: "text",  content: "What does this contract commit us to?" },
    { type: "image", url: "https://example.com/page-1.png" },
    { type: "audio", content: readFileSync("./meeting.m4a").toString("base64"), mime: "audio/mp4" },
  ],
});
import base64
from pathlib import Path

result = assistant.generate(inputs=[
    {"type": "text", "content": "What does this contract commit us to?"},
    {"type": "image", "url": "https://example.com/page-1.png"},
    {"type": "audio", "content": base64.b64encode(Path("meeting.m4a").read_bytes()).decode(), "mime": "audio/mp4"},
])

4 · تشغيل الوكيل لتنفيذ العمل

تجيب جلسة النموذج عن الأسئلة. أما الوكيل فينفّذ العمل: يقرأ ويبحث ويحرّر وينفّذ الأوامر، ويتوقف لطلب موافقتك قبل أي إجراء لا يمكن التراجع عنه.

const pc = await api.storage.get();          // this computer, as a storage

const agent = api.agents.create({
  runtime: "local",
  machine: pc,
  model: "gemini-3.5-flash",
  mode: "ask",                               // ask · auto · plan · full
  budget: 200,                               // credits; the run stops rather than overrun
  onPermission: async ({ tool, args, category }) => {
    console.log("asking for", tool, category);
    return "once";                           // "once" | "always" | "deny"
  },
});

const run = await agent.run({
  message: "Summarise every .md file in Notes/ into Notes/summary.md.",
  onEvent: (e) => {
    if (e.type === "text")      process.stdout.write(e.delta ?? "");
    if (e.type === "tool_start") console.log("\n→", e.tool, e.summary ?? "");
    if (e.type === "done")       console.log("\n", agent.usage);
  },
});

console.log(run.text);
console.log(agent.usage);        // { credits, turns, toolCalls }
console.log(agent.context);      // { tokens, limit, window, cachedTokens, parts }
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: "once",
)

def on_event(event):
    if event["type"] == "text":
        print(event.get("text", ""), end="", flush=True)
    elif event["type"] == "tool_start":
        print("\n", event.get("tool"), event.get("summary", ""))

run = agent.run(
    message="Summarize every .md file in Notes/ into Notes/summary.md.",
    on_event=on_event,
)
print(run["text"])
print(run["usage"])

متابعة استدلال الوكيل

تصل اثنا عشر نوعًا من الأحداث عبر onEvent. وتُستخدم الأنواع الخمسة التالية عادةً لبناء واجهة المستخدم.

الحدثالمحتوى
textdelta — الإجابة التي تصل تدريجيًا
tool_startid, tool, args, summary, category
tool_endid, tool, ok, summary, credits, durationMs
permissionالطلب الذي تستجيب له دالة onPermission
doneانتهى التنفيذ؛ وأصبحت قيمة agent.usage نهائية

الخطوات التالية