agent.create_session() or chatbot.create_session().
Use as an async context manager or manually call connect/disconnect.
Usage
Lifecycle
connect
disconnect
terminate
disconnect() which just detaches this client,
terminate() tells the engine to destroy the session entirely.
The session cannot be resumed after termination.
Messaging
send
Message content. Accepts str, Path, bytes, or file-like objects. See
Union.Optional list of additional file attachments (reserved for future use). See
Union.Optional MIME type for non-text content.
Optional filename override for bytes/IOBase content.
send_many
UserSessionMessage for full multimodal control.
All entries use the same encoding rules as send().
Parameters
Streaming
listen
Optional filter — only events whose
type is in this collection are yielded. See SessionEventType.Maximum size of the internal subscriber queue. When a slow consumer lets this fill up, the listener will drop the offending event and emit a synthetic
ERROR event with data["error"] == "subscriber queue overflow" so the consumer can react. Pass 0 for an unbounded queue.See
SessionEvent.get_messages
SessionMessage objects.
Each message has id, session_id, sender, content_type,
text, status, and the original raw dict.
Returns
See
SessionMessage.Approvals
When a tool is gated withToolApprovalConfig.REQUIRES_APPROVAL, the agent pauses its turn and emits a SessionEventType.APPROVAL_REQUEST event on listen(). Resume the turn by calling one of the methods below; both dispatch the same WS message but respond_approval keeps the call-site readable when you also want to override the proposed arguments or send a deny reason.
respond
APPROVAL_REQUEST; future event types dispatch through the same call). Pass approved=True to let the tool run, approved=False to reject it.
Parameters
The paused event yielded by
listen().True to approve, False to reject.Override the arguments the model proposed (e.g.
{"num_results": 3} to cap a search). Approved calls only.Surfaced back to the model on rejection so it can adapt its next turn.
respond_approval
respond, but approved is required and event.type must be APPROVAL_REQUEST. Use this when you only ever respond to approvals and want the call site to enforce that.
Parameters
The
APPROVAL_REQUEST event from listen().True to approve the proposed tool call, False to reject.Replacement argument values for the approved call.
Reason surfaced to the model on rejection.
session-approval-respond example for a full event loop.
State
session_id
is_connected
Types
Configuration objects, response shapes, and enums used by the methods above.SessionEvent
SessionEvent(type: ‘SessionEventType’, session_id: ‘str’, message_id: ‘Optional[str]’ = None, data: ‘dict[str, Any]’ = <factory>)
Fields
SessionEventType
Members
MESSAGE_DELTA="message_delta"MESSAGE_COMPLETE="message_complete"MESSAGE_STREAMING="message_streaming"TOOL_CALL="tool_call"TOOL_RESULT="tool_result"THINKING="thinking"SEARCH_RESULT="search_result"APPROVAL_REQUEST="approval_request"REAUTH_REQUEST="reauth_request"ERROR="error"PARTICIPANT_STATUS="participant_status"SESSION_CREATED="session_created"SESSION_CONNECTED="session_connected"MESSAGE_POSTED="message_posted"MESSAGES_POSTED="messages_posted"PONG="pong"
SessionMessage
A message from session history (returned by session.get_messages()).
Fields
SessionMessageStatus
Members
STREAMING="streaming"COMPLETE="complete"ERROR="error"
MessageSender
Who sent a session message.
Fields
UserSessionMessage
Authored outbound message for use with session.send_many().
Each field mirrors the keyword arguments of session.send():
