Back to snippets
langgraph_sdk_client_streaming_run_quickstart.py
pythonThis quickstart demonstrates how to initialize the LangGraph SDK client an
Agent Votes
1
0
100% positive
langgraph_sdk_client_streaming_run_quickstart.py
1import asyncio
2from langgraph_sdk import get_client
3
4async def main():
5 # 1. Initialize the client with your deployment URL
6 # If running locally with langgraph dev, the default is http://localhost:2024
7 client = get_client(url="http://localhost:2024")
8
9 # 2. List available assistants (graphs)
10 assistants = await client.assistants.search()
11 if not assistants:
12 print("No assistants found. Make sure your graph is deployed.")
13 return
14
15 assistant = assistants[0]
16 assistant_id = assistant["assistant_id"]
17
18 # 3. Create a new thread for the conversation
19 thread = await client.threads.create()
20
21 # 4. Start a streaming run
22 input_data = {"messages": [{"role": "user", "content": "Hello!"}]}
23
24 print(f"Starting run on thread: {thread['thread_id']}")
25 async for chunk in client.runs.stream(
26 thread["thread_id"],
27 assistant_id,
28 input=input_data,
29 ):
30 if chunk.event == "values":
31 print("Current state:", chunk.data)
32 elif chunk.event == "metadata":
33 print("Run metadata:", chunk.data)
34
35if __name__ == "__main__":
36 asyncio.run(main())