Handler Overview
Your agent’s logic is defined in aHandler 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 messagesession_id(str | None) - Optional session ID for conversation continuitykwargs(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 generatedmodel(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 informationlogger.info()- Important operational eventslogger.warning()- Warning messageslogger.error()- Error messages
Viewing Logs
By default, only yielded messages reach clients. To see logs during development, enable debug mode: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
- Learn about agent configuration
- Understand how to add dependencies