liveBook · Manning

Prompt engineering

As explained in AI Agents in Action, Second Edition

Prompt engineering is the deliberate design and refinement of instructions and contextual input to elicit desired behavior from a language model.

Prompt engineering is the deliberate design of clear, structured instructions and context so a language model or agent behaves predictably and completes useful work. It is less like asking a specialist a vague question and more like briefing a capable new employee: state the task, constraints, decisions, and desired result without assuming missing background. section 2.2 section 2.2.2

A prompt can describe not only an answer but an executable workflow. It may define a role, select among data sources, call tools, inspect results, make decisions, and consolidate the final output. Clear prompts remain useful even when models provide built-in reasoning, especially for long-horizon tasks or weaker models. section 1.1.2 section 2.2.2

Build prompts progressively by making the agent's job inspectable:

  • Define an explicit persona and audience, such as an internal knowledge search agent serving support engineers. section 2.2.2 section 1.3.1
  • State the task and decision rules, including which source to use and what action follows each result. section 2.2.2
  • Separate variable input with delimiters, then add examples showing the desired decisions and outcomes. section 2.2.2 section 2.5
  • Constrain the response with audience, tone, time, length, and output-format requirements. section 2.2.2 section 2.5
  • Handle failure explicitly: check whether the goal is complete, continue when necessary, and keep reasoning private when requested. section 1.1.2 section 2.2.2

From vague request to controlled workflow

Instead of asking an agent to “find information,” define: “You are an Internal Knowledge Search Agent. Choose internal knowledge base or public web based on the query, search the selected source, and summarize the outcome for support engineers in no more than 120 words.” Add delimited input, examples for each source choice, a three-minute search limit, and a consolidated output rule. The result gives the agent a role, decision boundary, operating constraints, and observable response shape. section 2.2.2

Figure 2.4 A complex workflow showing what a search researcher may perform. The workflow illustrates the tasks an agent may undertake, complete with decision points (circles) and the flow from one task to another. (The figure is overly complex just to demonstrate the workflow.) In the figure, the workflow shows how we want an LLM or agent to perform a series of tasks and consider the output to make decisions based on the results. The workflow details are not critical, and the complexity is used to demonstrate how complex instruction prompts can be constructed by following good prompt engineering practices. (Don’t be alarmed if you can’t follow this figure; it is just a toy example of complexity taken to the extreme.)

Inspect the deliberately complex search-research workflow to see how tasks, decision points, tool use, and result-based branching can be translated into prompt instructions. section 2.2.2

Refinement is iterative rather than purely stylistic. Test the prompt repeatedly, compare outputs, enforce structured schemas, and inspect tool traces when the agent acts unexpectedly. Tight constraints can improve consistency, but loops may end prematurely when handled only through prompting; agents can instead continue until the goal is complete or unattainable. section 2.2.2 section 2.5

How AI Agents in Action, Second Edition covers it

How deep it goes
Moves from instruction principles to complete workflows, examples, constraints, typed outputs, and tracing, while deferring deep model internals.
Examples
Uses a search-agent workflow, source-selection examples, typed research plans, strict length limits, tool calls, repeated runs, and trace inspection.
What it assumes
Assumes only basic task description, while teaching agent roles, workflow prompts, reasoning control, tools, schemas, and validation from foundational concepts.
What you can do after
Apply it via the OpenAI Agents SDK to refine prompts, enforce structured results, add tools, and inspect execution traces.
How it connects
Connects language models with agents, personas, reasoning, planning, tool calls, memory, structured output, and evaluation.

Also explained in

Compare how 38 books explain prompt engineering →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents in Action, Second Edition. The section links point to the parts of the book it draws on.