LogoLogo
Visit Contextual.ioSign Up
  • Getting Started
    • Welcome
    • Tour: Hello, AI World!
  • TRAINING
    • Basic Developer Training Course
      • Lesson 1: HTTP Agent Introduction
      • Lesson 2: Logging and Error Handling Basics
      • Lesson 3: Event Processing Agent Introduction
  • Services Catalog
    • What's in the Catalog?
      • Intro Patterns
      • Object Type Bundles
    • Browse by Platform
    • All Intro Patterns
      • Anthropic Claude Image Analysis
      • Mistral AI Prompt and Response
      • xAI Grok Prompt and Response
      • DeepSeek Chat Prompt and Response
      • Qwen Chat Prompt and Response
      • Perplexity AI Search and Response
      • Firecrawl Website Scraper
      • Groq Prompt and Response
      • Nyckel Dog Breed Classification
      • RapidAPI ClassifyAI Text Classification
      • RapidAPI YouTube AI Video Summary
      • UnifyAI Model Comparison
      • WebPilot URL Analysis and Summarization
      • OpenAI Assistants Prompt and Response
      • OpenAI Sync
    • All Prebuilt Solutions
      • Invoice AI
      • Lead Generation Form
    • All Object Type Bundles
      • Work Order Management System ITIL Object Type Bundle
        • Work Order
        • User
        • Role
        • Permission
        • Asset
        • Task
        • Action
        • Attachment
        • Comment
        • Notification
        • Audit Log
        • Service Level Agreement
        • Custom Fields
        • Work Order Template
        • Work Order Transition
        • Escalation Policy
        • Tag
  • Components & Data
    • Object Types
      • Data in Contextual
        • Secrets
        • Validation
        • Versioning
      • Examples
      • Creating an Object Type
      • Object Type Details
        • Definition
        • Data Schema
          • Automatic Record Metadata
          • Generated Values
            • Dates and Times
            • UUIDs
          • Frequently Used Validation
          • Disallowing Null Property Values
          • Disallowing Undefined Properties
          • Secrets
          • AI Assistant
          • ID and PrimaryKey Permanence
        • UI Schemas
        • Features
        • Triggers
        • Actions
        • Audit Trail
        • Versions
        • Templates
        • Records
      • Using Object Types in Flows
      • Records
        • Records and Your Tenant API
        • Record Import
    • Flows
      • Nodes
      • Wires
      • Message Object
      • Flow Editor
        • Basics
        • Saving Changes
        • In-Flow Testing with Debugger
        • Restart Agents to Make Changes Active
        • Config
      • Node Reference
        • Common
          • Log Tap
          • Inject
          • Debug
          • Complete
          • Catch
          • Status
          • Link In
          • Link Call
          • Link Out
          • Comment
        • Event
          • Prepare Event
          • Event Start
          • Event End
          • Event Error
        • Object
          • Search Object
          • Get Object
          • Create Object
          • Patch Object
          • Put Object
          • Delete Object
          • Run Action
        • Request
          • Send to Agent
          • HTTP GET
          • HTTP PATCH
          • HTTP PUT
          • HTTP DELETE
          • HTTP POST
          • GQL
          • Produce Message
        • Function
          • Function
          • Switch
          • Change
          • Range
          • Template
          • Delay
          • Trigger
          • Exec
          • Filter
          • Loop
        • Models
          • ML Predict
        • Network
          • MQTT In
          • MQTT Out
          • HTTP In
          • HTTP Response
          • HTTP Request
          • WebSocket In
          • WebSocket Out
          • TCP In
          • TCP Out
          • TCP Request
          • UDP In
          • UDP Out
        • Sequence
          • Split
          • Join
          • Sort
          • Batch
        • Parser
          • csv
          • html
          • json
          • xml
          • yaml
    • Agents
      • Creating an Agent
      • Types of Agents
        • Event to Flow
        • HTTP to Flow
          • Custom Domains
      • How Agents Work
        • Flow Execution
        • HTTP Load Balancing
        • Event Routing
      • Scale and Performance
        • Flow execution
        • Parallel Instances
        • Event Lag Scaling
        • Compute Threshold Scaling
        • Instance Compute Sizing
      • Agent Details
        • Definition
        • Operations
        • Logs
          • Session Log
          • Message Log
        • Audit Trail
        • Versions
      • Using Agents in Flows
    • Connections
      • Creating a Connection
      • Types of Connections
        • Basic
        • Bearer
        • Client Grant
        • Kafka
        • Password Grant
        • Public
        • Pulsar
      • Using Connections in Flows
    • JWKS Profiles
      • Using JWKS Profiles in Your Solution
  • PATTERNS
    • Solution Architecture
      • Events, Messages, Queues
    • Working with Data
      • Search Object Node & Pagination
      • Message Payload Content - Triggers and Actions
    • Industry Cookbooks
      • Field Services
  • Tenants
    • Tenant Workspace
    • Tenant Logs
      • Contextual Log Query Language (CLQL)
        • String Searches
        • Keyword Searches
        • Advanced Operators
    • Tenant API
      • API Keys
        • API Key Settings
        • API Key Permissions
      • Documentation
  • Release Notes
    • 2024
      • 2024.12.09
