<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_agent(msg):
 """ Handy hack to handle legacy messages where 'agent' was a list. """

    agent = msg['msg']['agent']
    if isinstance(agent, list):
        agent = agent[0]
    return agent