Correct Way to Provide Context to Your AI Agents
If you have spent any time building AI agents, you have probably run into this moment: you tell your agent something important, it responds perfectly, and then one message later it acts like the conversation never happened. Blank slate. No memory. Total amnesia. This is not a quirk. It is how large language models work by design. Every call to the model is stateless. Without explicit history being passed back each time, the model starts fresh on every turn. Context Providers are how the Microsoft Agent Framework solves this — and they do a lot more than just memory. What Is a Context Provider? A Context Provider is a class that wraps around every LLM call your agent makes. It gets two hooks: one before the call and one after. Before the call fires, the provider can inject anything into the conversation — previous messages, today's menu, user preferences, business rules, tool definitions. The LLM sees all of it before generating a response. After the call fires, the provider can ext...