Overview
The Agent module provides an interface to Constructor.io’s AI Agent service through Server-Sent Events (SSE). It allows you to retrieve streaming responses based on user intents, enabling real-time conversational search experiences. This module replaces the previous Assistant module and provides enhanced functionality for intent-based recommendations.Accessing the Agent Module
The Agent module is accessible via theagent property on the Constructor.io client instance:
Event Types
The Agent module provides several event types that can be emitted during a streaming response:Static property containing all possible event types that may be emitted during an agent response stream.
Denotes the start of the stream
Represents a semantic grouping of search results, optionally having textual explanation
Represents a set of results with metadata (used to show results with search refinements)
Represents a set of content with metadata
Represents recipes’ auxiliary information like cooking times & serving sizes
Represents recipe instructions
Server Error event
Event type used for enhancing recommendations with media content such as images
Represents the end of data stream
Example: Accessing Event Types
Methods
getAgentResultsStream
Retrieve a stream of agent results based on user intent
Common Use Cases
Basic Intent-Based Search
Handling Specific Event Types
Error Handling
Notes
- The Agent module uses Server-Sent Events (SSE) to provide real-time streaming responses
- All events are delivered through a
ReadableStreamthat can be consumed using the Streams API - The stream automatically closes when the
ENDevent is received - Always handle potential errors by checking for
server_errorevent types - The
domainparameter is required for all agent requests