Study FAQ
How do I preserve a Copilot Studio conversation across turns in a custom app?
Also asked as 2
- How should a client retain Copilot Studio conversation state for one signed-in user?
- How can an application continue an agent conversation without mixing users' context?
Answer
Keep the Copilot Studio conversation's continuation state bound to the signed-in user and the configured agent and environment. The .NET Copilot Studio client sample starts the conversation with StartConversationAsync and sends input with AskQuestionAsync. Choose the client lifetime or explicit state storage so that the next turn uses the same intended conversation. Sharing a stateful client across users can expose one user's context to another.
To initialize app context through the documented web or native integration, wait for the first agent message, then send a custom event and handle it in an OnEventActivity topic. Pass only approved values such as a selected device reference or UI language. Track whether the event was handled before making context-dependent requests. Display returned message activities and handle status activity types separately.
Test a follow-up that depends on an earlier message, and repeat the same steps in a fresh second user's session. Verify the second session receives its own context only. On sign-out, clear continuation state and follow the application's retention rules for cached content. Keep any eventual business request ID separate from conversation state.
Microsoft references
Full explanation
AB-400: Integrating Foundry and Copilot Studio Agents
Study guide · AB-400
Read the full explanation