def retrieve_state(self, activity, agent, state_id, registration=None):
        if not isinstance(activity, Activity):
            activity = Activity(activity)
        if not isinstance(agent, Agent):
            agent = Agent(agent)
        request = HTTPRequest(
            method="GET",
            resource="activities/state",
            ignore404=True
        )
        request.query_params = {
            "activityId": activity.id,
            "agent": agent.to_json(self.version),
            "stateId": state_id
        }
        if registration is not None:
            request.query_params["registration"] = registration
        lrs_response = self._send_request(request)
        if lrs_response.success:
            doc = StateDocument(
                id=state_id,
                content=lrs_response.data,
                activity=activity,
                agent=agent
            )
            if registration is not None:
                doc.registration = registration
            headers = lrs_response.response.getheaders()
            if "lastModified" in headers and headers["lastModified"] is not None:
                doc.timestamp = headers["lastModified"]
            if "contentType" in headers and headers["contentType"] is not None:
                doc.content_type = headers["contentType"]
            if "etag" in headers and headers["etag"] is not None:
                doc.etag = headers["etag"]
            lrs_response.content = doc
        return lrs_response