Skip to main content
Starter Kit - Ships with your template. You own it - modify freely.

Overview

The queries agent executes SQL queries across Hyperdrive-connected databases with built-in safety, performance, and transformation features. Key Features:
  • Support for named queries from catalog (coming soon)
  • Inline SQL queries with parameter binding
  • Named and positional parameters
  • Column name transformation (camelCase/snake_case)
  • Read-only mode for safety
  • Configurable row limits and timeouts
  • Query result caching
Location: /agents/system/queries/queries.yaml

Quick Start

Inline SQL with Positional Parameters

Inline SQL with Named Parameters

Input Schema

The queries agent accepts two mutually exclusive modes for specifying queries:

Option 1: Inline SQL (sql)

Option 2: Named Query (queryName)

Output Schema

Example Output

Configuration

Configure the queries agent behavior using the config block:

Configuration Examples

Read-only with row limit:
With caching and transformation:
With timeout:

Parameter Binding

Positional Parameters

Use ? placeholders in your SQL and provide values as an array:
SQL with positional parameters:
Parameters:

Named Parameters

Use :paramName placeholders in your SQL and provide values as an object:
SQL with named parameters:
Parameters:

Optional Parameters

Use OR :param IS NULL patterns for optional filtering:

Example Queries

The starter kit includes example SQL queries in /queries/examples/:

User Lookup (user-lookup.sql)

Find users by email or ID with optional filtering:
Usage:

Product Search (product-search.sql)

Full-text search with filtering and pagination:
Usage:

Analytics Summary (analytics-summary.sql)

Aggregate metrics for a date range:
Usage:

Best Practices

1. Use Named Parameters for Readability

Good:
Avoid:

2. Enable Read-Only Mode in Production

3. Set Row Limits

4. Cache Expensive Queries

5. Use Column Transformation Consistently

Result:

6. Handle Optional Filters Properly

7. Use Separate Databases for Different Workloads

8. Set Appropriate Timeouts

9. Validate Input Parameters

10. Monitor Query Performance

Use the metadata in the output to track performance:

Data Operations

Learn about D1, Hyperdrive, and Vectorize operations

Starter Kit Overview

Explore other agents in the starter kit