Agent Wranglers

AIF-1Recommended

Try plain code before a model

Use a language model only for a task that plain code, a search index or a fixed rule cannot do well enough. Write down why.

How to do it

Describe the task in one sentence. Build or sketch the simplest version without a model first. Examples are a regular expression, a lookup table, a keyword search or a fixed form. Measure it on the same examples you will use for the model. Choose the model only when it beats that baseline by a margin you set in advance, such as 10 points of accuracy. Models suit fuzzy language tasks, such as summaries, free-text questions and messy extraction. They suit exact sums, dates, prices and permission checks badly.

Examples

TypeScript example

// A fixed rule handles most order-status questions. The model gets only the rest.
const ORDER_NUMBER = /\b[A-Z]-\d{4,}\b/;

export async function answerSupportQuestion(question: string, user: User) {
  const orderId = ORDER_NUMBER.exec(question)?.[0];
  if (orderId && /\b(where|status|shipped)\b/i.test(question)) return orderStatusReply(orderId, user);
  return assistant.answer(question, user);
}

Python example

ORDER_NUMBER = re.compile(r"\b[A-Z]-\d{4,}\b")

def answer_support_question(question: str, user: User) -> Reply:
    match = ORDER_NUMBER.search(question)
    if match and re.search(r"\b(where|status|shipped)\b", question, re.I):
        return order_status_reply(match.group(0), user)
    return assistant.answer(question, user)

How to check

A CI script finds a decision note for every AI feature in the gateway's prompt list. Each note has a baseline score, a model score on the same eval set and a margin. The script fails when a note or field is missing, or when the model score minus the baseline is under the margin.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/ai-features/deciding-to-use-a-model/model-or-code">Agent Wranglers AI features playbook</a>. In code you write, add a comment next to it with the same link.