- Tracking agent behavior with logging, analytics, and debugging.
- Transforming prompts, tool selection, and output formatting.
- Adding retries, fallbacks, and early termination logic.
- Applying rate limits, guardrails, and PII detection.
createAgent:
The agent loop
The core agent loop involves calling a model, letting it choose tools to execute, and then finishing when it calls no more tools:

Additional resources
Built-in middleware
Explore built-in middleware for common use cases.
Custom middleware
Build your own middleware with hooks and decorators.
Middleware API reference
Complete API reference for middleware.
Testing agents
Test your agents with LangSmith.