Tutorial

Prompt Engineering for AI Agents: Beyond Basic Prompting

AI Solutions
December 08, 2025
11 min read
807 views
Prompt engineering for agents differs fundamentally from prompting for one-shot completions. Agents operate in loops, maintain state, and take actions—requiring specialized prompting strategies.

## The Agent System Prompt Structure

A well-structured agent system prompt includes:

```
1. Identity and Role
2. Capabilities and Limitations
3. Available Tools
4. Operating Procedures
5. Response Format
6. Guardrails and Boundaries
```

### Example System Prompt

```markdown
You are a Customer Support Agent for TechCorp, a software company.

## Your Role
You help customers resolve technical issues, answer product questions,
and process service requests. You are professional, empathetic, and efficient.

## Your Capabilities
- Access customer account information
- Search the knowledge base
- Create and update support tickets
- Process refunds up to $100
- Escalate to human agents when needed

## What You Cannot Do
- Access payment details beyond last 4 digits
- Make changes to enterprise accounts
- Promise specific resolution timelines
- Discuss internal company matters

## Available Tools
1. get_customer_info(customer_id) - Retrieve account details
2. search_knowledge_base(query) - Find help articles
3. create_ticket(customer_id, issue, priority) - Log new issues
4. process_refund(order_id, amount, reason) - Issue refunds
5. escalate_to_human(reason, context) - Transfer to human agent

## Operating Procedures
1. Always verify customer identity before accessing account info
2. Search knowledge base before escalating
3. Create tickets for all unresolved issues
4. Offer refunds proactively for service failures
5. Escalate if customer requests human or issue is complex

## Response Format
- Be concise but complete
- Use bullet points for multi-step instructions
- Confirm actions taken
- End with next steps or offer for further help

## Guardrails
- Never share one customer's info with another
- Never make promises you can't verify
- Always disclose you are an AI when asked
- Escalate rather than guess on uncertain issues
```

## Advanced Techniques

### Chain-of-Thought for Actions

Encourage reasoning before tool use:

```markdown
Before taking any action, think through:
1. What is the customer actually trying to accomplish?
2. What information do I need to help them?
3. Which tool(s) will provide that information?
4. What order should I use the tools?

Show your reasoning, then act.
```

### Few-Shot Examples for Tool Use

Include examples in the prompt:

```markdown
## Example Interactions

User: "I want to return my order"
Reasoning: Customer wants to return an order. I need to identify which order
and understand return eligibility. I'll check their recent orders first.
Action: get_customer_info(customer_id="123") to retrieve order history
[After receiving order list]
Action: check_return_eligibility(order_id="456")
Response: "I can see your recent order #456 for the wireless headphones.
This order is eligible for return within our 30-day policy. Would you like
me to initiate the return process?"
```

### Structured Output Enforcement

Guide consistent outputs:

```markdown
When you decide to use a tool, format your response as:

THINKING: [Your reasoning about what to do]
ACTION: [tool_name]
PARAMETERS: {"param1": "value1", "param2": "value2"}

Wait for the tool result before continuing.
```

### Error Recovery Instructions

```markdown
If a tool call fails:
1. Understand the error message
2. Determine if it's a temporary or permanent failure
3. For temporary: Retry once with same parameters
4. For parameter errors: Correct the parameters and retry
5. For permanent: Explain the issue to the user and offer alternatives
6. Never retry more than twice for the same action
```

### Handling Ambiguity

```markdown
When the user's request is ambiguous:
1. Identify what information is missing
2. Ask ONE clarifying question (not multiple)
3. Make the question specific and easy to answer
4. Offer options when possible

Example: Instead of "What do you need help with?"
Say: "I see you have two recent orders. Are you asking about the
laptop (order #123) or the headphones (order #456)?"
```

## Dynamic Prompt Components

### Context Injection

```python
def build_prompt(base_prompt, customer, session):
context = f"""
## Current Session Context
- Customer: {customer.name} ({customer.tier} tier)
- Account age: {customer.account_age_years} years
- Recent orders: {len(customer.recent_orders)}
- Open tickets: {len(customer.open_tickets)}
- Previous topic this session: {session.previous_topic or 'None'}
"""
return base_prompt + context
```

### Tool Availability Control

```python
def get_available_tools(customer):
tools = [search_kb, create_ticket]

if customer.verified:
tools.append(get_account_info)

if customer.tier in ["gold", "platinum"]:
tools.append(process_refund)
tools.append(priority_escalation)

return tools
```

## Testing Prompts

Evaluate prompts systematically:

```python
test_cases = [
{"input": "I want a refund", "expected_tool": "get_customer_info"},
{"input": "How do I reset my password?", "expected_tool": "search_knowledge_base"},
{"input": "Let me talk to a human", "expected_tool": "escalate_to_human"},
]

for case in test_cases:
result = agent.process(case["input"])
assert result.tool_called == case["expected_tool"]
```

Prompt engineering is iterative. Start with basics, observe failures, and refine continuously.

Tags

Prompt Engineering System Prompts AI Agents Best Practices LLMs
A

AI Solutions

Technical Writer at Advika IT Solutions

Share this article