So far, we've mostly been dealing with agents as a setup. An agent is where you've hand full control of your control flow of your application to an LLM. In other words, you give the LLM a bunch of tools and the LLM goes, right, I'll call this tool, then maybe call another tool, and that can produce some mixed results.
It can be extremely good for open-ended tasks, but less good for tasks where you know that one step should always follow another step.
The goal of this exercise is to show you what you can do with a deterministic workflow setup. We're going to use a generator-evaluator workflow where we:
This should give us a better output than just generating a message with a single LLM call.
Here's the structure of the code we'll be working with:
export const POST = async (req: Request): Promise<Response> => {const body: { messages: UIMessage[] } = await req.json();const { messages } = body;const writeSlackResult = TODO; // Write Slack message
All the code you're gonna be writing is inside this POST request. We have an initial writeSlackResult up here, then an evaluateSlackResult where we're gonna take the message from this first one and pass it to the second one, and then finally we have a finalSlackAttempt.
We've been provided with useful system prompts for each step:
const WRITE_SLACK_MESSAGE_FIRST_DRAFT_SYSTEM = `You are writing a Slack message for a user based on the conversation history. Only return the Slack message, no other text.`;const EVALUATE_SLACK_MESSAGE_SYSTEM = `You are evaluating the Slack message produced by the user.Evaluation criteria:- The Slack message should be written in a way that is easy to understand.- It should be appropriate for a professional Slack conversation.`;
We also have a helper function to format the message history:
const formatMessageHistory = (messages: UIMessage[]) => {return messages.map((message) => {return `${message.role}: ${message.parts.map((part) => {if (part.type === 'text'
The final draft will be streamed directly to the frontend, so the user will only see the best attempt so far.
Good luck, and I'll see you in the solution.