Official JavaScript/TypeScript SDK for the Execlave AI agent governance platform.
Framework integrations — drop-in handlers for LangChain, the OpenAI Agents SDK, CrewAI, the OpenAI Chat Completions API, and the Model Context Protocol, or see all integrations. Get an API key.
npm install @execlave/sdkimport { Execlave, AgentPausedError, PolicyBlockedError } from '@execlave/sdk';
// Initialize the SDK
const ag = new Execlave({
apiKey: 'exe_prod_xxx', // or set EXECLAVE_API_KEY env var
environment: 'production',
});
// Register your agent (idempotent — call on startup)
const agent = await ag.registerAgent({
agentId: 'my-chatbot',
name: 'Customer Support Bot',
type: 'chatbot',
platform: 'custom',
});
// Canonical pattern: enforce policies BEFORE the LLM call, then trace it.
async function handleMessage(userQuestion: string) {
const trace = ag.startTrace({ agentId: 'my-chatbot', sessionId: 'sess_123' });
trace.setInput(userQuestion);
try {
// Pre-execution enforcement is SYNCHRONOUS and MUST run before the LLM call.
// Throws PolicyBlockedError if a block-mode policy (e.g. prompt injection) fires.
await ag.enforcePolicy({ agentId: 'my-chatbot', input: userQuestion });
const answer = await llm.call(userQuestion);
trace.setOutput(answer).setModel('gpt-4-turbo').setTokens(150, 300).setCost(0.012).finish();
return answer;
} catch (err) {
if (err instanceof PolicyBlockedError) {
trace.setOutput('[BLOCKED BY POLICY]').finish('error', err.message);
return 'Your input was blocked by our content policies.';
}
if (err instanceof AgentPausedError) {
trace.finish('error', err.message);
return 'Service temporarily unavailable.';
}
trace.finish('error', String(err));
throw err;
}
}
// Prompt management
const version = await agent.deployPrompt({
promptTemplate: 'You are a helpful assistant. Answer: {question}',
systemMessage: 'Be concise.',
modelName: 'gpt-4-turbo',
changeSummary: 'Improved conciseness',
});
// Graceful shutdown (flushes remaining traces)
await ag.shutdown();Important: tracing alone does NOT block LLM calls. Trace ingestion creates incidents post-hoc. To block requests before they reach the LLM, you MUST call
ag.enforcePolicy()and handlePolicyBlockedErroras shown above. TheenableInjectionScanoption only tags traces with an injection score — it does not block.
| Option | Type | Default | Description |
|---|---|---|---|
apiKey |
string |
EXECLAVE_API_KEY env |
API key (exe_prod_xxx) |
baseUrl |
string |
https://api.execlave.com |
Execlave API URL |
environment |
string |
production |
Deployment environment |
asyncMode |
boolean |
true |
Buffer traces for background flush |
batchSize |
number |
100 |
Max traces per flush batch |
flushIntervalMs |
number |
10000 |
Background flush interval |
debug |
boolean |
false |
Enable debug logging |
enableControlChannel |
boolean |
true |
Poll agent status for kill-switch |
pollIntervalMs |
number |
15000 |
Status poll interval |
enableInjectionScan |
boolean |
true |
Client-side injection scoring; tags traces with metadata. Does NOT block LLM calls — use a block-mode injection policy + enforcePolicy() to block. |
enforcementOnOutage |
string |
fail_open |
Behavior when enforcement API is unreachable: fail_open allows the call, fail_closed raises EnforcementUnavailableError. |
policyCacheTtlMs |
number |
60000 |
TTL for cached policy decisions |
ping()— Check API connectivityregisterAgent(opts)— Register an AI agent. Accepts an optionalautonomyLevel('observe' | 'advise' | 'act_with_approval' | 'autonomous') that maps the agent onto a tiered-governance template.reportAgentMetadata(opts)— Record a version snapshot in the agent registry (versionLabel,gitCommit,deployedAt,notes,activate). Optional; call from your deploy pipeline on each release to build a version history for diff/rollback.enforcePolicy(opts)— Synchronous pre-execution policy check. Call this BEFORE every LLM invocation. ThrowsPolicyBlockedErroron a block-mode violation (ValidatorDeniedErrorwhen the denial came from a Custom Validator),AgentPausedErrorif the agent is kill-switched,EnforcementUnavailableErroronly when configuredfail_closed.opts:{ agentId, input, model?, metadata? }startTrace(opts)— Start a manual trace (post-hoc; does not block)wrap(fn, opts)— Wrap a function with automatic tracingcheckAgentStatus(agentId?)— Get agent statusflush()— Flush buffered tracesshutdown()— Flush and shut down
PolicyBlockedError— A block-mode policy fired. Has aviolations: PolicyViolation[]field withpolicyType,policyName,severity,message,enforcementMode.ValidatorDeniedError— ExtendsPolicyBlockedError; raised when the denial originated from a Custom Validator (BYOV). Existingcatch (err instanceof PolicyBlockedError)blocks keep working.AgentPausedError— Agent is kill-switched.EnforcementUnavailableError— Enforcement API unreachable ANDenforcementOnOutage: 'fail_closed'.
deployPrompt(opts)— Deploy a new prompt versiongetCurrentPrompt()— Get the deployed promptlistPromptVersions()— List all versionsrefreshStatus()— Refresh agent statusisPaused— Whether agent is kill-switched
setInput(data)— Set input data (chainable)setOutput(data)— Set output data (chainable)setModel(name)— Set model name (chainable)setTokens(prompt, completion)— Set token counts (chainable)setCost(usd)— Set cost (chainable)addMetadata(meta)— Add metadata (chainable)finish(status?, error?, errorType?)— Submit the trace
This SDK has zero runtime dependencies. It uses Node.js built-in http/https modules for network requests.
By using this SDK, you agree to the Execlave Terms of Service.
MIT — see LICENSE for details.