Factors 1-4: Structure Prompts, Tools, and Context

Introduction: Taking Control of the LLM Interface

In the previous lesson, we explored why building production-ready AI agents requires engineering discipline, not just better prompts. We identified the 70-80% reliability wall and discovered that the solution lies in applying systematic principles to how we build agent systems.

Now we're ready to get practical. In this lesson, we'll cover the first four factors of the 12-Factor Agents methodology — the foundational principles that establish control over how LLMs interact with your system. These factors form the "input-output layer" of agent reliability, defining what the LLM receives (prompts and context) and what it produces (structured outputs and tool calls). The key shift we're making is moving from hoping the LLM does the right thing to explicitly controlling what it sees and what it can produce.

There's no single "right way" to build agents — the patterns we'll discuss are starting points for experimentation. The goal is to give you the control and flexibility to discover what works for your specific use case. Let's dive in!

Factor 1: Natural Language to Tool Calls

The first factor establishes a fundamental principle: translate natural language into predictable, structured outputs that your system can reliably process.

Here's the LLM's real superpower in agent systems: it can translate natural language intents into structured outputs that your software understands. Instead of generating a narrative response, the LLM can produce a formal structure — typically as JSON or a function call — that your deterministic code can execute.

Let's look at a concrete example. Imagine you're building a payment system agent. A user says:

text
"Create a $10 payment link for Max"

Without Factor 1, you might let the LLM generate a free-form response like this:

"I'll create a payment link for $10 for Max right away. Please wait a moment."

This sounds nice, but it doesn't actually do anything. Your code has to parse this text, figure out what the LLM intended, and hope it mentioned all the necessary details.

With Factor 1, you design the agent to produce structured output instead:

{
  "action": "create_payment_link",
  "amount": 10,
  "recipient": "Max"
}

Now your code can immediately parse this JSON and execute the actual payment link creation. The LLM has translated the user's natural language into a precise, machine-executable command. This approach creates a clean separation of concerns: the LLM decides what needs to be done, while your regular code knows how to do it.

Sign up

Join the 1M+ learners on CodeSignal

Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal