Create a simple LangChain agent that uses Arcbeam tracing:
from langchain.agents import create_agentfrom langchain_openai import ChatOpenAIfrom arcbeam_connector.langchain.connector import ArcbeamLangConnector# Initialize the Arcbeam connectorconnector = ArcbeamLangConnector( base_url="http://platform.arcbeam.ai", # Or your self-hosted URL api_key="your-api-key-here", # Your Arcbeam API key)connector.init()# Create your modelmodel = ChatOpenAI(model="gpt-4o-mini")# Define a simple tooldef get_weather(city: str) -> str: """Get weather for a given city.""" return f"It's always sunny in {city}!"# Create the agent with your toolsagent = create_agent( model=model, tools=[get_weather], system_prompt="You are a helpful assistant",)# Run the agent - this will be automatically traced!result = agent.invoke( {"messages": [{"role": "user", "content": "what is the weather in sf"}]}, config={"callbacks": []})print(result["messages"][-1].content)
Make sure to set your OPENAI_API_KEY environment variable before running this code.
The connector automatically captures all LangChain operations without requiring you to modify your existing code beyond the initialization.