Skip to content

Simple Chatbot

Overview

A friendly conversational chatbot with memory that maintains context across multiple conversation turns. This example demonstrates the minimal setup needed to create a stateful chatbot using AWS Bedrock, perfect for getting started with conversational AI applications.

Architecture

flowchart TD
    subgraph APP ["📱 simple_chatbot"]
        direction TB

    subgraph FLOW_0 ["🔄 chat_flow"]
        direction LR
        FLOW_0_START@{shape: circle, label: "▶️ Start"}
        FLOW_0_S0@{shape: rounded, label: "✨ generate_response"}
        FLOW_0_START -->|user_message| FLOW_0_S0
    end

    subgraph RESOURCES ["🔧 Shared Resources"]
        direction LR
        MODEL_NOVA_LITE@{shape: rounded, label: "✨ nova_lite (aws-bedrock)" }
        MEM_CONVERSATION_MEMORY@{shape: win-pane, label: "🧠 conversation_memory (10KT)"}
    end

    end

    FLOW_0_S0 -.->|uses| MODEL_NOVA_LITE
    FLOW_0_S0 -.->|stores| MEM_CONVERSATION_MEMORY

    %% Styling
    classDef appBox fill:none,stroke:#495057,stroke-width:3px
    classDef flowBox fill:#e1f5fe,stroke:#0277bd,stroke-width:2px
    classDef llmNode fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px
    classDef modelNode fill:#e8f5e8,stroke:#2e7d32,stroke-width:2px
    classDef authNode fill:#fff3e0,stroke:#ef6c00,stroke-width:2px
    classDef telemetryNode fill:#fce4ec,stroke:#c2185b,stroke-width:2px
    classDef resourceBox fill:#f5f5f5,stroke:#616161,stroke-width:1px

    class APP appBox
    class FLOW_0 flowBox
    class RESOURCES resourceBox
    class TELEMETRY telemetryNode

Complete Code

id: simple_chatbot
description: A friendly chatbot with conversation memory using AWS Bedrock
models:
  - type: Model
    id: nova_lite
    provider: aws-bedrock
    model_id: amazon.nova-lite-v1:0
    inference_params:
      temperature: 0.7
      max_tokens: 512
memories:
  - id: conversation_memory
    token_limit: 10000
flows:
  - type: Flow
    id: chat_flow
    interface:
      type: Conversational
    variables:
      - id: user_message
        type: ChatMessage
      - id: assistant_response
        type: ChatMessage
    inputs:
      - user_message
    outputs:
      - assistant_response
    steps:
      - id: generate_response
        type: LLMInference
        model: nova_lite
        system_message: |
          You are a friendly and helpful chatbot. You have a warm, conversational 
          tone and enjoy helping users with their questions. You remember context 
          from previous messages in the conversation.
        memory: conversation_memory
        inputs:
          - user_message
        outputs:
          - assistant_response

Key Features

  • Conversational Interface: This instructs the front-end to create a conversational user experience.
  • Memory: Conversation history buffer with token_limit (10,000) that stores messages and automatically flushes oldest content when limit is exceeded
  • ChatMessage Type: Built-in domain type with role field (user/assistant/system) and blocks list for structured multi-modal content
  • LLMInference Step: Executes model inference with optional system_message prepended to conversation and memory reference for persistent context across turns
  • Model Configuration: Model resource with provider-specific inference_params including temperature (randomness) and max_tokens (response length limit)

Running the Example

# Start the chatbot server
qtype serve examples/conversational_ai/simple_chatbot.qtype.yaml

Learn More