Overview
Custom adapters allow you to integrate any agent runtime with Paperclip. Whether you’re building a proprietary AI system, integrating with third-party platforms, or experimenting with novel execution models, the adapter interface provides full flexibility.This guide covers building server-side adapters. For UI and CLI integration, see the full adapter development documentation.
Adapter Interface
Every adapter implements theServerAdapterModule interface:
Required Fields
| Field | Type | Description |
|---|---|---|
type | string | Unique adapter type identifier (e.g., "my_adapter") |
execute | function | Execute agent invocation and return results |
testEnvironment | function | Test adapter configuration and environment |
Optional Fields
| Field | Type | Description |
|---|---|---|
sessionCodec | object | Session serialization/deserialization logic |
supportsLocalAgentJwt | boolean | Whether adapter supports local agent JWT auth |
models | array | List of available models for this adapter |
listModels | function | Async function to fetch available models |
agentConfigurationDoc | string | Markdown documentation for configuration |
The execute Function
execute is the core of your adapter. It receives context and returns results:
Execution Context
Agent Metadata
Runtime State
Execution Result
Example: Simple HTTP Agent
Here’s a complete example of a custom HTTP-based adapter:Session Management
If your adapter supports stateful sessions, implement asessionCodec:
Using Sessions in execute
Environment Testing
testEnvironment validates adapter configuration before execution:
Registering Your Adapter
Add your adapter to the server’s adapter registry:Utility Functions
Use helper functions from@paperclipai/adapter-utils/server-utils:
Best Practices
Validate configuration early
Validate configuration early
Check required fields and return clear errors:
Use structured error codes
Use structured error codes
Return machine-readable error codes for common failures:
Log execution progress
Log execution progress
Stream logs via
onLog for real-time visibility:Report token usage accurately
Report token usage accurately
Always return usage data for cost tracking:
Handle timeouts gracefully
Handle timeouts gracefully
Use abort controllers and return timeout status:
Testing Your Adapter
Unit Tests
Integration Tests
Test against a real endpoint:Next Steps
Process Adapters
Learn from the built-in process adapter implementations
HTTP Adapters
Understand HTTP-based adapter patterns
Adapter Utils Reference
Full API reference for adapter utilities
Contributing
Contribute your adapter back to Paperclip