LogoLogo
  • 👋Welcome to Groclake
  • ⏩Jump right in
  • 🗣️Introduction to Groclake
  • 🧠High level Concepts
    • Agent Discovery
    • Agent Registry
    • Agent Communication
      • Agent Text Transfer Protocol - ATTP
    • Agent Security
      • Agent Private Cloud - APC
      • Authentication & Encryption
      • Zero Trust Policy
  • 💽Installation & Guide
  • 🏗️Groclake Use Cases
  • 📰Groclake Records
  • Example Codes
  • GrocAgent
    • What is GrocAgent?
    • Example Chat Agent
    • Reflections in GrocAgent
      • Workflow of Reflection Handler
  • Lakes
    • 💾Data & Model Management
      • Datalake
        • Create Datalake
        • Retrieve Document
        • Upload Documents
        • Datalake Connections
          • Snowflake integration
      • Vectorlake
        • Creating vector
        • Generating Vector
        • Pushing Vector
        • Retrieve Document
        • Searching Vector
      • Modellake
        • Create Modellake
        • Language Translation
        • Conversation AI
        • Text to Speech
        • Chat Completion
      • Knowledgelake
        • Create Knowledge Base
        • Push Documents from a URL
        • Push Documents from Local Storage
        • Searching for Information
    • ⚒️Tool Management & Gateway
      • Toollake
        • Tools
        • Salesforce CRM Integration
        • Slack Communication Module
        • New Relic Integration
        • Google Calendar Integration
          • Check Slot Availability
          • Get Available Slots
          • Delete Event
          • Create new event
          • Create new calendar event
    • 🤖Agent Management & Deployment
      • Agentlake
        • Register your agent
        • Fetch agent details & categories
        • Create Agent Private Cloud (APC)
        • Assign Agent Private Cloud (APC) to an Agent
      • Promptlake
        • Setting Connection & Initializing
        • Storing a Prompt
        • Fetching a Prompt
        • Example API Calls
      • Memorylake
        • Context Component Examples
        • Value Structure
        • Setup & Guide
        • Storing & Retrieving Memory
        • Wildcard Search
        • Updating Memory Quality
    • 🗃️Index Stores
      • Cataloglake
        • Create catalog
        • Generate Product Data
        • Fetch Catalog Data
        • Push Product Data
        • Optimize Data Retrieval with Catalog Caching
        • Search for Products
        • Filter Product Search
        • Update Product Data
        • Recommend Products Based on Product Name
        • Update Inventory in Catalog
        • Fetch Inventory Details from Catalog
        • Fetch Product Price
        • Update Product Price in Catalog
        • Cache Image in Catalog
        • Sync Your Catalog with external ecomm platforms
        • Deleting items
        • Address Parsing and Intent Extraction
        • Creating Mapper
        • Convert Mapper's Metadata
        • Fetching Mapper
        • Updating Mapper
        • Example use case of Cataloglake
      • Joblake
        • Joblake Mapping
        • Creating a Joblake
      • Resumelake
        • Resumelake Mapping
        • Creating a Resumelake
Powered by GitBook
On this page
  • Example: ChatAgent
  • Imports
  • Implementation Details
  • Default Handler
  • Request and Response Example
  1. GrocAgent

Example Chat Agent

Example: ChatAgent

ChatAgent is an implementation of GrocAgent designed to handle chat-based queries. It demonstrates how to use GrocAgent to create a chatbot capable of processing user queries and generating responses using an external model (e.g., Modellake). Note: While this example uses Modellake to implement chatbot functionality, users can extend GrocAgent to incorporate other libraries or custom logic based on their project requirements.

Imports

Ensure the following imports are included when using GrocAgent:

from flask import Flask  # Flask is used as the web server framework
from groclake.modellake import Modellake  # (Optional) For handling chatbot logic
from groclake.utillake import GrocAgent  # Base class to define custom agents

Implementation Details

The ChatAgent example is initialized with:

  1. Flask App Instance: Registers the agent with a Flask application.

  2. Agent Name: Identifies the agent (e.g., "ChatAgent").

  3. Initial Intent and Description: Defines the default intent ("chat") and its purpose.

  4. Adaptor Configuration: Links external dependencies through configurations.

class ChatAgent(GrocAgent):
    def __init__(self, app, agent_name, initial_intent=None, intent_description=None, adaptor_config=None):
        super().__init__(app, agent_name, initial_intent, intent_description, self.default_handler, adaptor_config)

Default Handler

The default_handler method processes incoming payloads to:

  • Extract key components: query_text, intent, entities, and metadata.

  • Construct a chat payload for the Modellake API.

  • Retrieve and return a response from the model, with error handling for fallback responses.

def default_handler(self, payload):
    try:
        query_text = payload.get('query_text', 'No query provided')
        intent = payload.get('intent', 'default_chat')
        entities = payload.get('entities', [])
        metadata = payload.get('metadata', {})

        chat_payload = {
            "messages": [
                {"role": "system", "content": "You are a helpful assistant. Only answer technical questions."},
                {"role": "user", "content": query_text}
            ],
            "token_size": 500
        }

        chat_response = Modellake().chat_complete(chat_payload)
        response_text = chat_response.get("answer", "I'm not sure how to help with that.")

        return {
            "response_text": response_text,
            "intent": intent,
            "entities": entities,
            "metadata": metadata,
            "query_text": query_text
        }
    except Exception as e:
        return {
            "response_text": f"Error: {str(e)}",
            "intent": payload.get('intent', 'default_chat'),
            "metadata": payload.get('metadata', {}),
            "query_text": payload.get('query_text', ''),
            "status": 500
        }

Request and Response Example

Request Example

{
  "groc_account_id": "",
  "header": {
    "version": "1.0",
    "message": "Request",
    "Content-Type": "application/json",
    "auth_token": "Authentication-Token",
    "apc_id": "c9d1c9b9-9f1b-4430-9bd4-6994dc1c89ee",
    "server_agent_uuid": "075fcb88-f25a-4390-a37e-e374a3c2b1df",
    "client_agent_uuid": "Client-Agent-UUID"
  },
  "body": {
    "query_text": "What is AI?",
    "intent": "chat",
    "entities": [{"ticket_id": "123314141"}],
    "metadata": {
      "context": "query generated from a support chatbot",
      "customer_id": "895985133"
    }
  }
}

Response Example

{
  "body": {
    "entities": [{"ticket_id": "123314141"}],
    "intent": "chat",
    "metadata": {
      "context": "query generated from a support chatbot",
      "customer_id": "895985133"
    },
    "query_text": "What is AI?",
    "response_text": "AI, or Artificial Intelligence, refers to the simulation of human intelligence processes by machines..."
  },
  "header": {
    "apc_id": "c9d1c9b9-9f1b-4430-9bd4-6994dc1c89ee",
    "auth_token": "Authentication-Token",
    "client_agent_uuid": "Client-Agent-UUID",
    "content-type": "application/json",
    "message": "response",
    "version": "1.0"
  }
}

PreviousWhat is GrocAgent?NextReflections in GrocAgent

Last updated 3 months ago