{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"TypeScript AI Agent SDK","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"typescript-ai-agent-sdk","__idx":0},"children":["TypeScript AI Agent SDK"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["@egain/ai-agent-sdk"]}," package is a TypeScript-first SDK for embedding eGain AI Agent conversations in browser and Node.js applications. It provides WebSocket communication, authentication helpers, typed events, reconnection, message queuing, transcript handling, and context persistence."]},{"$$mdtype":"Tag","name":"div","attributes":{"style":{"padding":"16px 0","marginBottom":"24px"}},"children":[{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://github.com/eGain/ai-agent-sdk","target":"_blank","rel":"noopener noreferrer","className":"github-card","style":{"display":"inline-flex","alignItems":"center","gap":"12px","padding":"12px 24px","border":"1px solid #d1d5db","borderRadius":"8px","backgroundColor":"#fff","color":"#374151","textDecoration":"none","fontSize":"14px","fontWeight":"500"}},"children":[{"$$mdtype":"Tag","name":"svg","attributes":{"width":"20","height":"20","fill":"currentColor","viewbox":"0 0 20 20","xmlns":"http://www.w3.org/2000/svg"},"children":[{"$$mdtype":"Tag","name":"path","attributes":{"fillRule":"evenodd","d":"M10 0C4.477 0 0 4.484 0 10.017c0 4.425 2.865 8.18 6.839 9.504.5.092.682-.217.682-.483 0-.237-.008-.868-.013-1.703-2.782.605-3.369-1.343-3.369-1.343-.454-1.158-1.11-1.466-1.11-1.466-.908-.62.069-.608.069-.608 1.003.07 1.531 1.032 1.531 1.032.892 1.53 2.341 1.088 2.91.832.092-.647.35-1.088.636-1.338-2.22-.253-4.555-1.113-4.555-4.951 0-1.093.39-1.988 1.029-2.688-.103-.253-.446-1.272.098-2.65 0 0 .84-.27 2.75 1.026A9.564 9.564 0 0110 4.844c.85.004 1.705.115 2.504.337 1.909-1.296 2.747-1.027 2.747-1.027.546 1.379.203 2.398.1 2.651.64.7 1.028 1.595 1.028 2.688 0 3.848-2.339 4.695-4.566 4.942.359.31.678.921.678 1.856 0 1.338-.012 2.419-.012 2.747 0 .268.18.58.688.482A10.019 10.019 0 0020 10.017C20 4.484 15.522 0 10 0z","clipRule":"evenodd"},"children":[]}]},"\n    View on GitHub\n  "]},{"$$mdtype":"Tag","name":"a","attributes":{"href":"https://egain.github.io/ai-agent-sdk/","target":"_blank","rel":"noopener noreferrer","className":"github-card","style":{"display":"inline-flex","alignItems":"center","gap":"12px","marginLeft":"24px","padding":"12px 24px","border":"1px solid #d1d5db","borderRadius":"8px","backgroundColor":"#fff","color":"#374151","textDecoration":"none","fontSize":"14px","fontWeight":"500"}},"children":[{"$$mdtype":"Tag","name":"svg","attributes":{"xmlns":"http://www.w3.org/2000/svg","width":"24","height":"24","viewbox":"0 0 24 24","fill":"none","stroke":"currentColor","strokeWidth":"2","strokeLinecap":"round","strokeLinejoin":"round"},"children":[{"$$mdtype":"Tag","name":"path","attributes":{"d":"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z"},"children":[]},{"$$mdtype":"Tag","name":"path","attributes":{"d":"M14 2v5a1 1 0 0 0 1 1h5"},"children":[]},{"$$mdtype":"Tag","name":"path","attributes":{"d":"M10 9H8"},"children":[]},{"$$mdtype":"Tag","name":"path","attributes":{"d":"M16 13H8"},"children":[]},{"$$mdtype":"Tag","name":"path","attributes":{"d":"M16 17H8"},"children":[]}]},"\n    View Documentation\n  "]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"sdk-installation","__idx":1},"children":["SDK Installation"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"bash","header":{"controls":{"copy":{}}},"source":"npm install @egain/ai-agent-sdk\n","lang":"bash"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["This package includes TypeScript definitions and supports modern browser builds and Node.js integrations."]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"example-usage","__idx":2},"children":["Example Usage"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"typescript","header":{"controls":{"copy":{}}},"source":"import { AiAgent } from \"@egain/ai-agent-sdk\";\n\nconst agent = new AiAgent({\n  id: \"your-agent-id\",\n  endpoint: \"https://your-endpoint.com\",\n  auth: { type: \"pre-auth\", accessToken: \"your-access-token\" },\n  autoConnect: true\n});\n\nawait agent.initialize();\n\nagent.on(\"agentMessage\", (event) => {\n  console.log(\"Agent:\", event.payload.message?.content);\n});\n\nawait agent.send(\"Hello, agent!\");\n","lang":"typescript"},"children":[]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"key-capabilities","__idx":3},"children":["Key Capabilities"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Real-time bidirectional messaging over WebSocket."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Anonymous, pre-authenticated, PKCE, and client credentials authentication strategies."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Automatic reconnection with offline message queuing."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Strongly typed events and message payloads."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Transcript storage, filtering, serialization, and export support."]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Context caching and restoration across reconnects."]}]}]},"headings":[{"value":"TypeScript AI Agent SDK","id":"typescript-ai-agent-sdk","depth":1},{"value":"SDK Installation","id":"sdk-installation","depth":2},{"value":"Example Usage","id":"example-usage","depth":2},{"value":"Key Capabilities","id":"key-capabilities","depth":2}],"frontmatter":{"seo":{"title":"TypeScript AI Agent SDK"}},"lastModified":"2026-05-01T23:48:30.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/developer-portal/sdks/ai-agent-sdk-overview","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}