When Should You Build an Agent?
Not every task benefits from an agent. Before reaching for LangGraph or CrewAI, ask:
| Question | Good Fit for Agent | Better as Plain LLM |
|---|---|---|
| Does the task require multiple steps? | Yes | Single-step |
| Does it need external data? | Yes | Context is self-contained |
| Is the path to solution unknown upfront? | Yes | Deterministic |
| Does it benefit from self-correction? | Yes | One-shot is fine |
| Does human oversight help? | Optionally | N/A |
The sweet spot for agents: multi-step tasks with external interactions where the optimal sequence is not known in advance.
Use Case 1: Software Engineering Agents
Software development is the highest-value domain for agents today.
What They Do
- Read and understand entire codebases
- Write, test, and debug code autonomously
- Create pull requests with descriptions
- Review code and suggest improvements
- Set up development environments
Example: Automated Bug Fix Agent
from anthropic import Anthropic
import subprocess, os
client = Anthropic()
tools = [
{
"name": "read_file",
"description": "Read a source code file",
"input_schema": {
"type": "object",
"properties": {"path": {"type": "string"}},
"required": ["path"]
}
},
{
"name": "write_file",
"description": "Write/update a source code file",
"input_schema": {
"type": "object",
"properties": {
"path": {"type": "string"},
"content": {"type": "string"}
},
"required": ["path", "content"]
}
},
{
"name": "run_tests",
"description": "Run the test suite and return output",
"input_schema": {
"type": "object",
"properties": {
"test_file": {"type": "string", "description": "Test file path (optional)"}
}
}
},
{
"name": "list_files",
"description": "List files in a directory",
"input_schema": {
"type": "object",
"properties": {"directory": {"type": "string"}},
"required": ["directory"]
}
}
]
def execute_tool(name: str, args: dict) -> str:
if name == "read_file":
with open(args["path"]) as f:
return f.read()
elif name == "write_file":
with open(args["path"], "w") as f:
f.write(args["content"])
return f"File written: {args['path']}"
elif name == "run_tests":
cmd = ["python", "-m", "pytest", args.get("test_file", "tests/"), "-v", "--tb=short"]
result = subprocess.run(cmd, capture_output=True, text=True, timeout=60)
return result.stdout + result.stderr
elif name == "list_files":
files = []
for root, dirs, names in os.walk(args["directory"]):
dirs[:] = [d for d in dirs if not d.startswith(".") and d != "__pycache__"]
for name in names:
files.append(os.path.join(root, name))
return "\n".join(files[:50])
def bug_fix_agent(bug_report: str) -> str:
messages = [{
"role": "user",
"content": f"""Fix this bug in the codebase:
{bug_report}
Steps:
1. List the project structure to understand the codebase
2. Read relevant source files
3. Identify the root cause
4. Write the fix
5. Run tests to verify the fix works
6. Return a summary of what you changed and why"""
}]
for _ in range(15): # max iterations
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=4096,
tools=tools,
messages=messages,
)
if response.stop_reason == "end_turn":
return next(b.text for b in response.content if hasattr(b, "text"))
messages.append({"role": "assistant", "content": response.content})
tool_results = []
for block in response.content:
if block.type == "tool_use":
result = execute_tool(block.name, block.input)
tool_results.append({
"type": "tool_result",
"tool_use_id": block.id,
"content": result,
})
messages.append({"role": "user", "content": tool_results})
return "Max iterations reached"Use Case 2: Research & Synthesis Agents
Research agents can compress days of human research into minutes by:
- Searching the web for recent information
- Reading and extracting key points from papers and articles
- Cross-referencing multiple sources
- Generating structured reports with citations
Production Example: Competitive Intelligence
# A crew that monitors competitors daily
crew = Crew(
agents=[web_researcher, analyst, report_writer],
tasks=[
Task("Monitor competitor blogs, product pages, and job postings for {company}"),
Task("Analyze findings: what changed? What does it signal?"),
Task("Write a 1-page executive brief with top 3 insights and recommendations"),
],
process=Process.sequential,
)
# Run every morning via cron
result = crew.kickoff(inputs={"company": "Acme Corp"})
send_email(to="team@mycompany.com", subject="Daily Intel", body=result)
Use Case 3: Customer Service Agents
Agentic customer service goes beyond FAQ bots:
| Capability | Traditional Chatbot | AI Agent |
|---|---|---|
| Answer FAQs | Yes | Yes |
| Look up account status | Limited | Yes (via tools) |
| Process refunds | No | Yes (with approval) |
| Troubleshoot issues | Script-based | Adaptive |
| Escalate to human | Keyword-based | Context-aware |
| Learn from resolution | No | Yes (with memory) |
Key Pattern: Confidence-Gated Actions
def route_action(action: str, confidence: float) -> str:
if confidence > 0.95:
return "auto_execute" # high confidence, execute immediately
elif confidence > 0.75:
return "human_review" # medium confidence, human approves
else:
return "escalate_to_human" # low confidence, human takes over
Use Case 4: Data Analysis Agents
These agents write SQL/Python, run queries, interpret results, and iterate:
- User: "Why did revenue drop 15% in Q3?"
- Agent writes SQL to query the data warehouse
- Agent runs the query, sees results
- Agent identifies the top 3 contributing factors
- Agent writes more targeted queries to confirm hypotheses
- Agent generates a formatted report with charts
Key tools: SQL executor, Python REPL, chart generator, email sender
Use Case 5: DevOps & SRE Agents
Production incident response is a high-stakes agentic domain:
Alert: p99 latency > 2s on /api/checkout
Agent:
1. Query metrics: identify which services are slow
2. Check recent deployments: find what changed
3. Read logs: find error patterns
4. Check database: spot slow queries
5. Identify root cause: new index missing after migration
6. Propose fix: CREATE INDEX idx_orders_user_id ON orders(user_id)
7. Run fix in staging → verify → ask human to approve prod
Frameworks like PagerDuty + LangGraph enable exactly this workflow with full audit trails.
Evaluating Your Agent Use Case
Before building, score your use case on these dimensions:
Green Flags (build it!)
- Clear success/failure criteria
- External data sources the LLM doesn't have
- Multi-step with knowable sub-tasks
- Human oversight feasible and valuable
- High cost of human doing this manually
Red Flags (rethink it)
- Success is subjective / hard to measure
- Errors have irreversible consequences (money, data deletion)
- Latency requirements < 1 second
- High compliance/regulatory requirements without audit trail
- The task is actually simple — a prompt is enough
Common Production Pitfalls
| Pitfall | Solution |
|---|---|
| Infinite loops | Max iteration limits + termination conditions |
| Hallucinated tool calls | Validate tool inputs with Pydantic schemas |
| Context window overflow | Summarize old messages, use RAG for history |
| Unreliable tool execution | Retry logic, idempotent tools |
| No observability | Structured logging of every step |
| Silent failures | Require explicit success confirmation |
Knowledge check
Which of these tasks is the BEST fit for an agentic system?
Summary
Agentic AI is delivering value across many domains:
- Software engineering — automated bug fixes, code review, CI/CD agents
- Research — competitive intelligence, literature synthesis, due diligence
- Customer service — account management, troubleshooting, escalation
- Data analysis — query generation, root cause analysis, reporting
- DevOps — incident response, runbook automation, deployment agents
The best use cases share a common profile: multi-step, externally-dependent, with measurable outcomes and human oversight for high-stakes actions.
In the final chapter, we'll put everything together and build a complete end-to-end agent system from scratch.