import { createAgent } from "@langchain/agents";function sendEmail(to: string, subject: string, body: string): string { // ... email sending logic return `Email sent to ${to}`;}function searchWeb(query: string): string { // ... web search logic return `Search results for: ${query}`;}const agent = createAgent({ model: "gpt-5.4", tools: [sendEmail, searchWeb], systemPrompt: "You are a helpful assistant that can send emails and search the web."});// Run the agent - all steps will be traced automaticallyconst response = await agent.invoke({ messages: [{ role: "user", content: "Search for the latest AI news and email a summary to john@example.com" }]});
import { LangChainTracer } from "@langchain/core/tracers/tracer_langchain";// This WILL be tracedconst tracer = new LangChainTracer();await agent.invoke( { messages: [{role: "user", content: "Send a test email to alice@example.com"}] }, { callbacks: [tracer] });// This will NOT be traced (if LANGSMITH_TRACING is not set)await agent.invoke( { messages: [{role: "user", content: "Send another email"}] });