Plugin System
Why Plugins?
The plugin system is the only way to programmatically extend agent functionality beyond the built-in capabilities. While agents themselves are markdown-based and declarative, plugins provide a JavaScript/TypeScript interface for:
- Custom integrations: Connect agents to your existing systems, databases, or APIs
- Observability: Add monitoring, logging, or analytics to track agent performance
- Automation workflows: Trigger actions based on agent completion or failure
- Development tools: Build debugging utilities or testing frameworks
- Cross-agent functionality: Share logic across all agents without modifying each one
Without plugins, you would be limited to the tools and capabilities built into AgentUse. Plugins bridge the gap between AgentUseβs declarative agent definitions and your custom programmatic needs.
Quick Start
- Create a plugin directory:
- Add a plugin file (
.js or .ts):
- Run your agent normally - plugins auto-load!
Plugin Locations
Plugins are automatically loaded from:
./.agentuse/plugins/*.{ts,js} - Project-specific plugins (loaded first)
~/.agentuse/plugins/*.{ts,js} - User-global plugins (loaded second)
Note: Project-specific plugins take precedence and are loaded before global plugins. All plugins with the same event handler will execute in the order they are loaded.
Plugin Structure
Each plugin must export a default object with event handlers:
Available Events
agent:complete
Fired when an agent successfully completes execution.
Event data:
The toolCallTraces array provides detailed performance information for each operation during agent execution:
Trace Types:
tool: Function tool calls (bash commands, file operations, etc.)
subagent: Sub-agent executions
llm: Direct LLM model calls
Use Cases:
- Performance monitoring and optimization
- Cost tracking for token usage
- Debugging slow operations
- Analytics and reporting
Example: Slack Notifications
Set your webhook URL:
Display detailed performance traces for agent executions using toolCallTraces:
This plugin outputs performance information like:
Ready to Use: Find this complete plugin in templates/plugins/trace-reporter.js. Copy it to .agentuse/plugins/ to start tracking performance.
You can extend the basic trace reporting with more advanced features:
- Slow Operation Detection: Warn about operations taking longer than 5 seconds
- Token Usage Tracking: Monitor prompt and completion tokens with cost estimates
- Operation Breakdown: Categorize calls by type (tool, sub-agent, LLM)
- Historical Logging: Save performance data to
.agentuse/performance.log
- Smart Filtering: Skip sub-agent executions to avoid duplicate logging
- Cost Analysis: Calculate estimated costs based on token usage
- Performance Thresholds: Set alerts for operations exceeding time or token limits
- Dashboards: Export data to monitoring services like Datadog or Grafana
- Comparative Analysis: Compare performance across different models or agent versions
TypeScript Support
For TypeScript plugins, import the types:
Error Handling
- Plugin loading errors are caught and logged as warnings, but donβt prevent the agent from running
- Invalid plugin formats (non-object default exports) are skipped with a warning message
- Plugin execution errors are caught and logged but donβt fail agent execution
- Missing plugin directories are handled gracefully
- Plugins can be disabled by removing/renaming the file
Best Practices
- Check
event.isSubAgent to avoid duplicate notifications
- Use environment variables for configuration
- Keep plugins focused on a single responsibility
- Handle errors gracefully within your plugin
- Use TypeScript for better type safety
Implementation Details
- Plugins are loaded using dynamic imports with absolute paths
- Plugin handlers are executed asynchronously in parallel
- Multiple plugins can handle the same event
- Console output is captured during agent execution and made available to plugins
- Plugin require cache is cleared for hot-reloading during development