Powered by GitBook
On this page
  • Temperature Event Monitoring Agent
  • Overview
  • Detailed Steps

Was this helpful?

  1. TRAINING
  2. Basic Developer Training Course

Lesson 3: Event Processing Agent Introduction

PreviousLesson 2: Logging and Error Handling BasicsNextWhat's in the Catalog?

Last updated 7 months ago

Was this helpful?

Temperature Event Monitoring Agent

Overview

Objective: Build an event-processing agent that receives the incoming temperature events and monitors temperature data for anomalies.

Description:

  • Add a weather-alert native-object.

  • Create an event-processing flow to monitor temperature data, either from manual submissions (like in Project 1) or through simulated temperature data (from an inject node). The goal is to detect temperature readings that fall outside of a set range (e.g., below 0°C or above 35°C) and create an alert object

  • Create an event-processing agent using the new flow

  • Add a trigger to the existing weather-report native object to send the message (as an event) to the new agent POST-INSERT.

Terminal Objective: Gain a basic understanding of how to create an event-to-flow agent that uses function nodes and switch nodes to process events, with the results being stored in additional native objects.

Enabling Objectives:

  • Set up an inject node to simulate a weather-report event.

  • Use a function node to detect low-temperature or high-temperature events.

  • Add logic (switch node) to detect low/high temperature anomalies and create an alert native-object.

  • Testing using an inject node.

Skills: FLOW-2, TRIGGER-1, CORE-1, CORE-3, CORE-5

Detailed Steps

This lessson begins where Lesson 2 left off. Ensure that you have compled lesson 2 and have the agent, flow, and object-type from that lesson in your tenant before continuing.

In this lesson we are going to send the weather reports received by the HTTP agent to an Event processing agent that will monitor for anomalous temperature readings, and when found, generate a "Weather Alert" record.

Part 1 — Create a New Object Type

  1. Create a new object-type called "weather-alert" as shown below:

{
  "primaryKey": "id",
  "type": "object",
  "$comment": "Schema representing a weather alert type",
  "properties": {
    "id": {
      "type": "string",
      "generate": {
        "type": "uuid",
        "format": "short"
      }
    },
    "timestamp": {
      "type": "string",
      "generate": {
        "type": "datetime"
      },
      "description": "The timestamp when the alert was created"
    },
    "type": {
      "type": "string",
      "enum": [
        "HIGH_TEMP",
        "LOW_TEMP",
        "WIND",
        "RAIN",
        "SNOW"
      ],
      "description": "The type of weather alert"
    },
    "description": {
      "type": "string",
      "minLength": 1,
      "description": "Detailed description of the weather alert"
    },
    "report": {
      "type": "object"
    }
  },
  "$commentRequired": "Optional, a list of mandatory properties for instances of this Object Type",
  "required": [
    "type",
    "description"
  ]
}

Part 2 — Create a New Flow

  1. Create a new flow called "weather-monitor". Open the flow in the flow editor.

  2. Add an Inject node, a Prepare Event node, and an Event Start node to the canvas as shown below.

  1. Modify the Inject node, changing the msg.payload type to "JSON" and setting the JSON value to:

