-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Fix Python cookbook recipes to use correct async SDK API #697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Updates the Python Copilot SDK cookbook recipes and docs to match the async, TypedDict-based API shape used by github-copilot-sdk, replacing outdated synchronous/kwargs-style examples.
Changes:
- Convert all 5 runnable Python recipes to
asyncusage (await client.start(),await session.send_and_wait(...), typed events). - Update corresponding markdown docs to reflect the async API and object-based event access.
- Replace deprecated/incorrect session APIs (e.g.,
wait_for_idle()→send_and_wait()).
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| cookbook/copilot-sdk/python/recipe/error_handling.py | Converts the runnable error-handling recipe to async client/session APIs. |
| cookbook/copilot-sdk/python/recipe/persisting_sessions.py | Updates persistence/resumption recipe to async session management and typed options. |
| cookbook/copilot-sdk/python/recipe/multiple_sessions.py | Updates multi-session recipe to async session creation and messaging. |
| cookbook/copilot-sdk/python/recipe/managing_local_files.py | Updates local-files recipe to async workflow and typed event handling. |
| cookbook/copilot-sdk/python/recipe/pr_visualization.py | Updates PR visualization CLI to async session lifecycle, events, and messaging. |
| cookbook/copilot-sdk/python/error-handling.md | Updates documentation snippets to async API patterns (needs some fixes for runnable correctness). |
| cookbook/copilot-sdk/python/persisting-sessions.md | Updates docs for persistence/resume/list/delete/history to async API (some snippets now use top-level await). |
| cookbook/copilot-sdk/python/multiple-sessions.md | Updates docs to async multi-session patterns (some snippets now use top-level await). |
| cookbook/copilot-sdk/python/managing-local-files.md | Updates docs to async patterns and typed events (some follow-up snippets now use top-level await). |
| cookbook/copilot-sdk/python/pr-visualization.md | Updates documentation version of the PR visualization script to async API usage. |
Comments suppressed due to low confidence (8)
cookbook/copilot-sdk/python/managing-local-files.md:112
- Same issue here: this snippet uses
await session.send_and_wait(...)without showing the required async wrapper andsession/target_folderinitialization. Make the snippet runnable standalone or clearly mark it as a continuation of the full example above.
await session.send_and_wait(MessageOptions(prompt=f"""
Look at the files in "{target_folder}" and suggest a logical organization.
Consider:
cookbook/copilot-sdk/python/error-handling.md:47
- The snippet uses
await client.start()directly inside atryblock, butawaitonly works inside anasync defand this block doesn’t defineclient. Make this example self-contained by showingasync def main()(includingclient = CopilotClient()) and running it viaasyncio.run(main()), or explicitly note it must be placed inside the earliermain().
try:
await client.start()
cookbook/copilot-sdk/python/error-handling.md:82
- This block uses top-level
awaitforcreate_session,send,sleep, andabort. As written it’s not valid Python outside anasync def. Consider wrapping the whole example inasync def main()+asyncio.run(main())to keep it runnable.
session = await client.create_session(SessionConfig(model="gpt-5"))
# Start a request (non-blocking send)
await session.send(MessageOptions(prompt="Write a very long story..."))
# Abort it after some condition
await asyncio.sleep(5)
await session.abort()
cookbook/copilot-sdk/python/persisting-sessions.md:64
- The “Listing available sessions” block uses
await client.list_sessions()at top level and assumesclientexists. Wrap in an async function (or include the missing setup) so the example can be copied and run.
sessions = await client.list_sessions()
for s in sessions:
cookbook/copilot-sdk/python/persisting-sessions.md:72
- This “Deleting a session” example uses
await client.delete_session(...)at top level without showing the async wrapper / client setup. Make it a complete runnable snippet (or note required surrounding context).
await client.delete_session("user-123-conversation")
cookbook/copilot-sdk/python/persisting-sessions.md:80
- The “Getting session history” snippet uses
await session.get_messages()but doesn’t show wheresessioncomes from (and uses top-levelawait). Consider folding this into the resumption example or adding a minimalasync def main()that initializesclient/session.
messages = await session.get_messages()
for msg in messages:
print(f"[{msg.type}] {msg.data.content}")
cookbook/copilot-sdk/python/multiple-sessions.md:58
- This “Custom session IDs” snippet uses
awaitat top level and assumes an initializedclient. Wrap it in an async function (and includeawait client.start()), or label it as a continuation from the earlier full example.
session = await client.create_session(SessionConfig(
session_id="user-123-chat",
model="gpt-5"
))
cookbook/copilot-sdk/python/multiple-sessions.md:75
- This “Deleting sessions” snippet uses
await client.delete_session(...)at top level and doesn’t show the surrounding async/client setup. Wrap it inasync def main()+asyncio.run(main())or clarify the required context.
await client.delete_session("user-123-chat")
858c7fc to
baf4beb
Compare
All 5 Python recipes and their markdown docs used a synchronous, kwargs-based API that doesn't match the real github-copilot-sdk: - client.start() -> await client.start() (all methods are async) - create_session(model=...) -> create_session(SessionConfig(model=...)) - session.send(prompt=...) -> session.send(MessageOptions(prompt=...)) - session.wait_for_idle() -> session.send_and_wait() (wait_for_idle doesn't exist) - event['type']/event['data']['content'] -> event.type/event.data.content - All code wrapped in async def main() + asyncio.run(main()) Verified all imports resolve against github-copilot-sdk.
baf4beb to
c65e8ab
Compare
Problem
All 5 Python cookbook recipes and their corresponding markdown documentation use a synchronous, kwargs-based API that doesn't match the real github-copilot-sdk package.
Issues found
Files changed (10)
Recipes: error_handling.py, persisting_sessions.py, multiple_sessions.py, managing_local_files.py, pr_visualization.py
Documentation: error-handling.md, persisting-sessions.md, multiple-sessions.md, managing-local-files.md, pr-visualization.md
Verification
All imports verified against installed github-copilot-sdk package.