The AI has two main factors to decide if it wants to trade with another player (or another AI):
1. If a player is far in the lead or about to win, the AI will trade with that player only in absolutely exceptional cases (e.g. if it could win itself).
2. If you are competing for a place on the board (e.g. both you and the AI could reach a building site within the next turns), the AI will not trade with the player in order to preserve its own chances of reaching it first.