> This is a page from the ElevenLabs documentation. For a complete page index, fetch https://elevenlabs.io/docs/llms.txt. For the full documentation in a single file, fetch https://elevenlabs.io/docs/llms-full.txt.

# क्लाइंट टूल्स

**क्लाइंट टूल्स** आपके असिस्टेंट को क्लाइंट-साइड फ़ंक्शंस चलाने देते हैं। [वेबहुक टूल्स](/docs/hi/eleven-agents/customization/tools/webhook-tools) के विपरीत, क्लाइंट टूल्स असिस्टेंट को ब्राउज़र इवेंट्स ट्रिगर करने, क्लाइंट-साइड फ़ंक्शंस चलाने या UI को नोटिफ़िकेशन भेजने जैसे काम करने देते हैं।

## ओवरव्यू

ऐप्लिकेशन में असिस्टेंट्स को यूज़र के एनवायरनमेंट के साथ सीधे इंटरैक्ट करना पड़ सकता है। क्लाइंट-साइड टूल्स आपके असिस्टेंट को क्लाइंट-साइड ऑपरेशंस करने की सुविधा देते हैं।

यहां कुछ उदाहरण हैं जहां क्लाइंट टूल्स उपयोगी हो सकते हैं:

* **UI इवेंट्स ट्रिगर करना**: असिस्टेंट को अलर्ट, मोडल या नोटिफ़िकेशन जैसे ब्राउज़र इवेंट्स ट्रिगर करने दें।
* **DOM के साथ इंटरैक्ट करना**: असिस्टेंट को डायनामिक कंटेंट अपडेट्स के लिए Document Object Model (DOM) में बदलाव करने या यूज़र्स को जटिल इंटरफ़ेस में गाइड करने दें।

> **Info**
>
> सर्वर-साइड APIs को कॉल करने के लिए, इसके बजाय [वेबहुक टूल्स](/docs/hi/eleven-agents/customization/tools/webhook-tools) इस्तेमाल करें।

## गाइड

### ज़रूरी शर्तें

