Replacing manual prompts with systematic optimization
Serj Smorodinsky, Brett Kennedy

#LLM
#DSPy
#RAG
#Python
#SIMBA
#GEPA
🧩 از پرامپتهای شکننده تا اپلیکیشنهای خودبهبوددهنده با DSPy
💭 «راهنمایی ضروری و آیندهنگر.»
— دهیِی ماوانی، کالج امهرست
📘 توضیح کتاب
⚙️ DSPy، مخفف Declarative Self-improving Python، یک فریمورک نوآورانه برای برنامهنویسی پرامپت است که پرامپتهای دستی شکننده و غیرقابلپیشبینی را با کد پایتون تمیز و ماژولار جایگزین میکنه. این کد مشخص میکنه مدل چه کاری باید انجام بده، ورودیها و قالب پاسخها را تعریف میکنه و معیارهای روشنی برای ارزیابی تعیین میکنه.
🏗️ در کتاب Building LLM Applications with DSPy، سرج اسمورودینسکی و برت کندی روشی نظاممند ارائه میدن تا پرامپتها را بهعنوان اجزای برنامهنویسیشده در نظر بگیری، نه صرفاً رشتههای متنی پراکنده. با این رویکرد، میتونی اپلیکیشنهای پیچیده AI را با همان انسجام ساختاری نرمافزارهای متداول بسازی، مقیاس بدی، نگهداری کنی و بهبود بدی.
🛠️ کتاب از همان صفحه اول عملی است و مسیر یک Workflow حرفهای مهندسی AI را دنبال میکنه؛ از Classifierهای ساده تا سیستمهای پیچیده خلاصهسازی، RAG پیشرفته و سیستمهای Agentic.
💭 سایروس نوروزی، از مشارکتکنندگان DSPy، درباره کتاب میگه: «تمام موضوع را حول یک دیدگاه منسجم شکل میده: برنامهنویسی پرامپت، یک رشته مبتنی بر داده و مشابه یادگیری ماشین است.»
🔄 برای پشتیبانی از این نگاه مهندسی، کتاب چرخه ساخت نسخه پایه → ارزیابی → بهینهسازی را معرفی میکنه؛ چرخهای که حدسوگمان را از طراحی متداول پرامپتها حذف میکنه.
📊 اپلیکیشنهای Production به معیارهای قابلراستیآزمایی و سازگار نیاز دارن؛ معیارهایی که تعیین اونها با پرامپتهای معمولی دشواره. این کتاب ساخت معیارهای ارزیابی سفارشی، راهاندازی اجراکنندههای تست چندریسمانی و کالیبرهکردن پروتکلهای LLM-as-a-Judge را آموزش میده تا دادههای قابلاتکایی برای سنجش عملکرد جمعآوری کنی.
🎯 بهجای انتشار پرامپتها براساس سلیقه یا حدس، اونها را در برابر مجموعههای اعتبارسنجی ساختاریافته Compile و Optimize میکنی. متن معرفی کتاب، برنامههای حاصل را دارای دقت بالاتر، هزینه کمتر و مقاومت چشمگیر در برابر تغییر رفتار مدل زیربنایی توصیف میکنه و این بهبودها را از نظر ریاضی اثباتشده میدونه.
🤖 فصلهای پایانی نشان میدن چطور DSPy را در Pipelineهای کاملاً Agentic به کار بگیری، حافظه مکالمه را یکپارچه کنی و از طریق MCP، Agentها را به محیطهای خارجی متصل کنی.
🚀 این کتاب در ۹ فصل متمرکز، قابلیتهای پیشرفته DSPy v3، از جمله Optimizerهای SIMBA و GEPA را هم معرفی میکنه تا بیشترین عملکرد ممکن را از مدلهای زبانی کوچکتر، ارزانتر و با وزنهای باز به دست بیاری. منبعی ضروری برای برنامهنویسانی که میخوان سیستمهای هوش مصنوعی مولد مقاوم، خودبهبوددهنده و آماده Production بسازن.
✨ آنچه در کتاب میآموزی
🧩 ساخت اپلیکیشنهای ماژولار مبتنی بر LLM با Signatureهای اعلانی در پایتون.
⚡ خودکارسازی بهینهسازی پرامپت با SIMBA و GEPA.
🧪 ساخت توابع سنجش دقیق و تکرارپذیر برای راستیآزمایی خروجیها.
🔗 استقرار سیستمهای RAG چندمرحلهای و Agentهای قابلاعتماد.
👤 این کتاب برای چه کسانیه؟
🎯 این کتاب برای توسعهدهندگان نرمافزار، دانشمندان داده و مهندسان هوش مصنوعی طراحی شده که مهارتهای پایه پایتون را دارن.
📖 فهرست مطالب
فصل ۱. مقدمهای بر برنامهنویسی پرامپت و DSPy
فصل ۲. پرامپتنویسی پایه و DSPy
فصل ۳. طبقهبندی قصد کاربر
فصل ۴. ارزیابی برنامههای DSPy
فصل ۵. بهینهسازی مثالهای پرامپت
فصل ۶. بهینهسازی دستورالعملهای پرامپت
فصل ۷. ماژولهای سفارشی
فصل ۸. خلاصهسازی و توابع سنجش مؤثرتر
فصل ۹. ساخت یک چتبات Agentic مبتنی بر RAG
👥 درباره نویسندگان
👨💻 سرج اسمورودینسکی از مشارکتکنندگان DSPy، دانشمند داده و مهندس هوش مصنوعی است و بیش از ۱۰ سال تجربه ترکیبی در توسعه نرمافزار و علم داده داره. فعالیتهای او شامل NLP برای هوش مصنوعی مکالمهای در خدمات مشتریان، خودکارسازی Workflowهای Agentic و ارزیابی LLMها میشه.
🏢 او تجربه عملی هدایت تیمها برای ساخت چتباتها و سیستمهای مبتنی بر بازیابی و تولید پاسخ برای مشتریان سازمانی را داره. همچنین سیستمهای Agentic و علم داده در محیط Production را در Nebius Academy، با نام پیشین Y-Data School of Data Science، تدریس میکنه.
👨💻 برت کندی دانشمند دادهای با بیش از ۳۰ سال تجربه در توسعه نرمافزار و علم داده است. او در زمینه تشخیص دادههای پرت در حسابرسی مالی، کشف تقلب و تحلیل شبکههای اجتماعی فعالیت کرده و پیشتر هدایت یک تیم پژوهشی متمرکز بر تشخیص دادههای پرت را بر عهده داشته است.
“An essential, forward-looking guide.”
—Dhyey Mavani, Amherst College
DSPy (Declarative Self-improving Python), an innovative framework for prompt programming, replaces fragile and unpredictable manual prompts with clean, modular Python code that declares what a model should do, defines the inputs and response formats, and establishes clear evaluation metrics. In Building LLM Applications with DSPy, authors Serj Smorodinsky and Brett Kennedy present a systematic approach for treating prompts as programmatic artifacts rather than loose text strings, so you can build, scale, maintain, and improve complex AI applications with the structural integrity of traditional software.
Practical from page one, this book mirrors a professional AI engineering workflow, taking you from simple classifiers to complex summarizers, advanced RAG, and agentic systems. Reviewer Cyrus Nouroozi, a DSPy contributor, notes that the book “frames the whole subject around a single coherent thesis: prompt programming is a data-driven discipline analogous to machine learning.” To support its strong focus on prompt programming as an engineering process, the book introduces the baseline —> evaluate —> optimize loop that eliminates the guesswork of traditional prompt design.
Production applications require verifiable, consistent metrics, which are difficult to establish with conventional prompts. This book guides you through constructing custom evaluation metrics, setting up multi-threaded test runners, and calibrating LLM-as-a-judge protocols to gather hard data. Instead of deploying prompts on a whim, you compile and optimize them against structured validation sets. The resulting programs are mathematically proven to be more accurate, more cost-effective, and remarkably resilient to underlying model drift.
The final chapters show you how to build DSPy into fully agentic pipelines, integrating conversation memories, and connecting agents to external environments via MCP. This focused 9-chapter book also introduces cutting-edge DSPy v3 features like SIMBA and GEPA optimizers to squeeze maximum performance out of smaller, cheaper open-weight language models. It is an indispensable resource for any modern programmer wanting to build robust, self-improving, and production-ready generative AI systems.
What's inside
• Build modular LLM applications using declarative Python signatures
• Automate prompt optimization using SIMBA and GEPA
• Construct rigorous, repeatable metric functions to verify outputs
• Deploy reliable, multi-hop RAG systems and agents
About the reader
This book is designed for software developers, data scientists, and AI engineers with basic Python skills.
Table of Contents
1. Introduction to prompt programming and DSPy
2. Basic prompting and DSPy
3. Classifying user intent
4. Evaluating DSPy programs
5. Optimizing prompt examples
6. Optimizing prompt instructions
7. Custom modules
8. Summarization and more effective metric functions
9. Creating an agentic RAG-based chatbot
About the Author
Serj Smorodinsky is a contributor to DSPy, a data scientist, and an AI engineer with over ten years of combined experience in software development and data science. His work spans NLP for customer-service related conversational AI, agentic workflow automation, and LLM evaluation, with hands-on experience leading teams to build chatbots and retrieval-augmented systems for enterprise clients. He also teaches agentic systems and data science in production at Nebius Academy (formerly Y-Data School of Data Science).
Brett Kennedy is a data scientist with over thirty years’ experience in software development and data science. He has worked in outlier detection related to financial auditing, fraud detection, and social media analysis. He previously led a research team focusing on outlier detection.









