Prompting Strategies and Tips: Role Assignment

Michael BrenndoerferJune 13, 202512 min read

Part of AI Agent Handbook

Covers advanced prompting strategies for AI agents including role assignment, few-shot prompting with examples, and iterative refinement.

Prompting Strategies and Tips

In the previous chapter, you learned that clear, specific instructions help your AI agent understand what you want. But what happens when you need more than just clarity? Sometimes you want the AI to adopt a particular style, or you need it to handle a task it hasn't seen before. That's where prompting strategies come in.

Think of prompting strategies as different ways to frame your request. Just like you might explain something differently to a child versus a colleague, or show someone an example before asking them to try it themselves, you can guide your AI agent in similar ways. These techniques help you get better results without changing the underlying model.

In this chapter, we'll explore practical strategies that make prompting more effective. You'll learn how to give your agent context through roles, how to teach by example, and why treating prompt design as an iterative process leads to better outcomes.

Giving Your Agent a Role

One of the simplest yet most powerful prompting strategies is telling the AI who it should be. When you assign a role, you're giving the model context about how to approach the task. This shapes both what it says and how it says it.

Here's a basic example. If you ask:

Explain photosynthesis.

You'll get a reasonable explanation. But watch what happens when you add a role:

You are a biology teacher explaining concepts to high school students. 
Explain photosynthesis in a way that's easy to understand.

The second version will likely use simpler language, include helpful analogies, and avoid jargon. The role gives the model a framework for how to structure its response.

Why Roles Work

Language models are trained on vast amounts of text, including conversations, articles, and documents where people adopt different roles. When you specify a role, you're essentially activating patterns the model has learned about how that type of person communicates.

A few common roles that work well:

  • Teacher or tutor: Good for explanations that need to be clear and educational
  • Expert consultant: Useful when you want detailed, technical information
  • Friendly assistant: Helps when you want a conversational, approachable tone
  • Critical reviewer: Effective when you need the AI to analyze or critique something

The key is matching the role to your goal. If you want creative brainstorming, you might say "You are a creative director." If you need careful analysis, try "You are a data analyst reviewing this information."

Example (GPT-5)

Let's see how roles change the output. Here's a simple Python example using OpenAI's API:

In[3]:
Code
import os
from openai import OpenAI


## Initialize client with your API key
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))

## Without a role
## GPT-5 excels at basic text generation tasks like explanations
response1 = client.chat.completions.create(
    model="gpt-5",
    messages=[{"role": "user", "content": "Explain machine learning."}],
)

## With a teacher role
response2 = client.chat.completions.create(
    model="gpt-5",
    messages=[
        {
            "role": "system",
            "content": "You are a patient teacher explaining concepts to beginners.",
        },
        {"role": "user", "content": "Explain machine learning."},
    ],
)

print("Without role:", response1.choices[0].message.content)
print("\nWith teacher role:", response2.choices[0].message.content)
Out[3]:
Console
Without role: Machine learning (ML) is the study and practice of building systems that learn patterns from data to make predictions or decisions without being explicitly programmed with fixed rules. In Tom Mitchell’s classic phrasing: a program learns from experience E, on task T, with performance P, if its performance at T improves with experience E.

Why use it
- When rules are too complex to hand-code.
- To generalize from past examples to new, unseen cases.

Main types
- Supervised learning: learn from labeled examples (e.g., predict house prices, classify emails as spam/not spam).
- Unsupervised learning: find structure in unlabeled data (e.g., clustering customers, dimensionality reduction).
- Semi/self-supervised: leverage large unlabeled data with limited or synthetic labels.
- Reinforcement learning: learn actions via trial and error to maximize reward (e.g., game playing, robotics).
- Generative modeling: learn data distributions to generate or model new samples (e.g., text, images, audio).

Core concepts
- Data and features: inputs (and labels for supervised tasks). Data quality dominates outcomes.
- Model: a function with parameters (e.g., linear model, neural network) mapping inputs to outputs.
- Loss/objective: measures error; training minimizes this (e.g., MSE, cross-entropy).
- Optimization: algorithms like gradient descent adjust parameters to reduce loss.
- Generalization: perform well on unseen data; avoid overfitting.
- Regularization and capacity: techniques (L2, dropout, early stopping) to control model complexity.
- Hyperparameters: settings not learned directly (learning rate, depth) tuned via validation.

Typical workflow
1. Define the problem and success metric.
2. Collect and explore data; handle missing values, leakage, and biases.
3. Split data into train/validation/test (or use cross-validation).
4. Engineer features or use representation learning (deep nets).
5. Train baseline models; iterate with tuning and regularization.
6. Evaluate with appropriate metrics (e.g., MAE/MSE/R²; accuracy/precision/recall/F1/ROC-AUC).
7. Deploy, monitor for drift, fairness, and reliability; retrain as needed.

Common algorithms
- Regression/classification: linear and logistic regression, decision trees, random forests, gradient boosting (XGBoost/LightGBM), SVM, k-NN, Naive Bayes.
- Unsupervised: k-means, hierarchical clustering, Gaussian mixtures, PCA/t-SNE/UMAP.
- Deep learning: neural networks (MLP), CNNs for images, RNN/LSTM/Transformers for sequences and language; diffusion and autoregressive models for generation.
- Reinforcement learning: Q-learning, policy gradients, actor-critic.

Applications
- Recommendation, search, fraud detection, forecasting, medical diagnosis, language translation, speech/image recognition, autonomous systems, personalization.

Pitfalls and considerations
- Data leakage and distribution shift.
- Class imbalance and calibration.
- Bias, fairness, and privacy.
- Interpretability vs. accuracy trade-offs.
- Correlation vs. causation; spurious patterns.
- Computational cost and energy.

Quick example
- Spam filter (supervised classification): collect labeled emails, extract features (or use a Transformer), train to minimize classification loss, tune on validation, evaluate with precision/recall, deploy and monitor for new spam tactics.

If you tell me your context (e.g., the kind of data and task), I can suggest a concrete approach and starter models.

With teacher role: Machine learning (ML) is a way of getting computers to learn patterns from data so they can make predictions or decisions without being told exact rules for every situation.

A simple analogy
- Imagine teaching a child to recognize cats. You don’t write a rule like “if it has whiskers and pointy ears, it’s a cat.” Instead, you show lots of pictures labeled “cat” or “not cat.” Over time, the child notices patterns and gets better at telling cats apart. ML works the same way, but with math.

Core ideas in plain terms
- Data: The examples the computer sees. Each example has inputs (features). Sometimes it also has the correct answer (label).
- Model: A flexible set of rules the computer can adjust to fit the data (like knobs it can turn).
- Training: The process of adjusting those knobs so the model’s predictions match the known answers.
- Generalization: Doing well on new, unseen data—not just memorizing the training examples.
- Prediction (inference): Using the trained model to make a guess for new input.

Main types of machine learning
- Supervised learning: Learn from input-output pairs.
  - Classification: Predict categories (spam vs not spam, disease vs no disease).
  - Regression: Predict numbers (house price, temperature).
- Unsupervised learning: Find structure without labels.
  - Clustering: Group similar items (customer segments).
  - Dimensionality reduction: Compress data to its essential factors (visualize high‑dimensional data).
- Reinforcement learning: Learn by trial and error with rewards (game-playing AIs, robot control).

A quick end-to-end example
- Goal: Predict house price.
- Data: For each house, features like size, bedrooms, location; label is the actual sale price.
- Train: Show many examples; the model adjusts to reduce the gap between predicted and real prices.
- Use: For a new house, the model estimates the price based on learned patterns.

Typical workflow
1) Define the problem and what “good” means (metric like accuracy, F1, mean error).
2) Collect data and clean it (handle missing values, fix errors).
3) Split into train/validation/test sets to check generalization.
4) Choose and train a model; tune settings (hyperparameters).
5) Evaluate on validation/test data; fix issues like overfitting.
6) Deploy the model; monitor performance and update as the world changes.

Common algorithms (with one‑line intuition)
- Linear regression/logistic regression: Fit a straight-line relationship; fast and interpretable.
- Decision trees and random forests: If‑then rules learned from data; handle mixed features well.
- Gradient boosting (e.g., XGBoost, LightGBM): Many small trees combined; often top tabular performers.
- k‑nearest neighbors: Look at the most similar past examples to vote on the answer.
- Support vector machines: Find a boundary that best separates classes.
- Neural networks (deep learning): Stacked layers that learn complex patterns (images, audio, language).

