# Agent

{% hint style="warning" %}
The Agent class is **NOT** a React Component.

Therefore none of the [Component Lifecycle functions](https://facebook.github.io/react/docs/react-component.html#the-component-lifecycle) is available.
{% endhint %}

## What is Agent?

The Agent is a js class, think about it like the brain of your plugin, the main component to communicate and do requests and talk to the outer world.

Agent can communicate with other components in your plugin or other plugin's Agent or component with the "plugin events dispatcher"&#x20;

The plugin Agent will be initiated and initialized once the plugin register it self.

Agent will always be up and running as long as your plugin is installed and active in Dashboard.

Agent will only be turned "off" when the plugin is uninstalled or deactivated.

Once the plugin is deactivated or Dashboard window closed, Dashboard will try to call the `close()` function if there is one provided in the Agent.

## What does the Agent look like?

You can build your Agent component by extending the Agent base from Plugin-API

```javascript
import { Plugin } from '@root'

class MyAgent extends Plugin.Agent {
    constructor(props) {
        super(props)
        
        this.config = props.config
        
        this.doMagic()
    }

    doMagic() {
        // i can do magic with this.config if you want to 🧙🏿‍♂️
    }
}

export {
    MyAgent
}
```

Dashboard will pass custom props to your Agent including the config of your plugin to be used inside your Agent

## How to register an Agent?

In your main `index.js` file where you register your plugin, import your Agent and pass it down with the register() method from Plugin-API

```javascript
import DashboardPlugin from 'Dashboard/plugin'

const Plugin = new DashboardPlugin('@plugin_bundle')

const registerPlugin = () => {
    const { MyAgent } = require('@components/Agent')
    
    Plugin.register({
        agent: MyAgent
    })
}

registerPlugin()

export {
    Plugin
}
```

## close()

Function that is called before agent is unregistered.

```
close() {
    // This is where you should for example close connections or clear intervals.
}

```


---

# 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.navigaglobal.com/dashboard-plugin/components/agent.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.
