Agent Examples
Search Chat App With State
Build a Search Chat App With State.
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 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
Step | Node Name | Type | Purpose |
---|---|---|---|
1 | get_new_user_message | create_messages | Takes in the user input as a message |
2 | add_user_message | insert_messages | Adds user messge to the messages in the state |
3 | search_generation | tool_generation | Performs search with concatenated messages |
4 | add_tool_and_asst_msgs | processor | Combines the user message with the search results |
4 | llm_call | get_message | Generates the best answer |
- 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.”
- 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.
- 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.
- Tool Generation: Uses tool_generation to perform searches using two tools:
- 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.
- 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.
Workflow Benefits over Simple Search
- 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.