LangGraph enables you to build complex, stateful agents that can use Observee’s MCP tools. This integration combines LangGraph’s powerful graph-based agent architecture with Observee’s tool ecosystem.
Example: Building a Stateful Agent with Observee Tools
This example demonstrates how to create a LangGraph agent that maintains state across interactions while using Observee tools:
Copy
Ask AI
from langchain_mcp_adapters.client import MultiServerMCPClientfrom langgraph.graph import StateGraph, MessagesState, STARTfrom langgraph.prebuilt import ToolNode, tools_conditionfrom langchain.chat_models import init_chat_model# Initialize the chat modelmodel = init_chat_model("openai:gpt-4")# Configure the MCP client to connect to Observee# Replace {your_client_id} with your actual client ID from the Observee dashboardclient = MultiServerMCPClient( { "observee": { "url": "https://mcp.observee.ai/mcp?client_id={your_client_id}", "transport": "streamable_http", "headers": { "Authorization": "Bearer {observee_api_key}" # Replace with your API key }, } })# Get all available tools from Observeetools = await client.get_tools()# Define the model calling functiondef call_model(state: MessagesState): response = model.bind_tools(tools).invoke(state["messages"]) return {"messages": response}# Build the state graphbuilder = StateGraph(MessagesState)builder.add_node("call_model", call_model)builder.add_node("tools", ToolNode(tools))builder.add_edge(START, "call_model")builder.add_conditional_edges( "call_model", tools_condition,)builder.add_edge("tools", "call_model")# Compile the graphgraph = builder.compile()# Use the agent - it maintains state across interactionsresponse1 = await graph.ainvoke({ "messages": "Check my latest system metrics"})# Follow-up question uses the context from the previous interactionresponse2 = await graph.ainvoke({ "messages": "Based on those metrics, are there any issues I should address?"})