> For the complete documentation index, see [llms.txt](https://docs.navigaglobal.com/dashboard-plugin/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.navigaglobal.com/dashboard-plugin/components/agent.md).

# 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.
}

```
