MCPcopy Create free account
hub / github.com/github/awesome-copilot / main

Function main

cookbook/copilot-sdk/python/recipe/multiple_sessions.py:6–40  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4from copilot import CopilotClient, SessionConfig, MessageOptions, PermissionHandler
5
6async def main():
7 client = CopilotClient()
8 await client.start()
9
10 # Create multiple independent sessions
11 session1 = await client.create_session(SessionConfig(model="gpt-5",
12 on_permission_request=PermissionHandler.approve_all))
13 session2 = await client.create_session(SessionConfig(model="gpt-5",
14 on_permission_request=PermissionHandler.approve_all))
15 session3 = await client.create_session(SessionConfig(model="claude-sonnet-4.5",
16 on_permission_request=PermissionHandler.approve_all))
17
18 print("Created 3 independent sessions")
19
20 # Each session maintains its own conversation history
21 await session1.send(MessageOptions(prompt="You are helping with a Python project"))
22 await session2.send(MessageOptions(prompt="You are helping with a TypeScript project"))
23 await session3.send(MessageOptions(prompt="You are helping with a Go project"))
24
25 print("Sent initial context to all sessions")
26
27 # Follow-up messages stay in their respective contexts
28 await session1.send(MessageOptions(prompt="How do I create a virtual environment?"))
29 await session2.send(MessageOptions(prompt="How do I set up tsconfig?"))
30 await session3.send(MessageOptions(prompt="How do I initialize a module?"))
31
32 print("Sent follow-up questions to each session")
33
34 # Clean up all sessions
35 await session1.destroy()
36 await session2.destroy()
37 await session3.destroy()
38 await client.stop()
39
40 print("All sessions destroyed successfully")
41
42if __name__ == "__main__":
43 asyncio.run(main())

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected