While the previous section detailed how to structure prompts for a sequence of operations, the effectiveness of each step, particularly for intricate agent actions, hinges on the precision of the instructions given. An agent might be tasked with actions that are multi-faceted, require conditional execution, or demand outputs in a highly specific format. Without meticulously crafted instructions, the agent's behavior can become unpredictable, leading to errors or suboptimal outcomes. Refining instructions for such complex agent actions is therefore a significant aspect of prompt engineering.
When we refer to a "complex agent action" from an instructional standpoint, we mean any operation where a simple, high-level command is insufficient for reliable execution. This can include:
For these types of actions, vague instructions are a recipe for failure. The agent, powered by an LLM, will attempt to interpret the ambiguity, but its interpretation may not align with the intended goal.
To guide an agent effectively through complex actions, your instructions must be clear, detailed, and unambiguous. Here are several strategies:
General instructions invite general, and often incorrect, results. Be explicit about what the agent needs to do.
For a single, complex action that the agent needs to perform in one turn, break down the instruction into smaller, explicit sub-steps within the prompt itself. This guides the LLM's reasoning process.
Consider an agent tasked with processing customer feedback:
Less Refined Instruction:
Process the attached customer feedback email, identify the main issues, and suggest a solution.
More Refined Instruction (with Action Decomposition):
Your task is to analyze the provided customer feedback email. Follow these steps:
1. **Read and Understand**: Carefully read the entire email content.
2. **Identify Core Issues**: Extract up to three distinct problems or complaints mentioned by the customer. List them clearly.
3. **Sentiment Assessment**: For each identified issue, determine the customer's sentiment (e.g., frustrated, satisfied, confused).
4. **Propose Solutions**: For each issue, suggest one actionable step or solution.
5. **Output Format**: Present your findings as a JSON object with keys: "identified_issues" (an array of objects, each with "issue_summary", "sentiment", and "proposed_solution") and "overall_email_sentiment".
This decomposition guides the agent through a more structured thought process for what is still a single "action" from the workflow's perspective.
Clearly outlining what an agent should do is as important as specifying what it should not do.
Providing these boundaries helps prevent the agent from straying, hallucinating information, or producing outputs in unusable formats.
For complex actions, especially those interacting with tools or other agentic steps, clearly define how the agent should expect input data related to this action and how it must structure its output.
Example:
Action: Perform_Trade
Input: A JSON object with fields: "ticker_symbol" (string), "quantity" (integer), "trade_type" (enum: "BUY" or "SELL").
Output: A JSON object with fields: "transaction_id" (string), "status" (string: "SUCCESS" or "FAILED"), "message" (string, optional error details).
Instruction for the LLM:
You need to execute a trade. I will provide the trade details as:
{ "ticker_symbol": "EXAMPLE", "quantity": 10, "trade_type": "BUY" }
Your response, after attempting the trade (e.g., by calling the relevant tool), should be formatted as:
{ "transaction_id": "...", "status": "...", "message": "..." }
If the ticker_symbol is missing, set status to "FAILED" and message to "Ticker symbol missing."
This level of detail is fundamental when the agent's output becomes another system's input.
Start your instructions with clear, unambiguous action verbs. This helps the LLM focus on the task at hand. Examples:
The impact of refining instructions can be visualized as moving from a state of high ambiguity and potential for diverse, undesirable outcomes to a state of clarity leading to a specific, desired outcome.
The diagram above shows how a vague instruction can lead an agent to multiple, potentially incorrect, outcomes, whereas a refined instruction guides the agent towards a single, desired result.
By investing effort in refining instructions for complex agent actions, you significantly improve the reliability and predictability of your agentic workflows. These precise instructions reduce the likelihood of errors, minimize the need for extensive error handling logic for common misinterpretations, and make the agent's behavior easier to debug and understand. This foundation of clear, actionable instructions is also important when agents need to select and use tools, or execute steps within a larger plan, topics we will address in subsequent chapters.
Was this section helpful?
© 2025 ApX Machine Learning