- 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.
create_agent:
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.
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.