Overview
The Lucidic TypeScript SDK provides a comprehensive set of functions to track, monitor, and analyze AI agent workflows. These functions handle session management, step tracking, event logging, and integration with various LLM providers.Installation
Quick Start
Session Management
init
Initialize the SDK and optionally create a session
Session Context
Async-safe session context for concurrent backends
updateSession
Update session metadata
endSession
End the current session
Step Management
createStep
Create a new step in the workflow
updateStep
Update an existing step
endStep
End the current step
Event Management
Advanced Features
Function Categories
Session Lifecycle
- Initialization: Use
init()
to initialize SDK and optionally start a session - Continuation: To resume an existing session, call
init({ sessionId })
- Updates: Modify session data with
updateSession()
- Completion: End with
endSession()
including success status
Step Management
- Creation: Use
createStep()
to begin tracking a unit of work - Updates: Update step data with
updateStep()
- Completion: Finish with
endStep()
including evaluation - Self-contained tasks: Prefer
withLucidic
for workflows that should end automatically (see Session Context)
Event Tracking
- Automatic: LLM calls through instrumented providers create events automatically
- Manual: Use
createEvent()
for custom events - Updates: Modify events with
updateEvent()
Utilities
- Prompts: Centralized prompt management with
getPrompt()
- Context: Async-safe session scoping via
withSession
,withLucidic
,setActiveSession
,clearActiveSession
Provider Support
The SDK instruments providers viainstrumentModules
in init()
:
- OpenAI -
instrumentModules: { OpenAI }
- Anthropic -
instrumentModules: { anthropic: Anthropic }
- LangChain -
instrumentModules: { langchain: LangChain }
Key Differences from Python SDK
- Async by Default: All functions return Promises and must be awaited
- Import Order: Providers must be imported AFTER
init()
for instrumentation - Named Parameters: Functions use object parameters for better TypeScript support
- No Decorators: Function-based API only (decorators exist but not recommended)
Best Practices
- Prefer withLucidic for self-sufficient workflows: It handles init → context → end automatically
- Always Initialize First: Call
await lai.init()
before any other operations - Import Order Matters: Import LLM providers AFTER initialization
- Use Named Parameters: TypeScript’s object syntax provides better IDE support
- Handle Promises: Always await async operations or handle Promise chains
- Type Safety: Leverage TypeScript’s type system for better development experience
Error Handling
Environment Variables
LUCIDIC_API_KEY
- Your API key for authenticationLUCIDIC_AGENT_ID
- Your agent identifier