Key challenges and pitfalls
- Overfitting: Model memorizes training data and fails on new data. Fix with more data, simpler models, regularization, or better validation.
- Underfitting: Model too simple to capture real patterns.
- Data leakage: Test information accidentally sneaks into training, giving overly optimistic results.
- Bias and fairness: If training data reflects historical bias, the model can learn and amplify it. Requires careful data design and evaluation.
- Data drift: The world changes; models decay over time and need retraining.
- Data needs and quality: Poor or too little data limits performance more than fancy algorithms.

When to use (and not use) ML
- Use ML when rules are hard to write by hand but examples are available (image recognition, speech, recommendations).
- Prefer simple rules or traditional software when the task is clear-cut, constraints are strict, or explanations are critical and data is scarce.

How ML differs from traditional programming
- Traditional: You give rules + data → outputs.
- ML: You give data + outputs (labels) → the system learns rules to produce outputs for new data.

If you’d like, tell me an area you care about (health, finance, apps, games), and I can walk through a concrete, beginner-friendly example in that context.

Notice how we use the system message to set the role. This tells the model to maintain that persona throughout the conversation. The system message acts like stage directions in a play, setting the scene before the dialogue begins.

Teaching by Example: Few-Shot Prompting

Sometimes the best way to explain what you want is to show examples. This technique, called few-shot prompting, involves giving the AI a few examples of the pattern you want it to follow. The model learns from these examples and applies the same pattern to new inputs.

Think about how you might train someone to format data. Instead of writing detailed rules, you'd probably just show them a few examples: "Here's how the first one should look, here's the second one, now you try the third." Few-shot prompting works the same way.

When to Use Few-Shot Prompting

This strategy shines in several situations:

Pattern matching: When you want the AI to follow a specific format or structure. For example, if you're extracting information from text and want it in a particular layout.

Classification tasks: When you need the AI to categorize things consistently. Show it a few examples of each category, and it will understand the distinctions.

Style matching: When you want the AI to write in a specific style or tone. A few examples help it capture the voice you're looking for.

Complex transformations: When the task involves multiple steps or subtle rules that are easier to demonstrate than explain.

Example (GPT-5)

Here's a practical example where we want the AI to categorize customer feedback as positive, negative, or neutral:

In[4]:
Code
import os
from openai import OpenAI


client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))

## Few-shot prompt with examples
## GPT-5 handles pattern matching tasks like classification well
prompt = """Categorize the following customer feedback as positive, negative, or neutral.

Examples:
Feedback: "The product arrived quickly and works great!"
Category: positive

Feedback: "The item was damaged and customer service was unhelpful."
Category: negative

Feedback: "The product is okay, nothing special."
Category: neutral

Now categorize this:
Feedback: "I love the design but wish it had more features."
Category:"""

response = client.chat.completions.create(
    model="gpt-5", messages=[{"role": "user", "content": prompt}]
)

print(response.choices[0].message.content)
Out[4]:
Console
Category: neutral

The model sees the pattern in the examples and applies it to the new feedback. It learns that positive feedback includes praise, negative includes complaints, and neutral is somewhere in between. Without these examples, the model might struggle with mixed feedback like "I love the design but wish it had more features."

How Many Examples Do You Need?

The name "few-shot" is literal. You typically need between 2 and 5 examples. More than that rarely helps and makes your prompt longer (which can slow things down and cost more). Start with 2-3 examples and add more only if the results aren't consistent.

Also, make sure your examples are diverse. If you're teaching the AI to categorize feedback, include examples that cover different types of positive, negative, and neutral responses. This helps the model generalize better.

Iteration: Your Secret Weapon

Here's something that might surprise you: even experienced practitioners rarely get the perfect prompt on the first try. Prompting is an iterative process. You start with something reasonable, see what happens, and then refine based on the results.

This isn't a flaw in the system. It's actually a feature. Because you can quickly test different prompts and see results, you can rapidly improve your approach. Think of it like adjusting a recipe while cooking. You taste, adjust the seasoning, taste again, and keep refining until it's right.

The Iteration Cycle

Here's a simple process that works well:

  1. Start with a clear, simple prompt: Don't overthink it. Write what you want in plain language.

  2. Run it and examine the output: Does it do what you wanted? Where does it fall short?

  3. Identify the gap: Is the output too vague? Too formal? Missing key information? Getting the format wrong?

  4. Adjust one thing: Add more specificity, include an example, change the role, or modify the instructions. Change one element at a time so you know what made the difference.

  5. Test again: See if the adjustment helped. If not, try a different approach.

Example: Refining a Prompt