{
    "temperature": 25,
    "stationId": "JEFF"
}
  1. Give the Inject node a name as well: "TEST". Save the changes to the Inject node.

  2. Add a function node to the canvas and wire it in immediately after the Event Start node.

  3. Double-click the function node to open the editor.

  4. Add the following JavaScript code to the function node.

// Payload will have temperature and stationId

// monitor for temperatures above 38C and below 0. Generate
// a weather alert if the temperature is outside of this range

msg.alert = false;

if (msg.payload.hasOwnProperty("temperature")) {

    if (msg.payload.temperature <= 0) {
        msg.alert = true;
        msg.alertType = "LOW_TEMP";
    } else if (msg.payload.temperature >= 38) {
        msg.alert = true;
        msg.alertType = "HIGH_TEMP";
    }
}

// important: always return msg from a function node
return msg;
  1. Give the function node a name: "Check Temperature"

  2. Click "Done" to save the changes to the function node.

  3. Your flow should now look like this:

  1. Drag a Switch node onto the canvas and wire it right after the function node.

  2. Double-click the Switch node to open the configuration editor.

  3. Give the switch node a name: "Alert?"

  4. Modify the "Property" field to check for msg.alert

  5. Modify the condition below the property to "is true"

  6. Add another condition and set it to "otherwise"

  7. At the bottom of the window, change the dropdown from "checking all rules" to "stopping after first match".

  8. Your Switch node should now look like this:

  1. Drag a new Function node onto the canvas and wire it to the "is true" output of the Switch node, like this:

  1. Open the function node and add the following JS. Give it a name: "Prep New Alert".

// build the alert record

msg.newAlert = {
    type: msg.alertType,
    description: msg.alertDescription,
    report: msg.payload
}

return msg;
  1. Drag a new Create Object node onto the canvas and wire it after the "Prep New Alert" Function node.

  2. Configure it as shown below:

  1. Drag an Event End node onto the canvas and wire it after the Create Object node.

  2. Connect the "Otherwise" output of the Switch node to the Event End node also.

  3. Your flow should now appear as shown below.

  1. Drag a Catch Node onto the canvas.

  2. Add log-tap node and wire it right after the Catch node. Name it "Error" and configure it for "Complete Msg Object" and log-level = Error.

  3. Add an Event Error node after the log-tap node.

  4. Your error handling should now look like this:

  1. Click Save to save your flow.

Part 3 — Create the Agent to run your new Flow

  1. Create a new agent as shown below:

NOTE: The agent type for this agent is "Event to Flow" and NOT "HTTP to Flow".

  1. Open the agent and wait for it to show "Running" in the Operations tab.

  2. Navigate to Components/Object Types and open the weather-report object type.

  3. Click on the "Triggers" tab and add a "Post-Insert" trigger using the "+" button.

  4. Select "SendToAgent"

  5. Give the trigger a name: "Send Weather Report"

  6. If needed, select "Weather Monitor" as the agent to send the event to. The trigger configuration should look like this:

  1. Save the trigger by clicking on "Create Trigger".

Part 4 — Testing Your New Agent

  1. Go back to the browser tab where you have the Submit Weather Report form. If you don't have it open any longer, go back to the "Submit Weather Report" agent and copy the agent URL and remember to append "/form" to the URL.

  2. Submit a weather report with a temperature within the range 0 < temperature < 38. For example: 25.

  3. Now submit a weather report with a temperature above the high temperature threshold. For example: 40.

  4. Now submit a weather report with a temperature below the log temperature threshold. For example, -5.

  5. Now navigate to Records/Data/Weather Reports in the console and verify that you see all of these new reports, as shown below.

  1. Now navigate to Records/Data/Weather Alerts in the console and verify that you see two weather alerts, for the HIGH_TEMP alert and the LOW_TEMP alert.

Congratulations! You have now completed Lesson 3 of the Basic Developer Training Course. You now have an understanding of how to create Event Processing agents as well as new function nodes such as Function and Switch.