Slipstream Package¶
The azad.slipstream package provides network communication and protocol handling for the Azad agent. It enables the agent to communicate with clients and other components over WebSockets.
Core Components¶
Base¶
The Base module defines the core interfaces and classes for network communication. It includes:
Protocolinterface for implementing different network protocolsProtocolHandlerinterface for handling protocol messages- Decorators for request/response and request/stream patterns
Client¶
The Client module provides client-side network communication. It includes:
- Classes for connecting to the agent server
- Methods for sending requests and receiving responses
- Utilities for handling streaming responses
Server¶
The Server module provides server-side network communication. It includes:
- Classes for creating and managing server instances
- Methods for handling client connections
- Utilities for routing messages to the appropriate handlers
WebSocket¶
The WebSocket module provides WebSocket-specific network communication. It includes:
WebSocketNetworkProtocolclass for WebSocket communication- Methods for starting and stopping the WebSocket server
- Utilities for handling WebSocket connections and messages
How Slipstream Works¶
The Slipstream package implements a request/response and request/stream pattern for network communication:
- Request/Response: A client sends a request to the server and receives a single response.
- Request/Stream: A client sends a request to the server and receives a stream of responses.
These patterns are implemented using decorators on handler methods:
@request_response: Indicates that a method handles a request and returns a single response.@request_stream: Indicates that a method handles a request and returns a stream of responses.
When a client connects to the server:
- The server creates a
WebSocketNetworkProtocolinstance - The protocol creates a
ProtocolHandlerinstance (typically anAzadAgent) - The protocol routes client messages to the appropriate handler methods
- The handler processes the messages and returns responses
- The protocol sends the responses back to the client
Connection States¶
The Slipstream package manages connection states to ensure reliable communication:
ConnectionState.CONNECTING: The connection is being establishedConnectionState.CONNECTED: The connection is established and ready for communicationConnectionState.DISCONNECTING: The connection is being closedConnectionState.DISCONNECTED: The connection is closed
Error Handling¶
The Slipstream package provides error handling for network communication:
ConnectionClosedError: Raised when a connection is closed unexpectedlyConnectionLostError: Raised when a connection is lost due to network issues
These errors are caught and handled appropriately to ensure graceful degradation of service.