# Keeping Your Agent Updated

How to ensure I am running the latest/recommended agent version

### Problem <a href="#problem" id="problem"></a>

When configuring the SeaLights agent for Java, it is difficult to manage the .jar files are in the correct version - especially in standalone environments (containers, backend servers etc)

### Solution <a href="#solution" id="solution"></a>

The following shell script checks for the recommended agent and latest version, and in case it does not exist locally - downloads & unzips it in the given directory.

#### Downloading the Recommended Agent set in settings <a href="#downloading-the-recommended-agent-set-in-settings" id="downloading-the-recommended-agent-set-in-settings"></a>

{% code overflow="wrap" lineNumbers="true" %}

```sh
#!/bin/bash

export DOMAIN=<CustomerDomain>.sealights.co
export SEALIGHTS_AGENT_TOKEN=`cat sltoken.txt`

if [ -f "sealights-java-agent.zip" ]; then
    export SL_LOCAL_VERSION=`cat sealights-java-version.txt`
    export SL_SETTINGS_VERSION=`curl -sX GET "https://$DOMAIN/sl-api/v1/agent-apis/agents/types/sealights-java/default-version" -H "Authorization: Bearer $SEALIGHTS_AGENT_TOKEN" -H "accept: application/json" | jq  -r .version`
    
    if [ "${SL_LOCAL_VERSION}" == "${SL_SETTINGS_VERSION}" ]; then
        echo "Skipping Download - Local agent matches the current latest version:" $SL_SETTINGS_VERSION
    else
        echo "Local agent is not using the latest version. Deleting local agent."
        rm -fr sealights-java-*  sl-*.jar     
    fi
fi

if [ ! -f "sealights-java-agent.zip" ]; then
    echo "Downloading Java Agent version set in Settings..."
    wget -nv -O sealights-java-agents.zip --header "accept: application/json" --header "Authorization: Bearer $SEALIGHTS_AGENT_TOKEN" \
        https://$DOMAIN/api/v2/agents/sealights-java/recommended/download

    unzip -oq sealights-java-agents.zip
    echo "Local agent version is now:" `cat sealights-java-version.txt`
fi
```

{% endcode %}

#### Downloading the latest agent <a href="#downloading-the-latest-agent" id="downloading-the-latest-agent"></a>

{% code overflow="wrap" lineNumbers="true" %}

```sh
#!/bin/bash

if [ -f "sealights-java-latest.zip" ]; then
    export LOCL_SL_VERSION=`cat sealights-java-version.txt`
    export CURR_SL_VERSION=`curl -s https://agents.sealights.co/sealights-java/sealights-java-version.txt`
    
    if [ "${LOCL_SL_VERSION}" == "${CURR_SL_VERSION}" ]; then
        echo "Skipping Download - Local agent matches the current latest version:" $CURR_SL_VERSION
    else
        echo "Local agent is not using the latest version. Deleting local agent."
        rm -fr sealights-java-*  sl-*.jar     
    fi
fi

if [ ! -f "sealights-java-latest.zip" ]; then
    echo "Downloading Sealights Latest Agent..."
    wget -nv https://agents.sealights.co/sealights-java/sealights-java-latest.zip
    unzip -o sealights-java-latest.zip
    echo "Local agent version is now:" `cat sealights-java-version.txt`
fi

```

{% endcode %}


---

# 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.sealights.io/knowledgebase/setup-and-configuration/troubleshooting-faq/java/keeping-your-agent-updated.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.
