#ווי אזוי צו בויען אן AI אגענט מיט די OpenAI API?

1 messages · Page 1 of 1 (latest)

green nebula
#

היי

sudden abyssBOT
#

Hi @green nebula. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

מען קען בויען אַן AI־אַגענט מיט דער OpenAI פּלאַטפֿאָרמע אויף אַ פּאָר הויפּט וועגן. איך וועל עס מסדר זײַן קורץ און אין שריט, מיט ביישפּיל־קאָד.


1. ניצן דעם Agents SDK (Python / TypeScript)

די OpenAI Agents SDK גיט אייך אַ לייכטן וועג צו בויען אַגענט־אַפּס מיט אינסטרוקציעס, טולס, האַנדאָפס און גאַרדריילס. [Agents SDK]

אינסטאַלאַציע (Python)

pip install openai-agents
export OPENAI_API_KEY=sk-...

פּשוטער אַגענט (“Hello world”)

from agents import Agent, Runner

agent = Agent(name="Assistant", instructions="You are a helpful assistant")

result = Runner.run_sync(agent, "Write a haiku about recursion in programming.")
print(result.final_output)

[Agents SDK EN]

מער קאָמפּליצירטע אַגענט־אָרקעסטראציע (האַנדאָפס)

from agents import Agent, Runner
import asyncio

spanish_agent = Agent(
    name="Spanish agent",
    instructions="You only speak Spanish.",
)

english_agent = Agent(
    name="English agent",
    instructions="You only speak English",
)

triage_agent = Agent(
    name="Triage agent",
    instructions="Handoff to the appropriate agent based on the language of the request.",
    handoffs=[spanish_agent, english_agent],
)

async def main():
    result = await Runner.run(triage_agent, input="Hola, ¿cómo estás?")
    print(result.final_output)

if __name__ == "__main__":
    asyncio.run(main())

[Quickstart]

די SDK שטיצט אויך:

  • טולס (Python־פונקציעס ווי פונקציע־טולס)
  • גאַרדריילס (אינפּוט/אַוטפּוט־וואַלידאַציע)
  • סעשאַנז (אוטאָמאַטישע קאָנווערסאַציע־היסטאָריע)
    [Agents SDK EN]

#

2. בויען אַגענט מיט דער Node.js SDK (פֿונקציע־קאָלינג)

איר קענט אויך בויען אַן “אַגענט” דורך Chat Completions + פונקציע־טולס. [Node agent example]

ביישפּיל: אַגענט וואָס נוצט לאָקאַציע + וועטער־API

import OpenAI from "openai";

const openai = new OpenAI({
  apiKey: process.env.OPENAI_API_KEY,
  dangerouslyAllowBrowser: true,
});

async function getLocation() {
  const response = await fetch("<https://ipapi.co/json/">);
  return await response.json();
}

async function getCurrentWeather(latitude, longitude) {
  const url = `<https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}&hourly=apparent_temperature`;>
  const response = await fetch(url);
  return await response.json();
}

const tools = [
  {
    type: "function",
    function: {
      name: "getCurrentWeather",
      description: "Get the current weather in a given location",
      parameters: {
        type: "object",
        properties: {
          latitude: { type: "string" },
          longitude: { type: "string" },
        },
        required: ["longitude", "latitude"],
      },
    },
  },
  {
    type: "function",
    function: {
      name: "getLocation",
      description: "Get the user's location based on their IP address",
      parameters: {
        type: "object",
        properties: {},
      },
    },
  },
];

const availableTools = { getCurrentWeather, getLocation };

const messages = [
  {
    role: "system",
    content: "You are a helpful assistant. Only use the functions you have been provided with.",
  },
];

async function agent(userInput) {
  messages.push({ role: "user", content: userInput });

  for (let i = 0; i < 5; i++) {
    const response = await openai.chat.completions.create({
      model: "gpt-4",
      messages,
      tools,
    });
#

const { finish_reason, message } = response.choices[0];

if (finish_reason === "tool_calls" && message.tool_calls) {
  const functionName = message.tool_calls[0].function.name;
  const functionToCall = availableTools[functionName];
  const functionArgs = JSON.parse(message.tool_calls[0].function.arguments);
  const functionArgsArr = Object.values(functionArgs);
  const functionResponse = await functionToCall.apply(null, functionArgsArr);

  messages.push({
    role: "function",
    name: functionName,
    content: `The result of the last function was this: ${JSON.stringify(functionResponse)}`,
  });
} else if (finish_reason === "stop") {
  messages.push(message);
  return message.content;
}

}
return "The maximum number of iterations has been met without a suitable answer.";
}

const response = await agent(
"Please suggest some activities based on my location and the weather."
);
console.log("response:", response);


