Prompt
what's the best way to build an AI agent that can use tools and handle real user requests?
Latest observation
The best way is to treat it like a reliable software system, not just “a model with prompts.”
A strong pattern
1) Make the agent a controller, not the worker
Use the LLM to:
- understand the user’s intent
- decide which tool to use
- extract parameters
- summarize results back to the user
But keep the actual business logic in normal code:
- validation
- permissions
- retries
- error handling
- data access
- side effects
This keeps the agent predictable.
2) Give it a small, well-designed toolset
Start with a few tools that are:
- clearly named
- narrowly scoped
- deterministic
- well-documented
Example tools:
search_docs(query)create_ticket(title, description, priority)lookup_order(order_id)send_email(to, subject, body)
Avoid giant “do everything” tools.
3) Use structured tool calling
Don’t rely on free-form text parsing if you can avoid it.
Have the model output structured arguments, like JSON/function calls.
That lets you:
- validate inputs before execution
- reject malformed actions
- log exactly what the agent intended
- recover from failures cleanly
4) Put a planning loop around the model
A practical agent usually follows this loop:
- read user request
- decide whether a tool is needed
- call one or more tools
- inspect results
- either answer, ask a clarification, or continue
This is often called an agent loop or tool-use loop.
5) Add guardrails for real users
Real requests are messy. You need:
- authentication and authorization
- rate limits
- confirmation for irreversible actions
- input sanitization
- tool-level permission checks
- logging and audit trails
For example:
- “Send this email” should usually require confirmation
- “Refund the customer” should verify policy and permissions first
6) Design for ambiguity
A good agent should know when to ask questions.
If the user says:
- “Book me a flight to Paris next Friday”
the agent may need to ask:
- departure city
- budget
- preferred time
- baggage needs
Don’t force it to guess when the cost of being wrong is high.
7) Use retrieval for knowledge, not prompting alone
If the agent needs company docs, policies, or product info:
- store them in a searchable knowledge base
- retrieve relevant passages at runtime
- feed only the needed context to the model
This is usually better than stuffing everything into the system prompt.
8) Build evaluation early
Before shipping, test with real-ish scenarios:
- straightforward requests
- ambiguous requests
- malformed tool outputs
- tool failures
- permission edge cases
- prompt injection attempts
Measure:
- task success rate
- tool-call accuracy
- clarification rate
- unsafe action rate
- latency and cost
Recommended architecture
A good practical setup is:
- UI / API
- Agent orchestrator
- LLM
- Tool layer
- Policy/permission layer
- Retrieval layer
- Logging/monitoring
The orchestrator handles the loop; the tools do the work; policy decides what’s allowed.
What not to do
- Don’t let the model directly access databases or production systems
- Don’t give it unlimited tools
- Don’t rely on a single giant prompt
- Don’t skip validation
- Don’t assume users will be well-formed or honest
Best starting approach
If you’re building from scratch, start with:
- one narrow use case
- 3–5 tools max
- structured tool calls
- human confirmation for risky actions
- logging and evaluation from day one
That gives you something useful without overcomplicating it.
If you want, I can also give you:
- a reference architecture
- a sample tool schema
- or a minimal agent loop in Python