Skip to content

Commit 7509191

Browse files
authored
Merge pull request #987 from realpython/update/microsoft-copilot-sdk
Rename github-copilot-sdk to copilot-sdk and update to SDK 2.0
2 parents e4f0a1f + a53457b commit 7509191

11 files changed

Lines changed: 29 additions & 17 deletions

File tree

‎copilot-sdk/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Copilot SDK: Put a Coding Agent in Your Python Code
2+
3+
This folder provides the code examples for the Real Python tutorial [Copilot SDK: Put a Coding Agent in Your Python Code](https://realpython.com/copilot-sdk/)
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,12 @@ def policy(request, invocation):
2828

2929
async def main() -> int:
3030
token = os.environ["COPILOT_GITHUB_TOKEN"]
31-
async with CopilotClient(github_token=token) as client:
31+
async with CopilotClient(
32+
mode="coding-agent",
33+
github={"token": token},
34+
) as client:
3235
session = await client.create_session(
33-
on_permission_request=policy,
36+
permissions={"on_request": policy},
3437
model="claude-haiku-5.5",
3538
)
3639
reply = await session.send_and_wait(
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@
66

77
async def main():
88
token = os.environ["COPILOT_GITHUB_TOKEN"]
9-
async with CopilotClient(github_token=token) as client:
9+
async with CopilotClient(
10+
mode="coding-agent",
11+
github={"token": token},
12+
) as client:
1013
session = await client.create_session(
11-
on_permission_request=PermissionHandler.approve_all,
14+
permissions={"on_request": PermissionHandler.approve_all},
1215
model="claude-haiku-5.5",
1316
)
1417
reply = await session.send_and_wait(
1518
"What is the walrus operator in Python? One sentence."
1619
)
17-
print(reply.data.content)
20+
print(reply.data.content if reply else "No reply")
1821
await session.disconnect()
1922

2023

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,19 @@ async def list_issues(params: ListIssuesParams):
2727

2828
async def main():
2929
token = os.environ["COPILOT_GITHUB_TOKEN"]
30-
async with CopilotClient(github_token=token) as client:
30+
async with CopilotClient(
31+
mode="coding-agent",
32+
github={"token": token},
33+
) as client:
3134
session = await client.create_session(
32-
tools=[list_issues],
33-
on_permission_request=PermissionHandler.approve_all,
35+
tools={"definitions": [list_issues]},
36+
permissions={"on_request": PermissionHandler.approve_all},
3437
model="claude-haiku-5.5",
3538
)
3639
reply = await session.send_and_wait(
3740
"Which open bugs are assigned to Ana? Use the tracker tool."
3841
)
39-
print(reply.data.content)
42+
print(reply.data.content if reply else "No reply")
4043
await session.disconnect()
4144

4245

File renamed without changes.
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ async def main():
2727
shutil.copytree(PROJECT, workdir)
2828
print(f"Working in {workdir}")
2929
token = os.environ["COPILOT_GITHUB_TOKEN"]
30-
async with CopilotClient(github_token=token) as client:
30+
async with CopilotClient(
31+
mode="coding-agent",
32+
github={"token": token},
33+
) as client:
3134
session = await client.create_session(
32-
streaming=True,
35+
events={"streaming": True},
3336
working_directory=str(workdir),
34-
on_permission_request=PermissionHandler.approve_all,
37+
permissions={"on_request": PermissionHandler.approve_all},
3538
model="claude-haiku-5.5",
3639
)
3740
session.on(on_event)

‎copilot-sdk/requirements.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
microsoft-copilot-sdk==2.0.6
2+
pydantic==2.14.4

‎github-copilot-sdk/README.md‎

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)