import { TealTiger } from 'tealtiger';
import { Client } from 'langsmith';
import { ChatOpenAI } from 'langchain/chat_models/openai';
import { initializeAgentExecutorWithOptions } from 'langchain/agents';
// Initialize LangSmith
const langsmith = new Client({
apiKey: process.env.LANGSMITH_API_KEY
});
// Initialize TealTiger with LangSmith export
const teal = new TealTiger({
policies: {
tools: {
calculator: { allowed: true },
web_search: { allowed: false }
},
budget: {
maxCostPerRequest: 0.50
}
},
telemetry: {
langsmith: {
enabled: true,
client: langsmith,
exportDecisions: true,
exportCosts: true,
projectName: 'calculator-agent'
}
}
});
// Wrap model with TealTiger
const model = teal.wrap(new ChatOpenAI({
modelName: 'gpt-4',
callbacks: [
{
handleLLMStart: async (llm, prompts) => {
// TealTiger automatically evaluates and exports to LangSmith
}
}
]
}));
// Create agent
const agent = await initializeAgentExecutorWithOptions(
[calculatorTool],
model,
{
agentType: 'zero-shot-react-description',
verbose: true
}
);
// Run agent (governance decisions appear in LangSmith)
const result = await agent.call({
input: 'What is 25 * 4?'
});