Overview

This YAML configuration describes a state machine designed to handle a chat interaction with capabilities for searching information using Google and Wikipedia.

YAML Workflow

initial_state:
  messages:
    - role: system
      content: Today's date is January 7, 2025.
starting_node: search_chat
machine:
  search_chat:
    workflow_config:
      final_output_nodes:
        - llm_call
      user_input:
        message:
          type: string
      workflow:
        - name: get_new_user_message
          type: create_messages
          config:
            message_configs:
              - role: user
                content: user_message
          inputs:
            user_message: message
        - name: add_user_message
          type: insert_messages
          config:
            index: -1
          inputs:
            messages: messages
            new_messages: get_new_user_message.output
        - name: search_generation
          type: tool_generation
          config:
            model: openai/gpt-4o
            tools:
              - name: internal.google_search
              - name: internal.WikipediaSearch
                init_kwargs: {}
          inputs:
            messages: add_user_message.output
        - name: add_tool_and_asst_msgs
          type: processor
          config:
            return_key: concatenate
            function_specs:
              concatenate:
                path: concatenate
                kwargs:
                  list1: list1
                  list2: list2
          inputs:
            list1: add_user_message.output
            list2: search_generation.output
        - name: llm_call
          type: get_message
          config:
            index: -1
          inputs:
            messages: add_tool_and_asst_msgs.output
    write_to_state:
      messages: add_tool_and_asst_msgs
    next_node:

      default: search_chat

Initial state

Messages Initialization: The initial state is set with a system message that specifies the current date, indicating a specific context or time frame for subsequent interactions. This could help in contextualizing queries or managing time-sensitive information.

Starting Node

search_chat: This node is the entry point of the workflow, indicating that the primary interaction focus is related to searching via chat.

Workflow Breakdown

StepNode NameTypePurpose
1get_new_user_messagecreate_messagesTakes in the user input as a message
2add_user_messageinsert_messagesAdds user messge to the messages in the state
3search_generationtool_generationPerforms search with concatenated messages
4add_tool_and_asst_msgsprocessorCombines the user message with the search results
4llm_callget_messageGenerates the best answer
  1. Get New User Message:
    • Create User Message: A node to take user input (the message) and convert it into a structured message object with the role “user.”
  2. Insert User Message:
    • Update Messages: Appends the newly created user message to the list of messages. This helps in maintaining context across interactions and forms part of the dialogue history.
  3. Search Generation:
    • Tool Generation: Uses tool_generation to perform searches using two tools:
      • Internal Google Search.
      • Internal Wikipedia Search.
    • This involves generating completion candidates that best match user queries by leveraging these search tools.
  4. Concatenate Messages:
    • Combine Message List: A processor node is used to concatenate outputs from the user message and tool-generated search results, combining them into a single message list (add_tool_and_asst_msgs).
    • The concatenate function merges these lists together.
  5. Retrieve Latest Message:
    • Get Latest Output: This node extracts the most recent message from add_tool_and_asst_msgs, indicating that it could be looking to retrieve the most relevant or recent piece of information for further processing or output.

State Updates and Transition

  • State Writing: Updates the messages in the state with the concatenated messages, ensuring the state carries forward the full conversation context, including the latest tool responses.
  • Next Node: The default path loops back to search_chat, suggesting a continuous interaction model where the workflow keeps iterating over user input and generating responses through searches.
  • Iterative Search Chat Mechanism: The setup is designed to handle chat interactions focused on searching, continuously updating the conversation context with new information via tool invocations.
  • Tool Flexibility: The use of tools within search_generation allows for dynamic query handling and response generation, which enhances the adaptability of chatbot responses based on external data.
  • Message Management: The process keeps track of the dialogue and ensures that every tool-generated message is integrated into the conversation, indicative of a system trying to enrich the dialogue with relevant information.