3. Prompting for Agent Personas
Giving the agent character and strict instructions. The subtle art of the system prompt in defining operational boundaries.
We have our tools written, and we have our local model running. Now we must fuse them together. We do this by writing the System Prompt. This is the master instruction set that the agent reads before it takes a single action.
A bad system prompt simply says: “You are a research bot. Use your tools to find answers.” This guarantees failure. The agent will not know how to format the tool request, and it will likely just invent an answer instead of searching the web.
Anatomy of a Perfect Agent Prompt
A robust ReAct (Reasoning and Acting) prompt is highly structured. It must include the persona, the available tools, the strict output format, and the stop condition.
You run in a loop of Thought, Action, PAUSE, Observation.
At the end of the loop, you output an Answer.
AVAILABLE TOOLS:
– search_web(query): Searches google for the query.
– read_url(url): Extracts text from a webpage.
– save_file(filename, content): Saves the final report.
INSTRUCTIONS:
1. Use Thought to describe your reasoning.
2. Use Action to run a tool. The action MUST be formatted exactly as JSON: {“tool”: “tool_name”, “args”: {“arg_name”: “value”}}
3. After your Action, you MUST output the word PAUSE and stop generating text.
4. I will then execute the tool and return the Observation to you.
5. When you have enough information, use the save_file tool, and then output your final Answer.
Why the PAUSE is Critical
If you do not instruct the LLM to output the word “PAUSE” and stop generating, it will hallucinate the execution of the tool. It will write the JSON to search the web, and instead of waiting for your Python script to actually execute the search, the LLM will just invent the search results and write the report based on its hallucination.
In our Python loop, we will configure the API call to stop the moment it sees the word “PAUSE”. That is our trigger to take the JSON, run the Python function, and feed the real data back into the context window as an “Observation.”
