<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def find_agent(self, desc):
        '''Gives medium class of the agent if the agency hosts it.'''
        agent_id = (desc.doc_id
                    if IDocument.providedBy(desc)
                    else desc)
        self.log("I'm trying to find the agent with id: %s", agent_id)
        result = first(x for x in self._agents
                       if x._descriptor.doc_id == agent_id)
        return defer.succeed(result)