Skip to main content

LangGraph ReAct Agent

Build a full ReAct agent that can read conversations, send messages, and search your knowledge base.

import asyncio
from langchain_anthropic import ChatAnthropic
from langgraph.prebuilt import create_react_agent
from dialogbrain import get_langchain_tools

async def main():
llm = ChatAnthropic(model="claude-sonnet-4-6")

async with get_langchain_tools(api_key="db_live_YOUR_KEY") as tools:
agent = create_react_agent(
llm,
tools,
state_modifier=(
"You are a helpful assistant with access to DialogBrain messaging tools. "
"You can read conversations, send messages, search contacts, and more."
),
)

# Example: find and respond to unanswered questions
result = await agent.ainvoke({
"messages": [{
"role": "user",
"content": "Find the last 3 conversations and summarize them"
}]
})
print(result["messages"][-1].content)

asyncio.run(main())

Streaming

async for chunk in agent.astream({"messages": [{"role": "user", "content": "..."}]}):
if "messages" in chunk:
for msg in chunk["messages"]:
if hasattr(msg, "content") and msg.content:
print(msg.content, end="", flush=True)