chan_agent: Remove some duplicated code.