* एक [ElevenLabs अकाउंट](https://elevenlabs.io)
* कॉन्फ़िगर किया गया ElevenLabs कन्वर्सेशनल एजेंट ([यहां बनाएं](https://elevenlabs.io/app/agents))

#### नया क्लाइंट-साइड टूल बनाएं

आवश्यक स्ट्रिंग पैरामीटर `message` ("कंसोल में लॉग करने वाला संदेश") के साथ `logMessage` नाम का क्लाइंट टूल कॉन्फ़िगर करें।

#### डैशबोर्ड से जोड़ें

अपने एजेंट डैशबोर्ड पर जाएं। **Tools** सेक्शन में, **Add Tool** पर क्लिक करें। सुनिश्चित करें कि **Tool Type** को **Client** पर सेट किया गया है। फिर निम्न कॉन्फ़िगर करें:

| सेटिंग | पैरामीटर                                                                        |
| ------ | ------------------------------------------------------------------------------- |
| नाम    | logMessage                                                                      |
| विवरण  | यूज़र के क्लाइंट पर संदेश लॉग करने के लिए इस क्लाइंट-साइड टूल का इस्तेमाल करें। |

फिर निम्न कॉन्फ़िगरेशन के साथ नया पैरामीटर `message` बनाएं:

| सेटिंग       | पैरामीटर                                                                             |
| ------------ | ------------------------------------------------------------------------------------ |
| डेटा टाइप    | String                                                                               |
| आइडेंटिफ़ायर | message                                                                              |
| आवश्यक       | true                                                                                 |
| विवरण        | कंसोल में लॉग करने वाला संदेश। सुनिश्चित करें कि संदेश जानकारीपूर्ण और प्रासंगिक हो। |

![logMessage क्लाइंट-टूल सेटअप](/docs/_fern-img/f7ed25d49a2a814b76112f3e385d471e0dc8444705e11f2f6fad0bd23f1eae12.webp)

#### CLI से जोड़ें

#### टूल कॉन्फ़िग फ़ाइल बनाएं

निम्न को `tool_configs/log_message.json` के रूप में सेव करें:

```json
{
  "type": "client",
  "name": "logMessage",
  "description": "Use this client-side tool to log a message to the user's client.",
  "expects_response": false,
  "parameters": {
    "type": "object",
    "properties": {
      "message": {
        "type": "string",
        "description": "The message to log in the console."
      }
    },
    "required": ["message"]
  }
}
```

#### टूल जोड़ें

```bash
elevenlabs tools add "logMessage" --type "client" --config-path ./tool_configs/log_message.json
```

#### अपने एजेंट से टूल रेफ़रेंस करें

`conversation_config.agent.prompt.tool_ids` में टूल की ID जोड़ने के लिए `agent_configs/<agent-name>.json` एडिट करें, फिर पुश करें:

```bash
elevenlabs agents push --agent "<agent-name>"
```

#### API से जोड़ें

```python
from elevenlabs import ElevenLabs, ToolRequestModel

elevenlabs = ElevenLabs()

tool = elevenlabs.conversational_ai.tools.create(
    request=ToolRequestModel(
        tool_config={
            "type": "client",
            "name": "logMessage",
            "description": "Use this client-side tool to log a message to the user's client.",
            "expects_response": False,
            "parameters": {
                "type": "object",
                "properties": {
                    "message": {
                        "type": "string",
                        "description": "The message to log in the console.",
                    }
                },
                "required": ["message"],
            },
        }
    )
)

elevenlabs.conversational_ai.agents.update(
    agent_id="agent_7101k5zvyjhmfg983brhmhkd98n6",
    conversation_config={
        "agent": {"prompt": {"tool_ids": [tool.id]}},
    },
)
```

```typescript
import { ElevenLabsClient } from "@elevenlabs/elevenlabs-js";

const elevenlabs = new ElevenLabsClient();

const tool = await elevenlabs.conversationalAi.tools.create({
  toolConfig: {
    type: "client",
    name: "logMessage",
    description: "Use this client-side tool to log a message to the user's client.",
    expectsResponse: false,
    parameters: {
      type: "object",
      properties: {
        message: {
          type: "string",
          description: "The message to log in the console.",
        },
      },
      required: ["message"],
    },
  },
});

await elevenlabs.conversationalAi.agents.update("agent_7101k5zvyjhmfg983brhmhkd98n6", {
  conversationConfig: {
    agent: { prompt: { toolIds: [tool.id] } },
  },
});
```

#### अपने कोड में क्लाइंट टूल रजिस्टर करें

वेबहुक टूल्स के विपरीत, क्लाइंट टूल्स को आपके कोड में रजिस्टर करना होता है।

क्लाइंट टूल रजिस्टर करने के लिए निम्न कोड इस्तेमाल करें:

**`Python`**

```python title="Python" focus={4-16}
from elevenlabs import ElevenLabs
from elevenlabs.conversational_ai.conversation import Conversation, ClientTools

def log_message(parameters):
    message = parameters.get("message")
    print(message)

client_tools = ClientTools()
client_tools.register("logMessage", log_message)

conversation = Conversation(
    client=ElevenLabs(api_key="your-api-key"),
    agent_id="agent_7101k5zvyjhmfg983brhmhkd98n6",
    requires_auth=True,
    client_tools=client_tools,
    # ...
)

conversation.start_session()
```

**`JavaScript`**

```javascript title="JavaScript" focus={2-10}
// ...
const conversation = await Conversation.startSession({
  // ...
  clientTools: {
    logMessage: async ({message}) => {
      console.log(message);
    }
  },
  // ...
});
```

**`Swift`**

```swift title="Swift" focus={2-10}
// ...
var clientTools = ElevenLabsSDK.ClientTools()

clientTools.register("logMessage") { parameters async throws -> String? in
    guard let message = parameters["message"] as? String else {
        throw ElevenLabsSDK.ClientToolError.invalidParameters
    }
    print(message)
    return message
}
```

> **Note**
>
> एजेंट कॉन्फ़िगरेशन में टूल और पैरामीटर के नाम case-sensitive हैं और आपके कोड में रजिस्टर किए गए नामों से **ज़रूर** मेल खाने चाहिए।

#### टेस्टिंग

अपने एजेंट के साथ बातचीत शुरू करें और कुछ ऐसा कहें:

> *कंसोल में Hello World लिखने वाला संदेश लॉग करें*

आपको अपने कंसोल में `Hello World` लॉग दिखाई देना चाहिए।

#### अगले चरण

अब आपने एक बेसिक क्लाइंट-साइड इवेंट सेट अप कर लिया है, आप ये कर सकते हैं:

* मोडल खोलने, पेज पर नेविगेट करने या DOM के साथ इंटरैक्ट करने जैसे अधिक जटिल क्लाइंट टूल्स एक्सप्लोर करें।
* फुल-स्टैक इंटरैक्शन के लिए क्लाइंट टूल्स को सर्वर-साइड वेबहुक के साथ जोड़ें।
* बातचीत के दौरान यूज़र एंगेजमेंट बेहतर करने और रीयल-टाइम फ़ीडबैक देने के लिए क्लाइंट टूल्स इस्तेमाल करें।

### बातचीत के संदर्भ में क्लाइंट टूल के नतीजे भेजना

जब आप चाहते हैं कि आपके एजेंट को क्लाइंट टूल से डेटा वापस मिले, तो सुनिश्चित करें कि टूल कॉन्फ़िगरेशन में **Wait for response** विकल्प चुना गया हो।

![क्लाइंट टूल कॉन्फ़िगरेशन में रिस्पॉन्स का इंतज़ार करने का विकल्प](/docs/_fern-img/0ecc615fc9f25446b67369fd3e010e34b39549a22146a2483ea17251206caf1e.webp)

क्लाइंट टूल जुड़ने के बाद, जब फ़ंक्शन कॉल होगा, एजेंट उसके रिस्पॉन्स का इंतज़ार करेगा और रिस्पॉन्स को बातचीत के संदर्भ में जोड़ देगा।

**`Python`**

```python title="Python"
def get_customer_details():
    # Fetch customer details (e.g., from an API or database)
    customer_data = {
        "id": 123,
        "name": "Alice",
        "subscription": "Pro"
    }
    # Return the customer data; it can also be a JSON string if needed.
    return customer_data

client_tools = ClientTools()
client_tools.register("getCustomerDetails", get_customer_details)

conversation = Conversation(
    client=ElevenLabs(api_key="your-api-key"),
    agent_id="agent_7101k5zvyjhmfg983brhmhkd98n6",
    requires_auth=True,
    client_tools=client_tools,
    # ...
)

conversation.start_session()
```

**`JavaScript`**

```javascript title="JavaScript"
const clientTools = {
  getCustomerDetails: async () => {
    // Fetch customer details (e.g., from an API)
    const customerData = {
      id: 123,
      name: "Alice",
      subscription: "Pro"
    };
    // Return data directly to the agent.
    return customerData;
  }
};

// Start the conversation with client tools configured.
const conversation = await Conversation.startSession({ clientTools });
```

इस उदाहरण में, जब एजेंट **getCustomerDetails** को कॉल करता है, तो फ़ंक्शन क्लाइंट पर चलेगा और एजेंट को वापस किया गया डेटा मिलेगा, जिसका इस्तेमाल फिर बातचीत के संदर्भ के हिस्से के रूप में होगा। रिस्पॉन्स की वैल्यूज़ को [वेबहुक टूल्स](https://elevenlabs.io/docs/eleven-agents/customization/tools/webhook-tools) की तरह, वैकल्पिक रूप से डायनामिक वैरिएबल्स को भी असाइन किया जा सकता है। ध्यान दें कि सिस्टम टूल्स डायनामिक वैरिएबल्स अपडेट नहीं कर सकते।

### समस्या निवारण

#### टूल्स ट्रिगर नहीं हो रहे हैं

* सुनिश्चित करें कि एजेंट कॉन्फ़िगरेशन में टूल और पैरामीटर के नाम आपके कोड में रजिस्टर किए गए नामों से मेल खाते हैं।
* टूल के चलने की पुष्टि करने के लिए एजेंट डैशबोर्ड में बातचीत का ट्रांसक्रिप्ट देखें।

#### कंसोल एरर्स

* किसी भी एरर के लिए ब्राउज़र कंसोल खोलें।
* सुनिश्चित करें कि आपके कोड में अपरिभाषित या अप्रत्याशित पैरामीटर्स के लिए ज़रूरी एरर हैंडलिंग है।

## सर्वोत्तम तरीके

#### टूल्स के नाम सहज रखें और विस्तृत descriptions दें

अगर आपको लगता है कि assistant सही टूल्स को कॉल नहीं कर रहा है, तो आपको टूल के names और descriptions अपडेट करने पड़ सकते हैं, ताकि assistant को बेहतर तरीके से समझ आए कि हर टूल कब चुनना है। टूल और argument names को छोटा करने के लिए abbreviations या acronyms इस्तेमाल न करें।

आप यह भी बता सकते हैं कि किसी टूल को कब कॉल करना चाहिए। Complex tools के लिए, हर argument का description शामिल करें, ताकि assistant को पता हो कि उस argument को पाने के लिए यूज़र से क्या पूछना है।

#### टूल parameters के नाम सहज रखें और विस्तृत descriptions दें

टूल parameters के लिए स्पष्ट और descriptive names इस्तेमाल करें। अगर लागू हो, तो description में parameter का expected format बताएं (जैसे किसी date के लिए YYYY-mm-dd या dd/mm/yy)।

#### अपने assistant के system prompt में टूल्स को कैसे और कब कॉल करना है, इसकी अतिरिक्त जानकारी देने पर विचार करें

अपने system prompt में स्पष्ट निर्देश देने से assistant की टूल-कॉलिंग accuracy काफ़ी बेहतर हो सकती है। उदाहरण के लिए, assistant को इस तरह के निर्देश दें:

```plaintext
Use `check_order_status` when the user inquires about the status of their order, such as 'Where is my order?' or 'Has my order shipped yet?'.
```

Complex scenarios के लिए context दें। उदाहरण के लिए:

```plaintext
Before scheduling a meeting with `schedule_meeting`, check the user's calendar for availability using check_availability to avoid conflicts.
```

#### LLM चयन

> **Warning**
>
> टूल्स इस्तेमाल करते समय, हम GPT 6 या Claude Sonnet 5.5 जैसे high intelligence models चुनने की सलाह देते हैं।

यह ध्यान रखना ज़रूरी है कि function calls की सफलता में LLM का चयन अहम होता है। कुछ LLMs को conversation से relevant parameters निकालने में मुश्किल हो सकती है।