INFO:langgraph_api.cli: Welcome to╦ ┌─┐┌┐┌┌─┐╔═╗┬─┐┌─┐┌─┐┬ ┬║ ├─┤││││ ┬║ ╦├┬┘├─┤├─┘├─┤╩═╝┴ ┴┘└┘└─┘╚═╝┴└─┴ ┴┴ ┴ ┴- 🚀 API: http://127.0.0.1:2024- 🎨 Studio UI: https://smith.langchain.com/studio/?baseUrl=http://127.0.0.1:2024- 📚 API Docs: http://127.0.0.1:2024/docsThis in-memory server is designed for development and testing.For production use, please use LangSmith Deployment.
langgraph dev 命令会以内存模式启动 Agent Server。该模式适用于开发和测试。用于生产环境时,请部署可访问持久化存储后端的 Agent Server。更多信息,请参阅平台设置概览。
from langgraph_sdk import get_clientimport asyncioclient = get_client(url="http://localhost:2024")async def main(): async for chunk in client.runs.stream( None, # Threadless run "agent", # Name of assistant. Defined in langgraph.json. input={ "messages": [{ "role": "human", "content": "What is LangGraph?", }], }, ): print(f"Receiving new event of type: {chunk.event}...") print(chunk.data) print("\n\n")asyncio.run(main())
安装 LangGraph Python SDK:
pip install langgraph-sdk
向 assistant 发送一条消息(无线程运行):
from langgraph_sdk import get_sync_clientclient = get_sync_client(url="http://localhost:2024")for chunk in client.runs.stream( None, # Threadless run "agent", # Name of assistant. Defined in langgraph.json. input={ "messages": [{ "role": "human", "content": "What is LangGraph?", }], }, stream_mode="messages-tuple",): print(f"Receiving new event of type: {chunk.event}...") print(chunk.data) print("\n\n")