Enabling Intelligent Interactions between an Agent and an LLM: A Reinforcement Learning Approach