Maven is an AI-powered product assistant designed to streamline the process of researching, selecting, and comparingElectroniccategorized products. This document details the complete yet simple operational workflow of Maven, from the initial user interaction to the delivery of AI-powered results.
The workflow begins when a user interacts with Maven, providing input through one of several methods.
The user enters a text-based query or request (e.g., “find me the best noise-canceling headphones“).
The user attaches a product (represented by its ID, title, and link) to the conversation.
The user requests a comparison between two products (identified by their call IDs).
The user responds to a previous inquiry from Maven, providing additional information.
1export type PayloadData = {
2 textInput?: string;
3 attachProduct?: AttachProduct;
4 productCompare?: ProductCompare;
5 inquiryResponse?: InquiryResponse;
6};
The PayloadData is passed to the orchestrator function, the central control unit that manages the workflow.
The user‘s input is converted into a standardized UserContentMessage and then into a MessageProperty object, adding it to the conversation history.
The orchestrator analyzes the user's input to determine their intent (e.g., search for a product, get product details, compare products).
Based on the intent, the orchestrator selects the most appropriate agent tool(s) from the available options.
The orchestrator interacts with MutableAIState to update the conversation history and manage the AI's state.
1export const AvailableTools = {
2 SEARCH_PRODUCT: "searchProduct",
3 GET_PRODUCT_DETAILS: "getProductDetails",
4 PRODUCTS_COMPARISON: "productsComparison",
5 INQUIRE_USER: "inquireUser",
6 RECOMMENDATOR: "recommendator",
7} as const;
The selected agent tool(s) are executed. Each tool performs a specific task, leveraging AI models and external APIs.
After a tool completes, mutateTool is called to update the AI state with the results.
Uses validateArgs and validateResult from ToolMutationConfig to validate input/output.
Uses transformResult to transform output before storing in the AI state.
Updates MutableAIState with tool results and generated messages.
If provided, updates the AI state with the given content.
1export type MutationPayload<ARGS, DATA> = {
2 name: AvailableTool;
3 args: ARGS;
4 result: DATA;
5 overrideAssistant?: {
6 content: string;
7 };
8};
The streamUI function generates UI components based on the AI's state.
AssistantMessage
ProductSearch
ProductDetails
ProductComparison
RecommendationAction
UserInquiry
RelatedMessage
ErrorMessage
1export type UIState = {
2 id: string;
3 display: ReactNode;
4}[];
Error handling is implemented throughout the workflow to ensure robustness.
handleScrapingWithCache handles web scraping errors.
Errors from external API calls are caught.
Errors during text/object generation are caught.
Errors accessing the database are handled.
inputInquirySchema and validation functions handle invalid input.
1export type StreamGeneration = {
2 loading: boolean;
3 process:
4 "initial"
5 | "generating"
6 | "api_success"
7 | "api_error"
8 | "database_error"
9 | "fatal_error"
10 | "done"
11 | ({} & string);
12 error?: string;
13};
The final output is the updated UI, presented to the user. This reflects the AI agent's processing, including generated text, product information, comparisons, recommendations, or inquiries. The user can then continue the interaction.
The user can now view the results and continue the interaction, starting a new workflow cycle.
This document provides a simple, technical overview of Maven's workflow. By combining user input, AI-powered tools, state management, and dynamic UI generation, Maven delivers a powerful product research experience. The modular design ensures robustness and maintainability.