Ask me anything

Hamburger

Initialization

Create and configure the agent.

Basic

1import Heylock from 'heylock'; 2 3const agent = new Heylock(process.env.HEYLOCK_AGENT_KEY); 4 5agent.onInitialized(success => { 6 if (!success) return console.error('Init failed'); 7 8 console.log('Ready'); 9});

With options

1import Heylock from 'heylock'; 2 3const agent = new Heylock(process.env.HEYLOCK_AGENT_KEY, { 4 useStorage: true, // Persist context in localStorage when in a browser 5 useMessageHistory: false, // Disable message history accumulation 6 suppressWarnings: false, // Hide non-fatal warnings 7 agentId: 'default' // Separate agents when using storage 8}); 9 10agent.onInitialized(success => { 11 if (!success) return console.error('Init failed'); 12 13 console.log('Ready'); 14});

Wait strategies

Choose a pattern based on environment. Avoid blocking loops when waiting for initialization.

1agent.onInitialized(success => { 2 if (!success) { 3 // retry logic, alert, etc. 4 return; 5 } 6 7 console.log('Agent ready'); 8});

Multiple agents

Create agents with different keys or behaviors. Provide distinct agentId if persisting in storage to avoid collisions.

1import Heylock from 'heylock'; 2 3const support = new Heylock(process.env.SUPPORT_AGENT_KEY, { agentId: 'support' }); 4const sales = new Heylock(process.env.SALES_AGENT_KEY, { agentId: 'sales' }); 5 6await Promise.all([ 7 new Promise(resolve => support.onInitialized(resolve)), 8 new Promise(resolve => sales.onInitialized(resolve)) 9]); 10 11console.log('Agents ready');

Error surface

If initialization fails (invalid key, network error) callbacks receive false. You can retry manually or prompt regeneration of the key.

Explore

SDK - Initialization | Heylock