Appearance
LangChain and LangGraph Monitoring
Monitor LangChain agents and LangGraph graphs using the elsai ARMS callback handler. Add arms.langchain_callback to your graph or agent invocation to automatically track execution, tools, LLM calls, and costs.
SaaS
Agent monitoring on SaaS supports LangChain and LangGraph via arms.langchain_callback. elsai Agents hook integration is available on on-prem deployments only.
Prerequisites
- elsai ARMS installed and configured with
ELSAI_ARMS_API_KEY - LangChain and LangGraph installed
Basic usage
Initialize elsai ARMS
python
from elsai_arms.elsai_arms import ElsaiARMS
arms = ElsaiARMS("Agent_Project")Create your LangGraph
python
from langchain_core.messages import HumanMessage
from langgraph.graph import StateGraph, END
from typing import TypedDict, Annotated
import operator
class State(TypedDict):
messages: Annotated[list, operator.add]
def agent_node(state: State):
return {"messages": [HumanMessage(content="Agent response")]}
graph = StateGraph(State)
graph.add_node("agent", agent_node)
graph.set_entry_point("agent")
graph.add_edge("agent", END)
graph = graph.compile()Invoke with the ARMS callback
python
messages = [HumanMessage(content="What is the weather today?")]
result = graph.invoke(
{"messages": messages},
config={"callbacks": [arms.langchain_callback]}
)Complete example
python
from elsai_arms.elsai_arms import ElsaiARMS
from langchain_core.messages import HumanMessage, AIMessage
from langgraph.graph import StateGraph, END
from typing import TypedDict, Annotated
import operator
arms = ElsaiARMS("Weather_Agent_Project")
class State(TypedDict):
messages: Annotated[list, operator.add]
def weather_agent(state: State):
user_message = state["messages"][-1].content
response = f"Processing weather query: {user_message}"
return {"messages": [AIMessage(content=response)]}
graph = StateGraph(State)
graph.add_node("agent", weather_agent)
graph.set_entry_point("agent")
graph.add_edge("agent", END)
graph = graph.compile()
try:
arms.info("Starting weather agent")
messages = [HumanMessage(content="What's the weather in New York?")]
result = graph.invoke(
{"messages": messages},
config={"callbacks": [arms.langchain_callback]}
)
arms.info("Agent execution completed")
arms.end_run()
print(arms.export())
except Exception as e:
arms.error(f"Agent error: {e}")What gets monitored
When you use the LangChain callback, elsai ARMS automatically tracks:
- Agent execution — start time, end time, duration
- LLM calls — all LLM interactions within the agent
- Token usage — input and output tokens for each LLM call
- Tool calls — tools invoked by the agent
- Cost — estimated cost for all LLM operations
- Performance — latency and throughput metrics
- Errors — any errors during agent execution
Traces are tagged with framework: "langchain" or framework: "langgraph" depending on the execution context.
Advanced usage
Combining with other callbacks
python
from langchain.callbacks import StdOutCallbackHandler
result = graph.invoke(
{"messages": messages},
config={
"callbacks": [
arms.langchain_callback,
StdOutCallbackHandler()
]
}
)Multiple invocations
Each invoke call creates a separate trace when using the callback:
python
step1_result = graph.invoke(
{"messages": messages1},
config={"callbacks": [arms.langchain_callback]}
)
step2_result = graph.invoke(
{"messages": messages2},
config={"callbacks": [arms.langchain_callback]}
)Viewing results
After running your agent:
- Export data — use
arms.export()to get JSON - Cloud dashboard — view traces at arms.elsaifoundry.ai/dashboard
- Review metrics — analyze agent performance, token usage, and costs
Next steps
- User Guide — full monitoring reference
- Tutorial — end-to-end walkthrough
- Configuration — API key setup