Let's walk through a real iteration process. Suppose you're building a feature for your personal assistant to summarize articles.

First attempt:

Summarize this article.

Result: The summary is too long and includes minor details.

Second attempt:

Summarize this article in 3 sentences, focusing on the main points.

Result: Better, but the tone is too formal for your needs.

Third attempt:

You are a friendly assistant helping someone catch up on news. 
Summarize this article in 3 sentences, focusing on the main points. 
Use a conversational tone.

Result: Much better! The summary is concise, focused, and easy to read.

Notice how each iteration addressed a specific issue. We didn't try to fix everything at once. This methodical approach helps you understand what works and why.

Example (GPT-5)

Here's how you might implement this iteration in code:

In[5]:
Code
import os
from openai import OpenAI


client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))

article = """[Your article text here...]"""


## Version 1: Basic prompt
## GPT-5 is ideal for summarization tasks with clear instructions
def summarize_v1(text):
    response = client.chat.completions.create(
        model="gpt-5",
        messages=[
            {"role": "user", "content": f"Summarize this article:\n\n{text}"}
        ],
    )
    return response.choices[0].message.content


## Version 2: Add constraints
def summarize_v2(text):
    response = client.chat.completions.create(
        model="gpt-5",
        messages=[
            {
                "role": "user",
                "content": f"Summarize this article in 3 sentences, focusing on the main points:\n\n{text}",
            }
        ],
    )
    return response.choices[0].message.content


## Version 3: Add role and tone
def summarize_v3(text):
    response = client.chat.completions.create(
        model="gpt-5",
        messages=[
            {
                "role": "system",
                "content": "You are a friendly assistant helping someone catch up on news.",
            },
            {
                "role": "user",
                "content": f"Summarize this article in 3 sentences, focusing on the main points. Use a conversational tone:\n\n{text}",
            },
        ],
    )
    return response.choices[0].message.content


## Test each version
print("Version 1:", summarize_v1(article))
print("\nVersion 2:", summarize_v2(article))
print("\nVersion 3:", summarize_v3(article))
Out[5]:
Console
Version 1: I don’t see the article text. Please paste the article (or a shareable link plus the key passages), and tell me:

- Desired length: 1–2 sentence TL;DR, 5-bullet summary, or a short paragraph?
- Audience: general reader, expert, or executive?
- Any focus: key findings, methods, implications, controversies, or stats/quotes to retain?
- Do you want a suggested headline?

If the article is long, you can paste it in parts—I’ll summarize as we go.

Version 2: I don’t have the article text yet. Please paste the article (or share a link), and I’ll summarize it in exactly 3 sentences focusing on the main points. If it’s long, you can paste it in chunks, and tell me if there’s any specific angle or audience you want prioritized.

Version 3: I don’t see the article text yet. Please paste the article or share a link, and I’ll give you a 3‑sentence, conversational summary focused on the main points. If it’s paywalled, you can paste the key sections or a screenshot, and I’ll work from that.

By keeping different versions, you can compare results and see which approach works best. In real development, you might save successful prompts in a file or database so you can reuse them later.

Combining Strategies

These strategies work even better together. You can give the AI a role AND provide examples AND iterate on the prompt. Each technique complements the others.

For instance, imagine you're building a feature where your personal assistant helps draft emails. You might combine strategies like this:

You are a professional assistant helping with business communication.

Here are examples of how to respond to meeting requests:

Request: "Can we meet next Tuesday?"
Response: "I'd be happy to meet next Tuesday. I have availability at 10am or 2pm. Which works better for you?"

Request: "Let's schedule a call sometime next week."
Response: "I'm available for a call next week. Would Monday at 3pm or Wednesday at 11am work for your schedule?"

Now draft a response to this request:
"We should catch up about the project. Are you free this week?"

This prompt combines a role (professional assistant), few-shot examples (two email responses), and clear instructions (draft a response). The result will be much better than using any single strategy alone.

Practical Tips for Better Prompting

As you develop your prompting skills, keep these guidelines in mind:

Be specific about format: If you want a list, say "Provide your answer as a numbered list." If you want JSON, show the structure you expect.

Set boundaries: Tell the AI what NOT to do if that's important. For example, "Explain this concept without using technical jargon" or "Summarize this without including personal opinions."

Use delimiters for clarity: When your prompt includes multiple parts (like examples or text to process), use clear separators. Triple quotes, XML-style tags, or section headers help the model understand the structure.

Consider token limits: Very long prompts can hit model limits or slow down responses. If your prompt is getting unwieldy, look for ways to be more concise.

Test edge cases: Once you have a prompt that works, try it with unusual inputs. This helps you find and fix weaknesses before they cause problems.

Building Your Prompting Intuition

As you practice these strategies, you'll develop intuition about what works. You'll start to recognize patterns: "This task needs examples" or "A role would help here." This intuition comes from experimentation.

Keep a collection of prompts that work well. When you find a good pattern for summarization, save it. When you discover a role that produces great results, note it down. Over time, you'll build a toolkit of proven approaches.

Remember that prompting is both an art and a science. The science is understanding the strategies and when to apply them. The art is crafting prompts that feel natural and produce results that match your vision. Both aspects improve with practice.

Looking Ahead

You now have several powerful strategies for communicating with your AI agent. You can give it roles to shape its responses, provide examples to teach patterns, and iterate to refine your results. These techniques work for simple tasks like summarization and complex challenges like multi-step reasoning.

In the next chapter, we'll explore how to get your agent to think through problems step by step. You'll learn about reasoning techniques that help the AI break down complex questions and arrive at better answers. The prompting strategies you've learned here will combine with these reasoning approaches to make your agent even more capable.

Glossary

Few-Shot Prompting: A technique where you provide the AI with a few examples of the pattern or task you want it to perform, allowing it to learn by demonstration rather than explicit instruction.

Role Assignment: The practice of giving the AI a specific persona or role (like "teacher" or "expert consultant") to guide how it approaches and responds to tasks.

System Message: A special type of prompt that sets the AI's behavior or role for an entire conversation, acting like stage directions that persist across multiple interactions.

Iteration: The process of repeatedly testing and refining prompts based on results, making incremental improvements until the output meets your needs.

Delimiter: A marker or separator (like triple quotes or XML tags) used in prompts to clearly distinguish different sections, such as examples, instructions, or content to be processed.

Quiz

Ready to test your understanding? Take this quick quiz to reinforce what you've learned about prompting strategies and tips.

Prompting Strategies and Tips Quiz

Question 1 of 60 of 6 completed
What is the primary purpose of assigning a role to an AI agent in a prompt?

Comments

No comments yet. Be the first to share your thoughts!

Reference

Citation details

Cite or share this article.

BIBTEXAcademic
@misc{brenndoerfer2025promptingstrategies, author = {Michael Brenndoerfer}, title = {Prompting Strategies and Tips: Role Assignment}, year = {2025}, url = {https://mbrenndoerfer.com/writing/prompting-strategies-tips-role-assignment-few-shot-iteration}, organization = {mbrenndoerfer.com}, note = {Accessed: 2026-09-30} }
APAAcademic
Michael Brenndoerfer (2025). Prompting Strategies and Tips: Role Assignment. Retrieved from https://mbrenndoerfer.com/writing/prompting-strategies-tips-role-assignment-few-shot-iteration
MLAAcademic
Michael Brenndoerfer. "Prompting Strategies and Tips: Role Assignment." 2026. Web. September 30, 2026. <https://mbrenndoerfer.com/writing/prompting-strategies-tips-role-assignment-few-shot-iteration>.
CHICAGOAcademic
Michael Brenndoerfer. "Prompting Strategies and Tips: Role Assignment." Accessed September 30, 2026. https://mbrenndoerfer.com/writing/prompting-strategies-tips-role-assignment-few-shot-iteration.
HARVARDAcademic
Michael Brenndoerfer (2025) 'Prompting Strategies and Tips: Role Assignment'. Available at: https://mbrenndoerfer.com/writing/prompting-strategies-tips-role-assignment-few-shot-iteration (Accessed: September 30, 2026).
SimpleBasic
Michael Brenndoerfer (2025). Prompting Strategies and Tips: Role Assignment. https://mbrenndoerfer.com/writing/prompting-strategies-tips-role-assignment-few-shot-iteration

About the author

Continue with the full handbook

This chapter is part of AI Agent Handbook. Use the handbook page to browse the complete table of contents and continue reading in sequence.

Explore AI Agent Handbook
Newsletter

Stay up to date

Get articles, book updates, and news delivered to your inbox.

No spam, unsubscribe anytime.

or

Join the community

Sign in to remove popups, track your reading progress, and join the discussion.