Braintrust tracing provider for agents.
- TypeScript 100%
|
|
||
|---|---|---|
| src | ||
| .gitignore | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
@fractal-synapse/braintrust-tracer
Braintrust tracing provider for Fractal Synapse agents. This package enables automatic tracing and monitoring of AI agent interactions using Braintrust.
Features
- Automatic Model Wrapping: Wraps AI SDK models with Braintrust tracing
- Request/Response Logging: Captures all model interactions
- Performance Metrics: Tracks execution time and token usage
- Error Monitoring: Logs and tracks errors in model calls
- Tool Call Tracing: Monitors AI agent tool executions
Installation
npm install @fractal-synapse/braintrust-tracer braintrust
Usage
Basic Setup
import { BraintrustProvider } from '@fractal-synapse/braintrust-tracer';
import { modelRegistry } from '@fractal-synapse/agent-core';
// Initialize the Braintrust provider
const braintrustProvider = new BraintrustProvider(
process.env.BRAINTRUST_API_KEY!,
'my-project-name'
);
// Apply tracing to all registered models
modelRegistry.applyTracing(braintrustProvider);
Environment Variables
Make sure to set the following environment variables:
BRAINTRUST_API_KEY=your_braintrust_api_key_here
Integration with Agents
When used with Fractal Synapse agents, all model calls will be automatically traced:
// All these calls will be traced
const response = await modelRegistry.getModel('openai-gpt-4o').generateText({
messages: [{ role: 'user', content: 'Hello!' }]
});
API Reference
BraintrustProvider
Constructor
new BraintrustProvider(apiKey: string, projectName: string)
apiKey: Your Braintrust API keyprojectName: Name of your Braintrust project for organizing traces
Methods
wrapModel(model: any): any
Wraps an AI SDK model with Braintrust tracing capabilities.
model: The AI SDK model to wrap- Returns: The wrapped model with tracing enabled
Requirements
- Node.js 16+
- Valid Braintrust API key
- AI SDK compatible models
License
MIT