Skip to main content

Handler Overview

Your agent’s logic is defined in a Handler class in handle_query.py. The handler receives user messages and yields responses using the Claude Agent SDK.

Handler Structure

The handler implements a single async method:

Key Components

The handle_query Method

  • prompt (str) - The user’s input message
  • session_id (str | None) - Optional session ID for conversation continuity
  • kwargs (Any) - Additional parameters from the request
  • Returns - AsyncIterator[Message] that yields Claude SDK messages

Claude Agent Options

Configure the Claude Agent SDK behavior:
  • include_partial_messages (bool) - Stream partial responses as they’re generated
  • model (str) - Claude model to use (e.g., “claude-haiku-4-5”, “claude-sonnet-4”)
  • resume (str) - Session ID to resume a previous conversation

Structured Logging

The handler includes a structured logging system:

Log Levels

  • logger.debug() - Development debugging, verbose information
  • logger.info() - Important operational events
  • logger.warning() - Warning messages
  • logger.error() - Error messages

Viewing Logs

By default, only yielded messages reach clients. To see logs during development, enable debug mode:
Or when calling the API:
Print statements are captured as DEBUG logs. Use logger.debug() for cleaner structured logging.

Customizing Your Handler

Extend the handler to add custom functionality:

Example: Custom Preprocessing

Example: External API Integration

Next Steps