from langchain.agents import create_agentdef send_email(to: str, subject: str, body: str): """Send an email to a recipient.""" # ... email sending logic return f"Email sent to {to}"def search_web(query: str): """Search the web for information.""" # ... web search logic return f"Search results for: {query}"agent = create_agent( model="openai:gpt-4o", tools=[send_email, search_web], prompt="You are a helpful assistant that can send emails and search the web.")# Run the agent - all steps will be traced automaticallyresponse = agent.invoke({ "messages": [{"role": "user", "content": "Search for the latest AI news and email a summary to [email protected]"}]})
import langsmith as ls# This WILL be tracedwith ls.tracing_context(enabled=True): agent.invoke({"messages": [{"role": "user", "content": "Send a test email to [email protected]"}]})# This will NOT be traced (if LANGSMITH_TRACING is not set)agent.invoke({"messages": [{"role": "user", "content": "Send another email"}]})