[[Node agent full](<https://cookbook.openai.com/examples/how_to_build_an_agent_with_the_node_sdk#running-the-final-app>)]

---

## 3. ניצן AgentKit / Agent Builder (וויזועלער קאַנוואַס)

אויב איר ווילט בויען אַגענט־וואָרקפֿלאָוז אָן צו שרײַבן אַ סך קאָד, קענט איר נוצן **Agent Builder** אין דער פּלאַטפֿאָרמע:

- Agent Builder – וויזועלער קאַנוואַס צו צוזאַמענשטעלן מאָדעלן, טולס, לאָגיק, נאָלידזש. [[Agents guide](<https://platform.openai.com/docs/guides/agents#page-top>)]
- ChatKit – צו אַרײַנעמבעדן דעם אַגענט אין אייער פֿראָנטענד. [[Agents guide](<https://platform.openai.com/docs/guides/agents#page-top>)]

---

## 4. Assistants API (מער “classic” אַגענט־סטיל)

איר קענט אויך שאַפֿן אַן Assistant (אַגענט) מיט טולס ווי `code_interpreter` און `file_search`. [[Create assistant](<https://platform.openai.com/docs/api-reference/assistants/createAssistant>)]
#

ביישפּיל: “Math Tutor” Assistant (Python)

from openai import OpenAI
client = OpenAI()

my_assistant = client.beta.assistants.create(
    instructions="You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
    name="Math Tutor",
    tools=[{"type": "code_interpreter"}],
    model="gpt-4o",
)
print(my_assistant)

[Create assistant]


אויב דו זאָגסט מיר וועלכע שפּראַך/סטעק דו נוצסט (Python, Node.js, אאַז"ו), קען איך צושטעלן אַ קלאָרן “סטאַרט־פּראָיעקט”־קאָד פּאַסיק צו דײַן סצענאַר.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@green nebula Kapa.ai is still learning and improving, please let me know how I did by reacting below.

green nebula
#

וועלכע שפּראַך פֿאָרשלאָגט איר: Node.js, Python, צי Go?

#

@sudden abyss ^^

sudden abyssBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

מען קען בויען אַן AI־אַגענט מיט דער OpenAI פּלאַטפֿאָרמע אויף אַ פּאָר הויפּט וועגן. דאָ איז אַ קורצע, פּראַקטישע איבערבליק:


1. Agents SDK – דער רעקאָמענדירטער וועג

די OpenAI Agents SDK (Python אָדער TypeScript) איז געבויט דווקא צו בויען אַגענט־אַפּס מיט אינסטרוקציעס, טולס, האַנדאָפס, גאַרדריילס און סעשאַנז. [Agents SDK; Quickstart agents]

אינסטאַלאַציע (Python)

pip install openai-agents
export OPENAI_API_KEY=sk-...

פּשוטער אַגענט (“Hello world”)

from agents import Agent, Runner

agent = Agent(name="Assistant", instructions="You are a helpful assistant")

result = Runner.run_sync(agent, "Write a haiku about recursion in programming.")
print(result.final_output)

[Agents SDK]

ביישפּיל: טריאַזש־אַגענט מיט האַנדאָפס

from agents import Agent, Runner
import asyncio

spanish_agent = Agent(
    name="Spanish agent",
    instructions="You only speak Spanish.",
)

english_agent = Agent(
    name="English agent",
    instructions="You only speak English",
)

triage_agent = Agent(
    name="Triage agent",
    instructions="Handoff to the appropriate agent based on the language of the request.",
    handoffs=[spanish_agent, english_agent],
)


async def main():
    result = await Runner.run(triage_agent, input="Hola, ¿cómo estás?")
    print(result.final_output)


if __name__ == "__main__":
    asyncio.run(main())

[Quickstart agents]

דעם זעלבן מוסטער עקזיסטירט אויך אין TypeScript: [Quickstart agents]

import { Agent, run } from '@openai/agents';
#

const spanishAgent = new Agent({
name: 'Spanish agent',
instructions: 'You only speak Spanish.',
});

const englishAgent = new Agent({
name: 'English agent',
instructions: 'You only speak English',
});

const triageAgent = new Agent({
name: 'Triage agent',
instructions:
'Handoff to the appropriate agent based on the language of the request.',
handoffs: [spanishAgent, englishAgent],
});

const result = await run(triageAgent, 'Hola, ¿cómo estás?');
console.log(result.finalOutput);


---

## 2. Agent Builder / AgentKit (אָן סך קאָד)

אויף דער וועב־פּלאַטפֿאָרמע קענט איר נוצן:

- **Agent Builder** – אַ וויזועלער קאַנוואַס צו צוזאַמענשטעלן מאָדעלן, טולס, נאָלידזש און לאָגיק אין אַגענט־וואָרקפֿלאָוז.  
- **ChatKit** – צו אַרײַנעמבעדן דעם אַגענט־וואָרקפֿלאָו אין אייער אייגענעם UI.  

[[Agents guide](<https://platform.openai.com/docs/guides/agents#page-top>)]

דאָס איז גוט אויב איר ווילט “קלעקן־און־ציען”־סטיל אָן צו שרײַבן פולן באַקענד.

---

## 3. Assistants API – אַסיסטאַנט ווי אַגענט

מיט דער **Assistants API** קענט איר שאַפֿן אַ “Assistant” מיט אינסטרוקציעס און טולס (`code_interpreter`, `file_search`, פונקציעס), וואָס פֿירט זיך ווי אַן אַגענט. [[Create assistant](<https://platform.openai.com/docs/api-reference/assistants/createAssistant>); [Assistants deep dive](<https://platform.openai.com/docs/assistants/deep-dive#creating-assistants>)]

### ביישפּיל: Math Tutor Assistant (Python)

```python
from openai import OpenAI
client = OpenAI()

my_assistant = client.beta.assistants.create(
    instructions="You are a personal math tutor. When asked a question, write and run Python code to answer the question.",
    name="Math Tutor",
    tools=[{"type": "code_interpreter"}],
    model="gpt-4o",
)
print(my_assistant)

[Create assistant]

#

איר קענט אויך צוגעבן טעקעס און נוצן tool_resources כּדי דער אַסיסטאַנט זאָל קענען אַרבעטן אויף דאַטן (למשל CSV־פֿיילס). [Assistants deep dive]


4. Node.js Chat + פונקציע־טולס (מאַנואַלער אַגענט)

אויב איר ווילט אַ לייכטן “אַגענט” אָן Agents SDK, קענט איר ניצן די Node SDK מיט פונקציע־טולס. דער קאָד־בײַשפּיל אין די קוכבוך ווײַזט אַ אַגענט וואָס רופט APIs (getLocation, getCurrentWeather) לויטן מאָדעל־באַשלוס. [Node agent example]


אויב דו זאָגסט קלאָר:

  • וועלכע שפּראַך (Python / Node.js),
  • און וואָס זאָל דער אַגענט טון (למשל: קאָד־העלפער, דאַטן־אַנאַליז, קאַסטאַמער־סופּאָרט),

קען איך דיר צושטעלן אַ גאַנץ מינימאַלן “סטאַרט־פּראָיעקט”־קאָד פּונקט פֿאַר דײַן קייס.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:

#

@green nebula Kapa.ai is still learning and improving, please let me know how I did by reacting below.

green nebula
#

@sudden abyss ^^

sudden abyssBOT
#

Let me check the knowledge base for you again. One moment! :books:

#

איך בין נישט גאַנץ זיכער וואָס דו מיינסט מיט ^^ אלס פֿראַגע – די צוגעשטעלטע נאָלידזש־קוועלער רעדן בלויז וועגן ווי צו בויען אַגענטן מיט OpenAI (Agents SDK, Node SDK, Agent Builder אאַז"ו), און נישט וועגן דעם סימבאָל זעלבסט.

אויב דיין כוונה איז נאָך אַמאָל צו פֿרעגן: “ווי אַזוי בויט מען אַן AI־אַגענט מיט די OpenAI API?”, דאַן קענסטו זיך אָריענטירן לויט די אָפיציעלע קוועלער:

  • פֿאַר Python / TypeScript אַגענטן ניצט מען די OpenAI Agents SDK (pip install openai-agents), שאַפֿט Agent־אָביעקטן מיט instructions, tools, handoffs, און לויפט זיי מיט Runner.run(...) אָדער run(...) אין JS.[OpenAI Agents SDK; Quickstart agents]
  • אין Node.js קען מען אויך בויען אַ “אַגענט” מיט chat.completions.create און tools (פונקציע־טולס) לויטן קוכבוך־בײַשפּיל.[Node agent example]
  • אויף דער וועב־פּלאַטפֿאָרמע קען מען נוצן Agent Builder / AgentKit צו בויען אַגענט־וואָרקפֿלאָוז וויזועל, און ChatKit צו אַרײַנעמבעדן זיי אין אַ UI.[Agents guide]

ביטע קלער אויס אין טעקסט (למשל: “איך וויל אַ מינימאַלן Python־בײַשפּיל מיט Agents SDK” אָדער “ווײַז מיר Node.js־קאָד”), און איך וועל דיך דאַן געבן גענוי דעם קאָד און שריט לויט די דאָקומענטירטע ביישפּילן.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: