การตั้งค่า RD-Agent และ Qlib
Updated 2026-09-06
ตั้งค่า model layer ของ research agent ตรวจ embedding แยกต่างหาก และเตรียม quantitative environment ในเครื่องก่อนเริ่มการทดลองแบบวนซ้ำ
กำหนดความรับผิดชอบของ RD-Agent และ Qlib แยกกัน
ใช้ RD-Agent พัฒนาและแก้ implementation ของงานวิจัย และใช้ Qlib รัน quantitative workflow ที่ตั้งค่าแล้ว model call ของ agent ช่วยเสนอ hypothesis เขียนโค้ด และตีความ feedback Qlib จัดการ data, training และ evaluation ใน experiment environment ดังนั้น model API key แก้ dependency ได้เพียงส่วนเดียว ก่อน setup ให้เลือก RD-Agent scenario ที่แน่นอน pin project revision และกำหนดขอบเขต dataset กับ evaluation วิธีนี้แยก environment preparation ออกจาก research decision ที่ agent จะทำ
ตั้งค่า chat และ embedding ผ่าน backend ตามเอกสาร
ที่ revision 32b3d395 ซึ่งรีวิวแล้ว .env.example ของ RD-Agent อธิบาย LiteLLM backend, chat model และ OpenAI-compatible base พร้อม embedding route ที่เติม proxy prefix แยกกัน shell template ด้านล่าง map model slot ที่ application เป็นเจ้าของเข้า field ตามเอกสาร เลือก chat model ปัจจุบันหลังตรวจ capability แล้ว EMBEDDING_BASE_URL และ EMBEDDING_MODEL_ID ต้องชี้ไปยัง embedding service ที่มีให้ใช้อย่างอิสระ อย่าสมมติว่า chat gateway มี embedding ให้ ส่ง credential ทั้งสองผ่าน environment และใช้ startup command ตามเอกสารของ scenario กับ version ที่ pin
export BACKEND=rdagent.oai.backend.LiteLLMAPIBackend
export OPENAI_API_BASE=https://api.apisrouter.com/v1
export CHAT_MODEL="openai/$RESEARCH_MODEL_ID"
# Set OPENAI_API_KEY securely for the chat endpoint.
export LITELLM_PROXY_API_BASE="$EMBEDDING_BASE_URL"
export EMBEDDING_MODEL="litellm_proxy/$EMBEDDING_MODEL_ID"
# Set LITELLM_PROXY_API_KEY securely for the embedding service.ตรวจ capability ของโมเดลทั้งสองแยกกัน
ตรวจว่า chat client ที่เลือกทำ response format และ tool behavior ตาม scenario ได้ ตรวจ embedding ว่าได้ vector ที่ไม่ว่าง dimension สม่ำเสมอ และ model identity เสถียร การเปลี่ยน embedding model อาจต้องสร้าง vector ที่เก็บไว้อีกครั้ง chat response ที่สำเร็จไม่ได้ validate retrieval diagram ที่มี source รองรับแสดงเฉพาะ chat route ที่เสนอ LiteLLM provider prefix เลือก client behavior และไม่จำเป็นต้องเป็น model ID ที่ endpoint เห็น เก็บทั้งค่าที่ตั้งไว้และ request identity ที่ resolve แล้ว
เตรียม quantitative environment ก่อนเปิด agent loop
ตรวจ dataset, Python environment และ execution container ที่อนุญาตด้วย deterministic check ขนาดเล็ก สำหรับงานวิจัยระหว่างประเทศ ให้ region ของ dataset, market calendar และ instrument universe ตรงกับตลาดเป้าหมาย เอกสาร Qlib workflow รองรับ US region แต่ไม่ควรคัดลอก dataset และ assumption ของตัวอย่างไปใช้กับตลาดอื่นโดยไม่แก้ ตรวจ historical coverage, adjustment policy และ benchmark identity จากนั้นค่อยให้ agent สร้าง candidate code บน environment นี้ มิฉะนั้น model revision ซ้ำๆ อาจเพียงชดเชย data setup ที่เสีย
ตรวจ hypothesis, code และ feedback ไปพร้อมกัน
ภาพประกอบ RD-Agent อย่างเป็นทางการแสดง interface วิจัยแบบวนซ้ำ ใช้โครงสร้างนั้นเตือนให้เก็บ hypothesis ทุกตัวคู่กับ implementation และ feedback แทนการเก็บเฉพาะ final report reviewer ควรแยกได้ว่า agent แก้ software error เปลี่ยน research question หรือเลือก candidate อื่นหลังเห็น score เก็บ experiment ที่ reject ให้เข้าถึงได้ และแยก tool output ออกจากการตีความ output ของ agent

