Chapter 8. Building AI Agents
In Chapter 7, you learned how to compose custom DSPy programs with built-in modules, multimodal types, and chat adapters. You now have a toolkit for building sophisticated LLM pipelines. But here’s the thing: all of those programs follow a path you designed in advance. You decided which module to call, in what order, with what inputs. What happens when you need the AI to figure out the path on its own?
That’s what agents are for. And when I tell other AI engineers I build agents with DSPy, the response is usually “wait, you can do that?” You can, and I think it’s actually easier than the alternatives. The reason most people don’t associate DSPy with agents is that they think of it as a prompt optimization framework from the workflow era of AI. It is that, but the same architecture that makes DSPy great for optimizing prompts––signatures, modules, evaluation, optimizers––also makes it uniquely powerful for building agents.
Unlike every other agent framework, DSPy lets you formally evaluate ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access