Block SDK Guide
This guide explains how to create new blocks for the AutoGPT Platform using the SDK pattern with advanced features.
Overview
Blocks are reusable components that perform specific tasks in AutoGPT workflows. They can integrate with external services, process data, or perform any programmatic operation.
Basic Structure
1. Create Provider Configuration
First, create a _config.py file to configure your provider using the ProviderBuilder:
from backend.sdk import BlockCostType, ProviderBuilder
# Simple API key provider
my_provider = (
ProviderBuilder("my_provider")
.with_api_key("MY_PROVIDER_API_KEY", "My Provider API Key")
.with_base_cost(1, BlockCostType.RUN)
.build()
)For OAuth providers:
2. Create the Block Class
Create your block file (e.g., my_block.py):
Key Components Explained
Provider Configuration
The ProviderBuilder allows you to:
.with_api_key(): Add API key authentication.with_oauth(): Add OAuth authentication.with_base_cost(): Set resource costs for the block.with_webhook_manager(): Add webhook support.with_user_password(): Add username/password auth
Block Schema
Input/Output classes: Define the data structure using
BlockSchemaSchemaField: Define individual fields with validation
CredentialsMetaInput: Special field for handling credentials
Block Implementation
Unique ID: Generate using
uuid.uuid4()Categories: Choose from
BlockCategoryenum (e.g., SEARCH, AI, PRODUCTIVITY)async run(): Main execution method that yields outputs
Error handling: Error output pin is already defined on BlockSchemaOutput
Advanced Features
Testing
Add test configuration to your block:
OAuth Support
Create an OAuth handler in _oauth.py:
Webhook Support
Create a webhook manager in _webhook.py:
File Organization
Best Practices
Error Handling: Use
BlockInputErrorfor validation failures andBlockExecutionErrorfor runtime errors (import frombackend.util.exceptions). These inherit fromValueErrorso the executor treats them as user-fixable. See Error Handling in new_blocks.md for details.Credentials: Use the provider's
credentials_field()methodValidation: Use SchemaField constraints (ge, le, min_length, etc.)
Categories: Choose appropriate categories for discoverability
Advanced Fields: Mark complex options as
advanced=TrueAsync Operations: Use
async/awaitfor I/O operationsAPI Clients: Use
Requests()from SDK or external librariesTesting: Include test inputs/outputs for validation
Common Patterns
Making API Requests
Multiple Auth Types
Testing Your Block
Integration Checklist
Example Blocks for Reference
Simple API:
/backend/blocks/firecrawl/- Basic API key authenticationOAuth + API:
/backend/blocks/linear/- OAuth and API key supportWebhooks:
/backend/blocks/exa/- Includes webhook manager
Study these examples to understand different patterns and approaches for building blocks.
Last updated
Was this helpful?