LangGraph Provider

The agentstr.agents.providers.langgraph module provides integration between Agentstr and the LangGraph agent framework. It enables you to use LangGraph graphs as chat agents within the Agentstr SDK, supporting streaming, tool calls, and payment-aware responses.

Overview

The main utility is langgraph_chat_generator(), which adapts a compiled LangGraph graph into an async chat generator compatible with the Agentstr agent interface. This allows you to:

  • Stream agent responses from LangGraph graphs

  • Integrate tool call pricing with NostrMCPClient

  • Use LangGraph as a backend for NostrAgent or NostrAgentServer

Example usage:

from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent

from agentstr import NostrAgentServer, NostrMCPClient, NostrAgent, AgentCard
from agentstr.mcp.providers.langgraph import to_langgraph_tools
from agentstr.agents.providers.langgraph import langgraph_chat_generator

# Note: To run this example, you need the Agentstr LangGraph extra
# pip install agentstr-sdk[langgraph]

# 1. Create react agent
my_langgraph_agent = create_react_agent(
    model=ChatOpenAI(),
    prompt="You are a helpful assistant",
)

# 2. Create LangGraph chat generator
chat_generator = langgraph_chat_generator(my_langgraph_agent, [nostr_mcp_client])

# 3. Create Nostr Agent
nostr_agent = NostrAgent(
    agent_card=AgentCard(name="LangGraphBot", description="An agent powered by LangGraph."),
    chat_generator=chat_generator)

# This `nostr_agent` can now be used with a NostrAgentServer to expose
# the LangGraph agent over the Nostr protocol.

Reference

See Also