← nitronium.dev

DeerFlow uzun araştırmalarda SSE stream değil background run kullan

2026-06-23
DeerFlow'un /runs/stream endpoint'i SSE (Server-Sent Events) ile cevap veriyor. Kısa sorgularda sorun yok, ama subagent'lı araştırmalar 3-10 dakika sürebiliyor. Bu kadar uzun süren stream bağlantıları araç ortamlarında (Multica agent, CI, CLI) kopuyor.

Doğru yaklaşım: /threads/{id}/runs ile background run başlat, /threads/{id}/runs/{run_id} endpoint'ini polling ile kontrol et.

`python
import urllib.request, json, time

LANGGRAPH_URL = "http://localhost:2026/api/langgraph"

Thread oluştur


req = urllib.request.Request(
f"{LANGGRAPH_URL}/threads",
data=json.dumps({}).encode(),
headers={"Content-Type": "application/json"}
)
with urllib.request.urlopen(req) as r:
thread_id = json.loads(r.read())["thread_id"]

Background run başlat (stream değil)


payload = {
"assistant_id": "lead_agent",
"input": {"messages": [{"type": "human", "content": [{"type": "text", "text": "Soru burada"}]}]},
"config": {"recursion_limit": 1000}
}
req = urllib.request.Request(
f"{LANGGRAPH_URL}/threads/{thread_id}/runs",
data=json.dumps(payload).encode(),
headers={"Content-Type": "application/json"}
)
with urllib.request.urlopen(req) as r:
run_id = json.loads(r.read())["run_id"]

Poll


for _ in range(120): # max 10 dk
time.sleep(5)
req = urllib.request.Request(f"{LANGGRAPH_URL}/threads/{thread_id}/runs/{run_id}")
with urllib.request.urlopen(req) as r:
status = json.loads(r.read())["status"]
if status in ("success", "error", "interrupted"):
break
`

Sonuç /threads/{id}/state endpoint'inden alınıyor: values.messages dizisindeki son type: "ai" mesajı.