diff --git a/copilot-sdk/README.md b/copilot-sdk/README.md new file mode 100644 index 0000000000..876899d644 --- /dev/null +++ b/copilot-sdk/README.md @@ -0,0 +1,3 @@ +# Copilot SDK: Put a Coding Agent in Your Python Code + +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/) diff --git a/github-copilot-sdk/ci_agent.py b/copilot-sdk/ci_agent.py similarity index 89% rename from github-copilot-sdk/ci_agent.py rename to copilot-sdk/ci_agent.py index 9ea2a1c223..aff89b50eb 100644 --- a/github-copilot-sdk/ci_agent.py +++ b/copilot-sdk/ci_agent.py @@ -28,9 +28,12 @@ def policy(request, invocation): async def main() -> int: token = os.environ["COPILOT_GITHUB_TOKEN"] - async with CopilotClient(github_token=token) as client: + async with CopilotClient( + mode="coding-agent", + github={"token": token}, + ) as client: session = await client.create_session( - on_permission_request=policy, + permissions={"on_request": policy}, model="claude-haiku-5.5", ) reply = await session.send_and_wait( diff --git a/github-copilot-sdk/hello_agent.py b/copilot-sdk/hello_agent.py similarity index 65% rename from github-copilot-sdk/hello_agent.py rename to copilot-sdk/hello_agent.py index 8c3fb1a28c..86c940f591 100644 --- a/github-copilot-sdk/hello_agent.py +++ b/copilot-sdk/hello_agent.py @@ -6,15 +6,18 @@ async def main(): token = os.environ["COPILOT_GITHUB_TOKEN"] - async with CopilotClient(github_token=token) as client: + async with CopilotClient( + mode="coding-agent", + github={"token": token}, + ) as client: session = await client.create_session( - on_permission_request=PermissionHandler.approve_all, + permissions={"on_request": PermissionHandler.approve_all}, model="claude-haiku-5.5", ) reply = await session.send_and_wait( "What is the walrus operator in Python? One sentence." ) - print(reply.data.content) + print(reply.data.content if reply else "No reply") await session.disconnect() diff --git a/github-copilot-sdk/issue_agent.py b/copilot-sdk/issue_agent.py similarity index 77% rename from github-copilot-sdk/issue_agent.py rename to copilot-sdk/issue_agent.py index ad08d17fa8..d1614a0c77 100644 --- a/github-copilot-sdk/issue_agent.py +++ b/copilot-sdk/issue_agent.py @@ -27,16 +27,19 @@ async def list_issues(params: ListIssuesParams): async def main(): token = os.environ["COPILOT_GITHUB_TOKEN"] - async with CopilotClient(github_token=token) as client: + async with CopilotClient( + mode="coding-agent", + github={"token": token}, + ) as client: session = await client.create_session( - tools=[list_issues], - on_permission_request=PermissionHandler.approve_all, + tools={"definitions": [list_issues]}, + permissions={"on_request": PermissionHandler.approve_all}, model="claude-haiku-5.5", ) reply = await session.send_and_wait( "Which open bugs are assigned to Ana? Use the tracker tool." ) - print(reply.data.content) + print(reply.data.content if reply else "No reply") await session.disconnect() diff --git a/github-copilot-sdk/project/shopping.py b/copilot-sdk/project/shopping.py similarity index 100% rename from github-copilot-sdk/project/shopping.py rename to copilot-sdk/project/shopping.py diff --git a/github-copilot-sdk/project/test_shopping.py b/copilot-sdk/project/test_shopping.py similarity index 100% rename from github-copilot-sdk/project/test_shopping.py rename to copilot-sdk/project/test_shopping.py diff --git a/github-copilot-sdk/refactor_agent.py b/copilot-sdk/refactor_agent.py similarity index 85% rename from github-copilot-sdk/refactor_agent.py rename to copilot-sdk/refactor_agent.py index f274d62673..1525c52ae9 100644 --- a/github-copilot-sdk/refactor_agent.py +++ b/copilot-sdk/refactor_agent.py @@ -27,11 +27,14 @@ async def main(): shutil.copytree(PROJECT, workdir) print(f"Working in {workdir}") token = os.environ["COPILOT_GITHUB_TOKEN"] - async with CopilotClient(github_token=token) as client: + async with CopilotClient( + mode="coding-agent", + github={"token": token}, + ) as client: session = await client.create_session( - streaming=True, + events={"streaming": True}, working_directory=str(workdir), - on_permission_request=PermissionHandler.approve_all, + permissions={"on_request": PermissionHandler.approve_all}, model="claude-haiku-5.5", ) session.on(on_event) diff --git a/copilot-sdk/requirements.txt b/copilot-sdk/requirements.txt new file mode 100644 index 0000000000..c17c59f0f6 --- /dev/null +++ b/copilot-sdk/requirements.txt @@ -0,0 +1,2 @@ +microsoft-copilot-sdk==2.0.6 +pydantic==2.14.4 diff --git a/github-copilot-sdk/tracker/issues.json b/copilot-sdk/tracker/issues.json similarity index 100% rename from github-copilot-sdk/tracker/issues.json rename to copilot-sdk/tracker/issues.json diff --git a/github-copilot-sdk/README.md b/github-copilot-sdk/README.md deleted file mode 100644 index c8842ba90a..0000000000 --- a/github-copilot-sdk/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# GitHub Copilot SDK: Put a Coding Agent in Your Python Code - -This folder provides the code examples for the Real Python tutorial [GitHub Copilot SDK: Put a Coding Agent in Your Python Code](https://realpython.com/github-copilot-sdk/) diff --git a/github-copilot-sdk/requirements.txt b/github-copilot-sdk/requirements.txt deleted file mode 100644 index 025c457ca8..0000000000 --- a/github-copilot-sdk/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -github-copilot-sdk==1.0.26 -pydantic==2.14.1