client.Interrupt(ctx) - Interrupt an ongoing response
client.Close() - Clean up resources
This is ideal for:
Multi-turn conversations with context
Interactive applications
Scenarios requiring interrupt capability
Examples
Example
Description
quick_start
Basic usage of the Query() function
query_stream
Using QueryStream() with iter.Seq[StreamingMessage]
client_multi_turn
Client API with multi-turn conversations, interrupts, and advanced patterns
sessions
Managing conversation sessions
agents
Building custom agents
filesystem_agents
File system operations with agents
hooks
Using lifecycle hooks
compaction_hook
Monitoring context compaction with the PreCompact hook
mcp_calculator
MCP server integration
mcp_status
Querying MCP server connection status
memory_tool
Filesystem-backed memory tool for agent state persistence
plugin_example
Plugin system usage
system_prompt
Customizing system prompts
tools_option
Configuring allowed tools
tool_permission_callback
Custom tool permission handling
user_input_callback
Auto-answer AskUserQuestion prompts with WithOnUserInput
stderr_callback
Capturing CLI stderr output
custom_logger
Custom logging configuration
max_budget_usd
Setting cost limits
setting_sources
Configuration sources
include_partial_messages
Handling partial/streaming messages
structured_output
Using WithOutputFormat() for structured JSON responses
extended_thinking
Extended thinking capabilities for complex reasoning
error_handling
Checking AssistantMessage.Error for API errors
cancellation
Context cancellation and signal handling
parallel_queries
Running concurrent Query() calls with errgroup
pipeline
Multi-step LLM orchestration with Go control flow
Running Examples
# Run a specific example
go run ./examples/quick_start
# Run client_multi_turn with a specific sub-example
go run ./examples/client_multi_turn basic_streaming
go run ./examples/client_multi_turn all