Understanding the Agent
TheAgent class extends the XRPC client with AT Protocol-specific functionality and Bluesky syntactic sugar. It handles authentication, request signing, and provides convenient methods for common operations.
- A
CredentialSessionfor app password authentication (deprecated) - An
OAuthSessionfrom the OAuth client (recommended) - A custom
SessionManagerimplementation
Core Concepts
Session Management
Every agent is backed by a session manager that handles authentication state:Labelers Configuration
Labelers provide moderation labels for content. Configure which labelers the agent uses:Proxy Configuration
Route requests through a proxy service:Working with Posts
Creating Posts
Create posts using thepost() method:
The
createdAt field is required and must be an ISO 8601 timestamp.Posts with Rich Text
Use theRichText class to handle mentions, links, and other facets:
Posts with Media
Upload images and embed them in posts:Deleting Posts
Delete a post using its URI:Reading Feeds and Posts
Getting the Timeline
Retrieve the authenticated user’s timeline:Getting an Author’s Feed
Retrieve posts from a specific user:Getting Post Threads
Retrieve a post and its replies:Getting Multiple Posts
Fetch multiple posts by URI:Social Graph Operations
Following Users
Follow a user:Unfollowing Users
Getting Followers
Getting Follows
Engagement Actions
Liking Posts
Unliking Posts
Reposting
Deleting Reposts
Profile Management
Getting Profiles
Get a single profile:Updating Your Profile
UseupsertProfile to safely update your profile:
upsertProfile method:
- Fetches the current profile
- Passes it to your callback function
- Creates or updates the profile record
- Handles CAS (Compare-And-Swap) conflicts automatically
Notifications
Listing Notifications
Counting Unread Notifications
Marking Notifications as Seen
Search
Searching for Users
Typeahead Search
For autocomplete functionality:Moderation
Muting Users
Unmuting Users
Blocking Users
Blocking is done by creating a block record:Advanced Usage
Direct XRPC Calls
For methods not wrapped by convenience functions, use the namespaced API:Custom Headers
Set custom headers for requests:Cloning Agents
Create a copy of an agent with the same configuration:Error Handling
Handle errors from API calls:Best Practices
1
Use OAuth authentication
Always use OAuth-based sessions in production rather than app passwords for better security and token management.
2
Handle pagination
Use cursors properly when fetching large datasets to avoid missing items.
3
Validate input
Validate user input before creating records, especially for rich text.
4
Handle rate limits
Implement exponential backoff when hitting rate limits.
Common Pitfalls
Next Steps
OAuth Authentication
Implement secure OAuth-based authentication
Rich Text
Work with mentions, links, and formatted text
Moderation
Implement content moderation in your app
API Reference
Explore the complete API reference