Building agents using Mellea.
Definition: An agent is a generative program in which an LLM determines the control flow of the program.In the generative programs we have seen so far, the developer orchestrates a sequence of LLM calls. In contrast, agentic generative programs delegate control flow to the model itself. In this chapter we will see a couple of different ways of developing agents in Mellea:
GenerativeSlot
components can be composed by introducing compositionality contracts. We will now build an “agentic” mechanism for automating the task of chaining together possibly-composable generative functions. Let’s get started on our guarded nondeterminism agent (“guarded nondeterminism” is a bit of a mouthful, so we’ll call this a a Kripke agent going forward).
The first step is to add a new Component
that adds preconditions and postconditions to generative slots:
Requirement
component throughout, so we now have all the power of Mellea requirement validation semantics at our disposal for defining and checking pre/post-conditions.
We are now ready to provide the stump of our kripke agent:
filter_actions
. The basic idea is simple: select only actions whose preconditions are implied by the current state: