15 Powerful Prompts for Building AI Agents with LangChain, AutoGPT, and CrewAI
Introduction
AI agents are transforming how we automate complex tasks — from customer support and data analysis to multi-step research and code generation. Whether you're using LangChain for orchestration, AutoGPT for autonomous goal pursuit, or CrewAI for multi-agent collaboration, the quality of your prompts determines the agent's effectiveness. In this guide, you'll find 15 battle-tested prompts that I use daily in production systems, complete with code examples and practical advice.
1. LangChain: ReAct Agent for Tool-Using
Prompt:
You are a helpful assistant with access to the following tools: {tools}. For each task, first decide which tool to use, call it with the correct parameters, and then use the result to answer the user. Always follow the format:
Thought: ...
Action: tool_name
Action Input: tool_input
Observation: tool_output
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: ...
Code Example:
from langchain.agents import create_react_agent, AgentExecutor
from langchain.tools import Tool
from langchain_openai import ChatOpenAI
from langchain.prompts import PromptTemplate
# Define tools
def search(query: str) -> str:
return f"Simulated search result for {query}"
def calculator(expr: str) -> str:
return str(eval(expr))
tools = [
Tool(name="Search", func=search, description="Search the web for information"),
Tool(name="Calculator", func=calculator, description="Perform arithmetic calculations")
]
# Create LLM and agent
llm = ChatOpenAI(model="gpt-4", temperature=0)
prompt = PromptTemplate.from_template(
"You are a helpful assistant with access to the following tools: {tools}.\n"
"For each task, first decide which tool to use, call it with the correct parameters, "
"and then use the result to answer the user. Always follow the format:\n"
"Thought: ...\nAction: tool_name\nAction Input: tool_input\nObservation: tool_output\n"
"... (this can repeat N times)\nThought: I now know the final answer\nFinal Answer: ...\n"
"\nTools: {tools}\n\n{agent_scratchpad}"
)
agent = create_react_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
# Run the agent
result = agent_executor.invoke({"input": "What is 25 * 4 + 10? Then search for 'AI news'"})
print(result["output"])
This prompt enforces a structured reasoning loop, critical for reliable tool use.
2. LangChain: Conversational Agent with Memory
Prompt:
You are a conversational assistant. Use the chat history and the current question to respond helpfully. If you need to use a tool, do so using the format below. If not, just answer directly.
Chat History:
{chat_history}
Human: {input}
Code Example:
from langchain.memory import ConversationBufferMemory
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain.tools import Tool
from langchain_openai import ChatOpenAI
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
tools = [Tool(name="Calculator", func=lambda x: str(eval(x)), description="Arithmetic")]
llm = ChatOpenAI(model="gpt-4", temperature=0.7)
agent = create_tool_calling_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, memory=memory, verbose=True)
# First interaction
agent_executor.invoke({"input": "Hi, my name is Alice"})
# Second interaction — remembers name
agent_executor.invoke({"input": "What's my name?"})
Memory makes the agent stateful — essential for customer support or personal assistants.
3. AutoGPT: Autonomous Goal-Setting
Prompt:
You are an autonomous AI agent. Your goal is: {goal}. Break down the goal into up to 5 sub-tasks. For each sub-task, decide whether to execute a command (like web search, file write, Python) or generate text. Execute one step at a time. After each step, review progress and decide the next action. When the goal is achieved, output "FINISHED: <summary>".
Code Example (using AutoGPT Python library):
from autogpt.agent import Agent
from autogpt.config import AgentConfig
config = AgentConfig(
ai_name="ResearchBot",
ai_role="autonomous researcher",
ai_goal="Find the latest papers on reinforcement learning from 2025 and summarize them in a markdown file.",
prompt_template="You are an autonomous AI agent. Your goal is: {goal}. ..."
)
agent = Agent(config)
agent.run()
This prompt enables long-running autonomy. I've used it for automated market research and report generation.
4. AutoGPT: Task Decomposition Prompt
Prompt:
You are an expert project manager. Given the high-level goal: {goal}, decompose it into a sequence of 3-5 smaller tasks. For each task, specify:
- Task name
- Required resources (tools, data)
- Expected output
- Dependencies
- Success criteria
Output as a numbered list.
This helps AutoGPT handle complex goals by breaking them into manageable steps.
5. CrewAI: Multi-Agent Research Team
Prompt for Researcher Agent:
You are a senior research analyst. Your task: {task}. Use the following tools: {tools}. Provide a detailed report with citations. Be thorough — include data, statistics, and key findings.
Prompt for Writer Agent:
You are a professional content writer. Based on the research provided by the analyst, write a 500-word blog post in a conversational tone. Include an engaging headline and a call to action.
Code Example:
from crewai import Agent, Task, Crew, Process
researcher = Agent(
role="Senior Research Analyst",
goal="Uncover cutting-edge developments in AI",
backstory="You work at a leading tech think tank.",
tools=[search_tool],
verbose=True,
allow_delegation=False,
prompt_template="You are a senior research analyst. Your task: {task}. ..."
)
writer = Agent(
role="Content Writer",
goal="Craft compelling blog posts based on research",
backstory="You are a famous tech blogger.",
verbose=True,
allow_delegation=False,
prompt_template="You are a professional content writer. ..."
)
research_task = Task(
description="Research the latest trends in LLM fine-tuning",
expected_output="A detailed 3-page research report",
agent=researcher
)
write_task = Task(
description="Write a blog post based on the research report",
expected_output="A 500-word blog post in markdown",
agent=writer
)
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, write_task],
process=Process.sequential
)
result = crew.kickoff()
print(result)
This pattern is a staple for content pipelines and automated reporting.
6. CrewAI: Manager Agent with Delegation
Prompt:
You are a project manager. You have a team of agents with the following roles: {roles}. Your goal: {goal}. Delegate tasks to the appropriate agent. Monitor progress. If an agent fails, reassign the task. When all tasks are complete, provide a final summary.
Code Example:
manager_agent = Agent(
role="Project Manager",
goal="Coordinate the team to build a market analysis report",
backstory="You are an experienced PM at a consulting firm.",
allow_delegation=True,
prompt_template="You are a project manager. ..."
)
crew = Crew(
agents=[researcher, analyst, writer, manager_agent],
tasks=[research_task, analysis_task, write_task],
manager_agent=manager_agent,
process=Process.hierarchical
)
Hierarchical crew with a manager agent scales well for complex projects.
7. LangChain: Tool-Using Agent with Error Handling
Prompt:
You are a robust agent. You have access to tools: {tools}. If a tool call fails (e.g., returns an error), retry up to 2 times with a different approach. If it still fails, tell the user and suggest an alternative.
Code Example:
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain.tools import Tool
from langchain_openai import ChatOpenAI
# A tool that sometimes fails
def fragile_api(query: str) -> str:
if "error" in query.lower():
raise Exception("API failure")
return f"Result for {query}"
tools = [Tool(name="FragileAPI", func=fragile_api, description="A fragile API")]
llm = ChatOpenAI(model="gpt-4", temperature=0)
agent = create_tool_calling_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True, max_iterations=5, early_stopping_method="generate")
result = agent_executor.invoke({"input": "Call the fragile API with 'error test'"})
print(result["output"])
Error handling is crucial for production agents.
8. AutoGPT: Self-Reflection Prompt
Prompt:
You are an AI agent. You just completed the step: {last_step}. The output was: {output}. Reflect on whether the output moves you closer to the goal: {goal}. If yes, proceed to the next step. If no, adjust your approach. Explain your reasoning.
This prompt adds a metacognitive layer, improving autonomy and reducing wasted steps.
9. CrewAI: Parallel Task Execution
Prompt for each agent:
You are a {role}. Your task is: {task}. Work independently. Do not wait for other agents unless your task explicitly depends on them. Report your results when done.
Code Example:
crew = Crew(
agents=[agent_a, agent_b, agent_c],
tasks=[task_a, task_b, task_c],
process=Process.parallel # Agents work simultaneously
)
Parallel execution speeds up workflows like data scraping and analysis.
10. LangChain: Custom Prompt with Few-Shot Examples
Prompt:
You are an agent that converts natural language into SQL queries. Here are some examples:
Example 1:
Input: "Show all customers from New York"
Output: SELECT * FROM customers WHERE city = 'New York';
Example 2:
Input: "Total sales per product in 2025"
Output: SELECT product_id, SUM(sales) FROM orders WHERE year = 2025 GROUP BY product_id;
Now, convert this input: {input}
Code Example:
from langchain.prompts import FewShotPromptTemplate, PromptTemplate
from langchain.agents import create_tool_calling_agent, AgentExecutor
examples = [
{"input": "Show all customers from New York", "output": "SELECT * FROM customers WHERE city = 'New York';"},
{"input": "Total sales per product in 2025", "output": "SELECT product_id, SUM(sales) FROM orders WHERE year = 2025 GROUP BY product_id;"}
]
few_shot_prompt = FewShotPromptTemplate(
examples=examples,
example_prompt=PromptTemplate(input_variables=["input", "output"], template="Input: {input}\nOutput: {output}"),
prefix="You are an agent that converts natural language into SQL queries.",
suffix="Now, convert this input: {input}",
input_variables=["input"]
)
agent = create_tool_calling_agent(llm, tools, few_shot_prompt)
Few-shot learning dramatically improves task-specific performance.
11. LangChain: Agent with Human-in-the-Loop
Prompt:
You are an agent. Before executing any tool call that costs money (like API calls), ask the user for confirmation. Format your confirmation request as:
CONFIRM: I need to call {tool_name} with parameters {tool_input}. Approve?
Code Example:
from langchain.agents import create_tool_calling_agent, AgentExecutor
def human_approval(tool_name, tool_input):
response = input(f"Approve call to {tool_name} with {tool_input}? (y/n): ")
return response.lower() == 'y'
# Custom executor with approval step
class ApprovalAgentExecutor(AgentExecutor):
def _take_next_step(self, *args, **kwargs):
action = super()._take_next_step(*args, **kwargs)
if hasattr(action, 'tool') and not human_approval(action.tool, action.tool_input):
return None # Skip the action
return action
Human-in-the-loop prevents costly mistakes in production.
12. CrewAI: Agent with Specific Output Format
Prompt:
You are a data analyst. Your task: {task}. Output your findings strictly as a JSON object with keys: "summary", "key_metrics", "recommendations". Do not include any other text.
Code Example:
analyst = Agent(
role="Data Analyst",
goal="Provide structured analysis",
backstory="You work in a data science team.",
prompt_template="You are a data analyst. Your task: {task}. Output your findings strictly as a JSON object with keys: 'summary', 'key_metrics', 'recommendations'. Do not include any other text."
)
result = analyst.execute_task("Analyze the sales data for Q1 2026")
# result will be a JSON string
Structured output makes it easy to integrate agents into pipelines.
13. AutoGPT: Constraint-Aware Prompt
Prompt:
You are an AI agent. You have the following constraints:
- Budget: {budget} API calls
- Time: {time} minutes
- Allowed tools: {allowed_tools}
- Disallowed actions: {disallowed_actions}
Your goal: {goal}. Plan your steps to respect these constraints.
This is useful when running agents on limited resources.
14. LangChain: Multi-Step Reasoning Agent
Prompt:
You are an agent that solves problems step by step. For each step, think aloud:
1. What do I know?
2. What do I need to find out?
3. What tool can help?
4. Execute the tool.
5. Interpret the result.
Repeat until the answer is found. Show all your work.
Code Example:
from langchain.agents import create_react_agent, AgentExecutor
prompt = PromptTemplate.from_template(
"You are an agent that solves problems step by step. For each step, think aloud:\n"
"1. What do I know?\n2. What do I need to find out?\n3. What tool can help?\n"
"4. Execute the tool.\n5. Interpret the result.\n"
"Repeat until the answer is found. Show all your work.\n\n"
"Tools: {tools}\n\n{agent_scratchpad}"
)
agent = create_react_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
result = agent_executor.invoke({"input": "What is the population of Tokyo divided by the population of Paris?"})
This encourages transparency and makes debugging easier.
15. CrewAI: Feedback Loop Between Agents
Prompt for Reviewer Agent:
You are a quality assurance reviewer. Review the output from the {previous_agent} for the task: {task}. Check for accuracy, completeness, and clarity. If the output meets criteria, say "APPROVED". If not, provide specific feedback for improvement.
Code Example:
reviewer = Agent(
role="QA Reviewer",
goal="Ensure output quality",
backstory="You are a meticulous editor.",
prompt_template="You are a quality assurance reviewer. ..."
)
# Tasks: research -> review (if not approved, redo) -> write
# This can be implemented with a custom process
Feedback loops dramatically improve output quality in multi-agent systems.
Conclusion
These 15 prompts cover the core patterns for building effective AI agents: structured reasoning, memory, autonomy, delegation, error handling, and quality control. Start by adapting them to your specific use case — whether it's a simple LangChain bot or a complex CrewAI team. The key is iteration: test, observe, refine your prompts. For further reading, check out the official LangChain documentation and the CrewAI GitHub repository. Happy building!
Comments