จำกัด code execution และรักษาความเป็นอิสระของ evaluation
รัน code ที่สร้างด้วย filesystem, network และ resource limit ที่ระบุชัด mount เฉพาะ dataset ที่จำเป็น และอย่าเปิด credential ที่ไม่เกี่ยวข้อง ตรึง train, validation และ held-out evaluation window ก่อน iterative development หากส่ง test feedback กลับให้ agent ซ้ำๆ ให้บันทึกว่า test period กลายเป็นส่วนหนึ่งของ development process แล้ว experiment manifest ควรมี source revision, code hash, data version, configuration, environment identity และ selection decision วิธีนี้ทำให้ทั้ง successful execution และ methodological failure มองเห็นได้สำหรับ reviewer ถัดไป
ติดตามต้นทุนและกู้คืน stage ที่ล้มเหลว
เชื่อม chat และ embedding request ledger เข้ากับ local compute ledger ด้วย experiment ID LiteLLM cost estimate ไม่จำเป็นต้องเท่ากับ gateway charge จริง ให้กระทบยอดกับ billing record ที่ใช้ได้ แยก model transport failure, vector-index mismatch, code exception และ Qlib data ที่หายเป็นคนละสถานะ retry call ชั่วคราวภายใต้ budget และเก็บ code error ไว้ตรวจ อย่า restart loop ทั้งหมดเมื่อมีเพียง source artifact หรือ model request เดียวต้องแก้ และ invalidate cache เมื่อ model, code หรือ dataset ที่เกี่ยวข้องเปลี่ยน
หลักฐานและขอบเขต
environment field และ backend behavior ถูกรีวิวใน official source revision 32b3d395 เมื่อ September 5, 2026 Qlib invocation และความรับผิดชอบเป็นไปตามเอกสารทางการ ไม่มี project-client request, embedding result หรือ RD-Agent/Qlib loop ที่ทำครบผ่าน APIsRouter สำหรับคู่มือนี้ acceptance ถัดไปคือ scenario ที่มีขอบเขต พร้อม input, request evidence และ numerical output ที่เก็บไว้
คำถามที่พบบ่อย
Qlib ใช้ OPENAI_API_BASE หรือไม่?
ตัวแปรนี้ตั้งค่า agent model path ที่อธิบายไว้ Qlib เองทำงาน data, model และ evaluation ใน runtime ของตัวเอง
ใช้ embedding provider แยกได้หรือไม่?
template ที่รีวิวระบุ LITELLM_PROXY_API_BASE และ key แยก พร้อม model ที่มี prefix litellm_proxy ตรวจ service ที่เลือกและ vector compatibility แยกกัน
ทำไม chat model มี prefix openai/?
มันเลือก compatible provider ใน LiteLLM ตรวจ resolved request model ID ตอน validate endpoint แทนการสมมติว่า prefix ทุกตัวถูกส่งต่อเหมือนเดิม
chat hello validate research loop ได้หรือไม่?
ไม่ได้ มันทดสอบ client operation เดียว Embedding, retrieval, code execution, Qlib data และ final evaluation ต่างต้องมี observable outcome ของตัวเอง
เมื่อ agent เปลี่ยน code ควรเก็บอะไร?
เก็บ code เดิม code ใหม่ hypothesis feedback และ experiment identity เพื่อให้ reviewer สร้าง search ย้อนกลับและตรวจ evaluation leakage ได้