ai-sage-client
v0.0.3
Published
AI Sage Auto-Instrumentation SDK
Downloads
337
Maintainers
Readme
ai-sage-client
The official Node.js SDK for AI Sage Agent APM. Auto-instrument your AI agents to capture logs, LLM calls, tool usage, and execution traces with a single line of code.
Features
- 🔍 Auto-Instrumentation: Automatically captures
console.log,OpenAIcalls, and outboundfetch/httprequests. - 🧵 Context Aware: Uses
AsyncLocalStorageto keep logs isolated across concurrent user sessions. - 🛡️ Active Governance: Validate inputs against policies before execution using
aisage.check(). - ⚡ Zero Config: Just set your API Key and go.
Installation
npm install ai-sage-clientUsage
1. Initialize
Call init() at the start of your application (e.g., inside server.js or app.ts).
import aisage from 'ai-sage-client';
aisage.init({
apiKey: process.env.AISAGE_API_KEY,
// baseUrl: 'https://your-sage-instance.com' // Optional
});2. Wrap Agent Execution
Wrap your agent's entry point with aisage.run(). This establishes the session context.
import aisage from 'ai-sage-client';
async function handleUserRequest(userInput: string) {
return aisage.run('chat_flow', async () => {
// 1. Governance Check (Optional)
const check = await aisage.check(userInput);
if (!check.allowed) {
throw new Error(`Blocked: ${check.reason}`);
}
// 2. Your Agent Logic (Auto-captured!)
console.log('Processing user input:', userInput);
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: userInput }]
});
// 3. Outbound Calls (Auto-captured!)
await fetch('https://api.weather.com/...');
return response.choices[0].message.content;
});
}3. Auto-Instrumentation
To enable OpenAI capture, pass the openai instance:
import OpenAI from 'openai';
const openai = new OpenAI();
// Enable auto-capture
aisage.instrument(openai);Environment Variables
AISAGE_API_KEY: Your Agent API Key from the AI Sage Dashboard.AISAGE_BASE_URL: (Optional) URL of the AI Sage ingestion API.
License
MIT
