Skip to main content
Use direct model calls when your application owns conversation state and tool execution. Use an agent when the SDK should manage the model/tool loop. The snippets assume ctx and a configured model. Import pkg/gateway/llm/responses and pkg/utils.

Request a complete response

Streaming responses

Cancel the stream context when you stop consuming, so producer work can unwind. Account for terminal events if your application needs to distinguish completed output from an incomplete response. Do not silently discard in-band errors.

Continue a conversation

For direct model calls, retain the input and output items yourself. Convert returned output items with item.AsInput() and append the next user message to responses.InputMessageList. Preserve reasoning and tool-call items required by the provider, not just visible assistant text. The bound client does not maintain a thread for you. For persisted conversation state, use agent history.