# turn · الأدوات

Canonical URL: https://developers.iagenify.com/ar/sdk/ref/models/turn/tools/
Language: ar

`api.models.turn({ tools })`

فَهُمْ يُقَرِّرُونَ ، يُنْفِذُونَ ، وَلَا يَعْرِفُونَ أَيْضًا عَلَى حَيَاتِنَا .

Status: اختياري · sent on every turn · two schema forms

فالإعلان هو اسم ووصف ومخطط معياري، والنموذج لا يعمل أي شيء: فهو يجيب بقرار، ويشغله هو لك - وهو أيضا ما يجعل من الآمن أن نفضح أشياء من الخطر أن ننقلها إلى أي شخص آخر.

## إعلان واحد {#shape}

```javascript
{
  name: "weather",
  description: "Current weather for a city.",
  parameters: {
    city: { type: "string", description: "City name", required: true },
    unit: { type: "string", enum: ["c", "f"] },
  },
}
```

## طريقتان لكتابة الـ {#schemas}

الشكل القصير هو خريطة لحقول، كل منها مع `required` الشكل الكامل هو كائن JSON وكلاهما مقبول؛ والقصير موجود لأن كتابة مخطط بثلاثة بارامترات باليد لا يتناسب مع ذلك.

```javascript
// Short
parameters: {
  city: { type: "string", required: true },
  unit: { type: "string", enum: ["c", "f"] },
}

// Full — reach for this when it gets complicated
parameters: {
  type: "object",
  properties: {
    city: { type: "string" },
    unit: { type: "string", enum: ["c", "f"] },
  },
  required: ["city"],
}
```

| الأنواع التي لم يُبت فيها |  |
| --- | --- |
| عدد عدد عدد عدد عدد صحيح polean | -السلسلات |
| (م) | مع العناصر و الخصائص |

## كل إعلان يدفع ثمنه كل دور {#cost}

يتم إرسال الأدوات مع كل نداء، لذلك فهي جزء من المدخلات التي تمّت تأليفها - أداة النموذج لا يختارها أبداً

> **أرسل ما قد تدعوه هذه المنعطفة، ليس كل ما تدعمه**
>
> تضييق القائمة بما تدور حوله المحادثة هو أرخص أفضل تكبير متاح في حلقة اتصال بأداة، ويجعل النموذج يختار أفضل.

```javascript
const ALL = { weather: weatherTool, invoices: invoiceTool, calendar: calendarTool };

// Pick per turn rather than declaring the catalogue
const tools = Object.entries(ALL)
  .filter(([name]) => relevant(name, conversation))
  .map(([, tool]) => tool);
```

## الوصف هو التعليمات {#descriptions}

هو الشيء الوحيد الذي يخبر النموذج متى يصل لهذا بدلاً من الإجابة مباشرة. قل ما يفعله، ما يحتاجه، ومتى *غير* لاستخدامه.

| ن ن | مُحسن |
| --- | --- |
| } يحصل على بيانات } | ‹ الطقس الحالي للمدينة - يستخدم اليوم فقط - لا يوجد أي تنبؤات. □ □ |
| } البحث عن | "يبحث في سجل منتجاتنا بالاسم وليس في سجلات العملاء. |
| ’ يرسل رسالة بريد إلكتروني ’ | □ يرسل رسالة إلكترونية، فقط بعد أن يؤكد المستخدم المتلقي والنص. □ |

## جاري تحميل التوقيع {#signature}

أداة نداء يمكن أن يأتي مرة أخرى `signature`اعيدها بدون تغيير في المنعطف التالي أو يُرفض الدور. احفظ الرسالة المساعدة بأكملها وادفعها للخلف كما تتعامل مع هذا بدون أن تفكر فيها.

```javascript
// Right: the message goes back whole
messages.push(turn.message);

// Wrong: rebuilt, and the signature is gone
messages.push({ role: "assistant", content: turn.message.content,
                toolCalls: turn.message.toolCalls.map(({ id, name, args }) => ({ id, name, args })) });
```

## عدة نداءات في كل مرة {#parallel}

منعطف يمكن أن يطلب أكثر من أداة واحدة دفعة واحدة. `tool` . . . .

```javascript
const results = await Promise.all(
  turn.message.toolCalls.map((call) => run(call.name, call.args).catch((e) => `Error: ${e.message}`)),
);

turn.message.toolCalls.forEach((call, i) => {
  messages.push({ role: "tool", toolCallId: call.id, name: call.name, content: String(results[i]) });
});
```

> **حدِّ لنفسك ما قد لا يُحَمَّل**
>
> النموذج يختار، لا يصرح. أي شيء يرسل أو ينشر أو يحذف أو ينفق يجب أن يمرر شيكاً من تلقاء نفسه قبل تشغيله -- فئات أذون المحرك هي طريقة واحدة للتفكير في أي منها.

## الأخطاء {#errors}

| الرمز | الحالة | متى |
| --- | --- | --- |
| invalid_tools | 400 | كانت الأدوات موجودة ولكن لم تكن مصفوفة. |
| turn_failed | 502 | ورفض مقدم الإعلان الإعلانات - وعادة ما يكون ذلك مخططا لا يمكن أن يقبله. |

حافظ على chemas programmarmary chemas Sil. *عن كل* دوران، ليس فقط ذلك الواحد أداة.

- [turn · الرسائل](/ar/sdk/ref/models/turn/messages): حيث تذهب نتيجة أداة، والحلقة حولها.
- [api.mcp](/ar/sdk/ref/mcp): أدوات من خادم مُوصل، معلنة بنفس الطريقة.

```python
{
    "name": "weather",
    "description": "Current weather for a city.",
    "parameters": {
        "city": {"type": "string", "description": "City name", "required": True},
        "unit": {"type": "string", "enum": ["c", "f"]},
    },
}
```

```python
# Short
parameters = {
    "city": {"type": "string", "required": True},
    "unit": {"type": "string", "enum": ["c", "f"]},
}

# Full — reach for this when it gets complicated
parameters = {
    "type": "object",
    "properties": {
        "city": {"type": "string"},
        "unit": {"type": "string", "enum": ["c", "f"]},
    },
    "required": ["city"],
}
```

```python
ALL = {"weather": weather_tool, "invoices": invoice_tool, "calendar": calendar_tool}

# Pick per turn rather than declaring the catalogue
tools = [tool for name, tool in ALL.items() if relevant(name, conversation)]
```

```python
# Right: the message goes back whole
messages.append(turn["message"])

# Wrong: rebuilt, and the signature is gone
messages.append({"role": "assistant", "content": turn["message"]["content"],
                 "toolCalls": [{"id": c["id"], "name": c["name"], "args": c["args"]}
                               for c in turn["message"]["toolCalls"]]})
```

```python
from concurrent.futures import ThreadPoolExecutor

def safe_run(call):
    try:
        return run(call["name"], call["args"])
    except Exception as error:
        return f"Error: {error}"

calls = turn["message"]["toolCalls"]
with ThreadPoolExecutor() as pool:
    results = list(pool.map(safe_run, calls))

for call, result in zip(calls, results):
    messages.append({"role": "tool", "toolCallId": call["id"], "name": call["name"], "content": str(result)})
```
