# SmartAdapter

Namespace: **Wisej.AI**

Assembly: **Wisej.AI** (3.5.0.0)

Represents an abstract base class for creating smart adapters that interact with AI endpoints.

{% tabs %}
{% tab title="C#" %}

```csharp
public class SmartAdapter : Component, IToolProvider
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Class SmartAdapter
    Inherits Component
    Implements IToolProvider
```

{% endtab %}
{% endtabs %}

## Constructors

### ![](/files/ptrKjmmRoQB76pvrIqh0) SmartAdapter()

Initializes a new instance of the [SmartAdapter](/ai/components/api/smartadapter.md) class.

### ![](/files/ptrKjmmRoQB76pvrIqh0) SmartAdapter(container)

Initializes a new instance of the [SmartAdapter](/ai/components/api/smartadapter.md) class attached to an [IContainer](https://docs.microsoft.com/dotnet/api/system.componentmodel.icontainer) implementation to allow for disposing the SmartAdapter when the service container is disposed.

| Name          | Type                                                                                 | Description                                                                                                                             |
| ------------- | ------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------- |
| **container** | [IContainer](https://docs.microsoft.com/dotnet/api/system.componentmodel.icontainer) | An [IContainer](https://docs.microsoft.com/dotnet/api/system.componentmodel.icontainer) that represents the container of the component. |

## Properties

### ![](/files/ptrKjmmRoQB76pvrIqh0) Agents

[AgentCollection](https://docs.wisej.com/api?q=wisej.ai.agentcollection): Gets the collection of agents associated with this adapter.

### ![](/files/ptrKjmmRoQB76pvrIqh0) AutoRun

[Boolean](https://docs.microsoft.com/dotnet/api/system.boolean): Gets or sets a value indicating whether the adapter should automatically run. (Default: `True`)

### ![](/files/ptrKjmmRoQB76pvrIqh0) AutoUpdate

[Boolean](https://docs.microsoft.com/dotnet/api/system.boolean): Gets or sets a value indicating whether the adapter should automatically update the browser when is done processing (requires a working WebSocket connection). (Default: `True`)

### ![](/files/ptrKjmmRoQB76pvrIqh0) Busy

[Boolean](https://docs.microsoft.com/dotnet/api/system.boolean): Gets or sets a value indicating whether the adapter is busy. (Default: `False`)

### ![](/files/ptrKjmmRoQB76pvrIqh0) Controls

[IList\<Control>](https://docs.microsoft.com/dotnet/api/system.collections.generic.ilist-1): Gets the list of controls associated with this adapter.

### ![](/files/ptrKjmmRoQB76pvrIqh0) HasTools

[Boolean](https://docs.microsoft.com/dotnet/api/system.boolean): Gets a value indicating whether the adapter has any tools.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Hub

[SmartHub](/ai/components/api/smarthub.md): Gets or sets the [SmartHub](/ai/components/api/smarthub.md) associated with this adapter.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Name

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets or sets the name of the adapter.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Parameters

[ParameterCollection](https://docs.wisej.com/api?q=wisej.ai.parametercollection): Gets the collection of parameters associated with this adapter.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Session

[SmartSession](/ai/components/api/smartsession.md): Gets the [SmartSession](/ai/components/api/smartsession.md) in use by the adapter.

### ![](/files/ptrKjmmRoQB76pvrIqh0) SystemPrompt

[String](https://docs.microsoft.com/dotnet/api/system.string): Gets or sets the system prompt used by the adapter. (Default: `""`)

### ![](/files/ptrKjmmRoQB76pvrIqh0) Tools

[ToolCollection](https://docs.wisej.com/api?q=wisej.ai.smarttool+toolcollection): Gets the collection of tools associated with this adapter.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Usage

[Metrics](/ai/components/api/smartendpoint/wisej.ai.smartendpoint.metrics.md): Gets the usage metrics for the session.

## Methods

### ![](/files/ptrKjmmRoQB76pvrIqh0) ClearTools()

Clears all tools from the adapter.

### ![](/files/KL0Ik37djZRr8a07Wopd) CreateSession(prompt)

Creates a new session with an optional prompt.

| Parameter                                   | Type                                             | Description                        |
| ------------------------------------------- | ------------------------------------------------ | ---------------------------------- |
| **prompt** ![](/files/52BqKf9SltWQ97FbQSBF) | [SmartPrompt](/ai/components/api/smartprompt.md) | The prompt to use for the session. |

**Returns:** [SmartSession](/ai/components/api/smartsession.md). A new [SmartSession](/ai/components/api/smartsession.md) instance.

### ![](/files/KL0Ik37djZRr8a07Wopd) CreateSession\<T>(systemPrompt)

Creates a new session of a specified type with an optional prompt.

| Parameter                                         | Type                                             | Description                               |
| ------------------------------------------------- | ------------------------------------------------ | ----------------------------------------- |
| **T**                                             |                                                  | The type of session to create.            |
| **systemPrompt** ![](/files/52BqKf9SltWQ97FbQSBF) | [SmartPrompt](/ai/components/api/smartprompt.md) | The system prompt to use for the session. |

**Returns:** [T](/ai/components/api/smartadapter.md). A new session of type *T* .

### ![](/files/KL0Ik37djZRr8a07Wopd) Dispose(disposing)

Releases the unmanaged resources used by the [SmartAdapter](/ai/components/api/smartadapter.md) and optionally releases the managed resources.

| Parameter     | Type                                                            | Description                                                                                      |
| ------------- | --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| **disposing** | [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean) | True to release both managed and unmanaged resources; false to release only unmanaged resources. |

### ![](/files/KL0Ik37djZRr8a07Wopd) GetJSON(message)

Returns the JSON string returned in the *message* by stripping the enclosing markers (`json and` ) if present.

| Parameter   | Type                                                                        | Description                                               |
| ----------- | --------------------------------------------------------------------------- | --------------------------------------------------------- |
| **message** | [Message](/ai/components/api/smartsession/wisej.ai.smartsession.message.md) | Message with the response text that may be a JSON string. |

**Returns:** [String](https://docs.microsoft.com/dotnet/api/system.string). JSON string.

### ![](/files/ptrKjmmRoQB76pvrIqh0) IsAssociatedWith(control)

Determines whether a control is associated with the adapter.

| Parameter   | Type                                                      | Description           |
| ----------- | --------------------------------------------------------- | --------------------- |
| **control** | [Control](https://docs.wisej.com/api?q=wisej.web.control) | The control to check. |

**Returns:** [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean). True if the control is associated; otherwise, false.

### ![](/files/ptrKjmmRoQB76pvrIqh0) NotifyAgentsAsync(message)

Notifies all agents asynchronously with a message.

| Parameter   | Type                                                                        | Description                        |
| ----------- | --------------------------------------------------------------------------- | ---------------------------------- |
| **message** | [Message](/ai/components/api/smartsession/wisej.ai.smartsession.message.md) | The message to notify agents with. |

**Returns:** [Task](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task). A task representing the asynchronous operation.

### ![](/files/KL0Ik37djZRr8a07Wopd) OnBusyChanged(e)

Raises the [BusyChanged](#busychanged) event.

| Parameter | Type                                                                | Description                                                                                          |
| --------- | ------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| **e**     | [EventArgs](https://docs.microsoft.com/dotnet/api/system.eventargs) | An [EventArgs](https://docs.microsoft.com/dotnet/api/system.eventargs) that contains the event data. |

### ![](/files/KL0Ik37djZRr8a07Wopd) OnControlCreated(control)

Called when a control is created.

| Parameter   | Type                                                      | Description                   |
| ----------- | --------------------------------------------------------- | ----------------------------- |
| **control** | [Control](https://docs.wisej.com/api?q=wisej.web.control) | The control that was created. |

### ![](/files/KL0Ik37djZRr8a07Wopd) OnControlDisposed(control)

Called when a control is disposed.

| Parameter   | Type                                                      | Description                    |
| ----------- | --------------------------------------------------------- | ------------------------------ |
| **control** | [Control](https://docs.wisej.com/api?q=wisej.web.control) | The control that was disposed. |

### ![](/files/ptrKjmmRoQB76pvrIqh0) OnDone(e)

Raises the [Done](#done) event.

| Parameter | Type                                                                | Description                                                                                          |
| --------- | ------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| **e**     | [EventArgs](https://docs.microsoft.com/dotnet/api/system.eventargs) | An [EventArgs](https://docs.microsoft.com/dotnet/api/system.eventargs) that contains the event data. |

### ![](/files/ptrKjmmRoQB76pvrIqh0) OnStart(e)

Raises the [Start](#start) event.

| Parameter | Type                                                                | Description                                                                                          |
| --------- | ------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| **e**     | [EventArgs](https://docs.microsoft.com/dotnet/api/system.eventargs) | An [EventArgs](https://docs.microsoft.com/dotnet/api/system.eventargs) that contains the event data. |

### ![](/files/ptrKjmmRoQB76pvrIqh0) RegisterControl(control)

Registers a control with the adapter.

| Parameter   | Type                                                      | Description              |
| ----------- | --------------------------------------------------------- | ------------------------ |
| **control** | [Control](https://docs.wisej.com/api?q=wisej.web.control) | The control to register. |

### ![](/files/ptrKjmmRoQB76pvrIqh0) RemoveTool(tool)

Removes a tool from the adapter.

| Parameter | Type                                                              | Description         |
| --------- | ----------------------------------------------------------------- | ------------------- |
| **tool**  | [Delegate](https://docs.microsoft.com/dotnet/api/system.delegate) | The tool to remove. |

**Returns:** [SmartAdapter](/ai/components/api/smartadapter.md).

### ![](/files/ptrKjmmRoQB76pvrIqh0) RemoveTools(target)

Removes the tools from the specified object.

| Parameter  | Type                                                          | Description                         |
| ---------- | ------------------------------------------------------------- | ----------------------------------- |
| **target** | [Object](https://docs.microsoft.com/dotnet/api/system.object) | The target object containing tools. |

**Returns:** [SmartAdapter](/ai/components/api/smartadapter.md). The current [SmartAdapter](/ai/components/api/smartadapter.md) instance.

### ![](/files/ptrKjmmRoQB76pvrIqh0) RunAsync(control)

Runs the adapter asynchronously.

| Parameter                                    | Type                                                      | Description                        |
| -------------------------------------------- | --------------------------------------------------------- | ---------------------------------- |
| **control** ![](/files/52BqKf9SltWQ97FbQSBF) | [Control](https://docs.wisej.com/api?q=wisej.web.control) | The control to run the adapter on. |

**Returns:** [Task\<Message>](https://docs.microsoft.com/dotnet/api/system.threading.tasks.task-1). A task representing the asynchronous operation.

### ![](/files/ptrKjmmRoQB76pvrIqh0) UnregisterControl(control)

Unregisters a control from the adapter.

| Parameter   | Type                                                      | Description                |
| ----------- | --------------------------------------------------------- | -------------------------- |
| **control** | [Control](https://docs.wisej.com/api?q=wisej.web.control) | The control to unregister. |

### ![](/files/ptrKjmmRoQB76pvrIqh0) UseTool(tool)

Adds a tool to the adapter.

| Parameter | Type                                                              | Description      |
| --------- | ----------------------------------------------------------------- | ---------------- |
| **tool**  | [Delegate](https://docs.microsoft.com/dotnet/api/system.delegate) | The tool to add. |

**Returns:** [SmartAdapter](/ai/components/api/smartadapter.md).

### ![](/files/ptrKjmmRoQB76pvrIqh0) UseTools(target)

Adds multiple tools to the adapter from a target object.

| Parameter  | Type                                                          | Description                         |
| ---------- | ------------------------------------------------------------- | ----------------------------------- |
| **target** | [Object](https://docs.microsoft.com/dotnet/api/system.object) | The target object containing tools. |

**Returns:** [SmartAdapter](/ai/components/api/smartadapter.md).

## Events

### ![](/files/ptrKjmmRoQB76pvrIqh0) BusyChanged

[EventHandler](https://docs.microsoft.com/dotnet/api/system.eventhandler) Occurs when the busy state of the adapter changes.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Done

[EventHandler](https://docs.microsoft.com/dotnet/api/system.eventhandler) Occurs when the adapter has completed processing.

### ![](/files/ptrKjmmRoQB76pvrIqh0) Start

[EventHandler](https://docs.microsoft.com/dotnet/api/system.eventhandler) Occurs when the adapter starts processing.

## Inherited By

| Name                                                                                                      | Description                                                                                                                                                                                                                                                                                                                                                |
| --------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [SmartAudioTTSAdapter](/ai/components/api/smartadapter/wisej.ai.adapters.smartaudiottsadapter.md)         | Converts the [Text](https://docs.wisej.com/api?q=wisej.web.control.text) of the associated [Audio](https://docs.wisej.com/api?q=wisej.web.audio) control into lifelike speech.                                                                                                                                                                             |
| [SmartAudioWhisperAdapter](/ai/components/api/smartadapter/wisej.ai.adapters.smartaudiowhisperadapter.md) | Transcribes the audio file of the of the associated [Audio](https://docs.wisej.com/api?q=wisej.web.audio) control to its [Text](https://docs.wisej.com/api?q=wisej.web.control.text) property in the original language of the audio. [speech-to-text](https://platform.openai.com/docs/guides/speech-to-text)                                              |
| [SmartCalendarAdapter](/ai/components/api/smartadapter/wisej.ai.adapters.smartcalendaradapter.md)         | Represents a smart calendar adapter that extends the functionality of a SmartAdapter.                                                                                                                                                                                                                                                                      |
| [SmartChartAdapter](/ai/components/api/smartadapter/wisej.ai.adapters.smartchartadapter.md)               | Represents an adapter that enhances a chart control with AI features.                                                                                                                                                                                                                                                                                      |
| [SmartChartJS3Adapter](/ai/components/api/smartadapter/wisej.ai.adapters.smartchartjs3adapter.md)         | Represents an adapter that enhances a ChartJS control with several AI features.                                                                                                                                                                                                                                                                            |
| [SmartChatBoxAdapter](/ai/components/api/smartadapter/wisej.ai.adapters.smartchatboxadapter.md)           | Turns the [ChatBox](/ai/components/api/smartadapter/wisej.ai.adapters.smartchatboxadapter.md#chatbox) control into a AI-powered bot. It can answer any question (depending on the AI model being used) and can invoke methods in your applications as needed (see [SmartTool](/ai/components/api/smarttool.md)).                                           |
| [SmartComboBoxAdapter](/ai/components/api/smartadapter/wisej.ai.adapters.smartcomboboxadapter.md)         | Adds semantic filtering to the [ComboBox](https://docs.wisej.com/api?q=wisej.web.combobox) auto-complete functionality.                                                                                                                                                                                                                                    |
| [SmartCopilotAdapter](/ai/components/api/smartadapter/wisej.ai.adapters.smartcopilotadapter.md)           | Turns the [ChatBox](/ai/components/api/smartadapter/wisej.ai.adapters.smartcopilotadapter.md#chatbox) control into a AI-powered assistant. It can control and navigate an application, click menu items, navigation bar items, buttons, etc. It can also invoke methods in your applications as needed (see [SmartTool](/ai/components/api/smarttool.md)). |
| [SmartDataEntryAdapter](/ai/components/api/smartadapter/wisej.ai.adapters.smartdataentryadapter.md)       | Enhances all the controls in the associated container with the AI-powered capability to extract structured data from unstructured text.                                                                                                                                                                                                                    |
| [SmartDocumentAdapter](/ai/components/api/smartadapter/wisej.ai.adapters.smartdocumentadapter.md)         | Represents a document adapter that can perform AI tasks using a document as a data source and interact with the user through a ChatBox control.                                                                                                                                                                                                            |
| [SmartFullCalendarAdapter](/ai/components/api/smartadapter/wisej.ai.adapters.smartfullcalendaradapter.md) |                                                                                                                                                                                                                                                                                                                                                            |
| [SmartObjectAdapter](/ai/components/api/smartadapter/wisej.ai.adapters.smartobjectadapter.md)             | Converts unstructured text into a structured .NET object.                                                                                                                                                                                                                                                                                                  |
| [SmartPictureBoxAdapter](/ai/components/api/smartadapter/wisej.ai.adapters.smartpictureboxadapter.md)     | Represents an adapter for a PictureBox that generates images based on a description using the OpenAI DALL-E endpoint.                                                                                                                                                                                                                                      |
| [SmartQueryAdapter](/ai/components/api/smartadapter/wisej.ai.adapters.smartqueryadapter.md)               | Represents an adapter that generates a data set from a database schema and a user-provided description.                                                                                                                                                                                                                                                    |
| [SmartRealtimeAdapter](/ai/components/api/smartadapter/wisej.ai.adapters.smartrealtimeadapter.md)         | Represents a smart adapter that provides real-time data processing capabilities for use with the [OpenAIEndpointRealtime](/ai/components/api/smartendpoint/wisej.ai.endpoints.openaiendpointrealtime.md) endpoint.                                                                                                                                         |
| [SmartReportAdapter](/ai/components/api/smartadapter/wisej.ai.adapters.smartreportadapter.md)             | Enhances the ChatBox control to allow seamless PDF report queries using an AI provider.                                                                                                                                                                                                                                                                    |
| [SmartTextBoxAdapter](/ai/components/api/smartadapter/wisej.ai.adapters.smarttextboxadapter.md)           | Enhances a TextBox control with several AI features, including suggestions, translation, and auto-correction.                                                                                                                                                                                                                                              |

## Implements

| Name                                                                              | Description                                |
| --------------------------------------------------------------------------------- | ------------------------------------------ |
| [IToolProvider](/ai/components/api/smarttool/wisej.ai.smarttool.itoolprovider.md) | Represents a provider that supplies tools. |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/ai/components/api/smartadapter.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
