> For the complete documentation index, see [llms.txt](https://ruilabs.gitbook.io/airgent/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ruilabs.gitbook.io/airgent/agent/using-a-community-node-mediastack-in-your-agent.md).

# Using a community node (Mediastack) in your agent

Community Nodes allow you to extend your agent’s functionality with tools built by other developers. In this section, we’ll integrate the Mediastack Node, created by JunyaoC, to fetch live news.

## **Prerequisites**

Before starting, ensure you have:

1. A **Mediastack API Key**: Register an account at [Mediastack](https://mediastack.com/) to obtain your key.
2. Familiarity with the **Live News API**: Refer to the [Mediastack documentation](https://mediastack.com/documentation) for details on how the API works.
3. This guide is a continued guide from [Using ChatGPT node in your agent](/airgent/agent/using-chatgpt-node-in-your-agent.md). Make sure you have go through the guide.

***

## **Step-by-Step Guide**

The final agent are setup as below:

<figure><img src="https://4116416135-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUjtYjZk0Li2m5r1hpmEd%2Fuploads%2F5n8FvqfbnDr8M3N8Rn3l%2Fimage.png?alt=media&amp;token=6a4e0ea5-11ee-4c27-8656-1455bf7ec69c" alt=""><figcaption><p>Agent setup with community node</p></figcaption></figure>

{% stepper %}
{% step %}
**Add the Mediastack Node**

1. Locate the **Mediastack Node** in the **Community Nodes** section of the **Node Library**.
2. Drag the node into your workspace.
   {% endstep %}

{% step %}
**Configure the Mediastack Node**

The Mediastack Node has several inputs for filtering news based on your requirements. For this example, we’ll filter for news from **Malaysia**.

1. **API Key**:
   * Paste your Mediastack API key into the `api_key` field of the node.
2. **Country Filter**:
   * Double-tap an empty space in the editor and type `str`.
   * Select **Basic/String** from the options and drag it to your workspace.
   * Enter the value `my` (country code for Malaysia) into the String node.
   * Connect this String node to the `countries` input of the Mediastack Node.
3. **Other Inputs**:
   * If needed, you can use additional String nodes to specify filters like `sources`, `categories`, `keywords`, or `languages`.
   * For now, we’ll only filter by country.
     {% endstep %}

{% step %}
**Why Do We Need a JSON Stringify Node?**

The Mediastack Node returns raw JSON data, which may not be easily readable or usable for downstream nodes like ChatGPT.

* **JSON Stringify** converts this raw JSON data into a formatted string, making it compatible with nodes like ChatGPT for natural language processing.
* It also ensures that any additional information can be passed in a structured and clean format.

To add the JSON Stringify Node:

1. Drag it from the library under **Basic/Format** or use the **double-click shortcut** (explained below).
2. Connect the `result` output of the Mediastack Node to the `value` input of the JSON Stringify Node.
   {% endstep %}

{% step %}
**Connect the Workflow**

1. **Execution Flow (Exec)**:
   * Connect the `exec` output of the **Input Node** to the `exec` input of the **Mediastack Node**.
   * Link the `exec` output of the Mediastack Node to the **JSON Stringify Node**, and then to the **ChatGPT Node**.
   * Finally, connect the execution flow to the **Output Node**.
2. **Message/Data Flow**:
   * Link the `message` output of the Input Node to the `message` input of the Mediastack Node.
   * Connect the `result` output of the Mediastack Node to the `value` input of the JSON Stringify Node.
   * Pass the output of the JSON Stringify Node to the `message` input of the ChatGPT Node.
   * Finally, link the `response` output of the ChatGPT Node to the **Output Node**.
     {% endstep %}

{% step %}
**Test Your Agent**

1. Use the **Message Box** to input a test message.
   * For example, type: *“Fetch the latest news from Malaysia.”*
2. Observe the results:
   * The Mediastack Node fetches live news from Malaysia.
   * JSON Stringify formats the data.
   * ChatGPT processes and summarizes the news, which is returned to the Message Box.
     {% endstep %}
     {% endstepper %}

***

## **Summary**

* **Mediastack Node**: Fetches live news with flexible filters.
* **String Nodes**: Quickly assign values for filtering (e.g., country: `my` for Malaysia).
* **JSON Stringify Node**: Converts raw data into a readable string format for ChatGPT.
* **Double-Click Shortcut**: Saves time by skipping manual node selection from the library.

This guide empowers users to efficiently integrate a Community Node and optimize their workflow.
