@egain/ai-agent-sdk API Reference - v0.3.2 / AiAgentConfig
Interface: AiAgentConfig
Configuration options for creating an AiAgent instance.
Example
const config: AiAgentConfig = {
id: "123-456-789",
endpoint: "https://api.egain.com",
auth: { type: "pre-auth", accessToken: "your-access-token" },
autoConnect: true,
logLevel: LogLevel.DEBUG
};Table of contents
Properties
- id
- endpoint
- auth
- autoConnect
- maxQueueSize
- maxReconnectAttempts
- baseReconnectDelay
- maxReconnectDelay
- logger
- logLevel
- enableLogging
- transcriptConfig
- cache
- sessionId
- initParams
- context
- connector
- authScheme
Properties
id
• id: string
Agent ID
Defined in
endpoint
• endpoint: string
WebSocket endpoint URL
Defined in
auth
• Optional auth: AuthenticationInput
Authentication configuration (optional) Can be:
- AuthenticationServiceConfig: Configuration object (e.g., { type: 'pre-auth', accessToken: '...' })
- AuthProvider: Custom auth provider implementing getToken()
- AuthStrategy: Full authentication strategy with lifecycle
- undefined: Falls back to anonymous authentication
Defined in
autoConnect
• Optional autoConnect: boolean
Automatically connect after initialize() completes
Default
falseDefined in
maxQueueSize
• Optional maxQueueSize: number
Maximum queue size
Default
1000Defined in
maxReconnectAttempts
• Optional maxReconnectAttempts: number
Maximum reconnection attempts
Default
InfinityDefined in
baseReconnectDelay
• Optional baseReconnectDelay: number
Base reconnection delay in milliseconds
Default
1000Defined in
maxReconnectDelay
• Optional maxReconnectDelay: number
Maximum reconnection delay in milliseconds
Default
30000Defined in
logger
• Optional logger: Logger
Logger instance (optional) If not provided, a new logger instance will be created
Default
undefined (creates new instance)Defined in
logLevel
• Optional logLevel: LogLevel
Logging level for the agent
Default
INFODefined in
enableLogging
• Optional enableLogging: boolean
Enable console output for logs
Default
trueDefined in
transcriptConfig
• Optional transcriptConfig: TranscriptConfig
Transcript configuration (optional) Controls whether and how messages are stored in the transcript
Defined in
cache
• Optional cache: CacheConfig
Cache configuration for API calls (optional) Controls caching of agent details, portal details, and other API responses
Default
{ enabled: true, storageType: 'session', ttl: 300000 }Defined in
sessionId
• Optional sessionId: string | number
Pre-provided session ID (optional) If provided, the SDK will skip fetching sessionId from the network during initialization. Useful when you already have a session ID from a previous session or external source.
Default
undefined (fetches from network)Example
// Use existing sessionId (skips network fetch)
const agent = new AiAgent({
id: "agent-id",
endpoint: "https://api.egain.com",
sessionId: "existing-session-id"
});Defined in
initParams
• Optional initParams: Record<string, string>
Initialization parameters forwarded from the host application. SDK consumers pass them explicitly so the SDK remains URL-agnostic.
The SDK uses specific well-known keys internally:
agentid— when set and Flow A (isDefaultAgentis not"true"), portals are intersected withagentDetails.portals(cc-widget parity)departmentId— optional fallback in Flow B whenagentDetails.departmentIdis missing; prefer agent details from the default agent API (cc-widget parity)portalIds— comma-separated portal IDs; when set, skipsgetMyPortalsand uses minimal portal objectstemplateName— alias for theme short URL template sent asshortUrlTemplateto portalmgr APIsauthType— signals the authentication mode ("user" | "customer")scopes— comma-separated OAuth scopes to request, used exactly as given (no defaults, no agentextraScopes, no platform augmentation). A host-supplied PKCE config's ownscopestake precedence over this.userid— user identifier for portal cache keyingisDefaultAgent— when "true", enables Flow B (agent selection mode)
All other keys are stored and accessible via agent.getInitParams() for use by the consuming application.
Example
initParams: {
agentid: "agent-123",
userid: "user-456",
authType: "user",
isDefaultAgent: "true",
scopes: "knowledge.portalmgr.manage,core.aiservices.read"
}Defined in
context
• Optional context: Record<string, unknown>
Optional initialization context (merged with initialize({ context })). Used for portal/profile auto-select during the portal pipeline and stored for chat reconnect.
Defined in
connector
• Optional connector: AiAgentConnectorConfig
Platform connector script URL and environment label from the host (e.g. cc-widget). When connectorUrl is omitted, the SDK loads from https://apps.egain.services/ using initParams.platform (with test mapped to the standalone connector path).
Defined in
authScheme
• Optional authScheme: "popup" | "redirect"
Authentication scheme for the PKCE flow (login and logout).
- 'popup': Opens a popup window for login / logout (default)
- 'redirect': Redirects the current page to the identity provider
Only applies when the SDK auto-builds PKCE config from deployment info. Ignored when a full PKCEAuthConfig is supplied via config.auth.
Default
'popup'