Align Copilot SDK documentation with permission handling requirements (#1107)

* Apply permission handler requirements across Copilot SDK docs

Co-authored-by: jamesmontemagno <1676321+jamesmontemagno@users.noreply.github.com>
Agent-Logs-Url: https://github.com/jamesmontemagno/awesome-copilot/sessions/adf27a88-92f8-4ca6-b3fe-1204e3bb9963

* Polish permission update formatting in SDK examples

Co-authored-by: jamesmontemagno <1676321+jamesmontemagno@users.noreply.github.com>
Agent-Logs-Url: https://github.com/jamesmontemagno/awesome-copilot/sessions/adf27a88-92f8-4ca6-b3fe-1204e3bb9963

* Fix review comments on SDK permission handling PR

Address 5 review comments from PR #1103:

1. Fix invalid object literal syntax (stray comma) in resumeSession
   example in copilot-sdk-nodejs.instructions.md

2. Replace unused PermissionHandler import with actual usage in
   cookbook/copilot-sdk/python/recipe/ralph_loop.py (was using
   inline lambda instead)

3. Replace unused approveAll import with actual usage in
   cookbook/copilot-sdk/nodejs/recipe/ralph-loop.ts (was using
   inline handler instead)

4. Add missing PermissionHandler import to 4 Python code snippets
   in skills/copilot-sdk/SKILL.md that reference it without importing

5. Add missing approveAll import to 3 TypeScript code snippets
   in skills/copilot-sdk/SKILL.md that reference it without importing

* Refactor session creation to improve code formatting and consistency across SDK examples

* Fix formatting: split multi-property lines and put closing braces on own lines

Address review comments on PR #1107:
- Split OnPermissionRequest + Model onto separate lines in Go, C#, TypeScript
- Put closing }); on its own line consistently across all examples
- Fix indentation in SKILL.md Quick Start, CLI URL, Error Handling sections
- Fix cookbook Go multiple-sessions and error-handling formatting
- Fix ralph-loop.md TypeScript indentation

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jamesmontemagno <1676321+jamesmontemagno@users.noreply.github.com>
This commit is contained in:
James Montemagno
2026-03-22 17:11:19 -07:00
committed by GitHub
parent 6d48c08215
commit 33f544c71d
48 changed files with 376 additions and 143 deletions

View File

@@ -30,7 +30,7 @@ uv add github-copilot-sdk
### Basic Client Setup
```python
from copilot import CopilotClient
from copilot import CopilotClient, PermissionHandler
import asyncio
async def main():
@@ -82,6 +82,7 @@ Use a dict for SessionConfig:
```python
session = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"model": "gpt-5",
"streaming": True,
"tools": [...],
@@ -113,6 +114,7 @@ session = await client.create_session({
```python
session = await client.resume_session("session-id", {
"on_permission_request": PermissionHandler.approve_all,
"tools": [my_new_tool]
})
```
@@ -195,6 +197,7 @@ Set `streaming: True` in SessionConfig:
```python
session = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"model": "gpt-5",
"streaming": True
})
@@ -248,6 +251,7 @@ async def fetch_issue(issue_id: str):
return {"id": issue_id, "status": "open"}
session = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"model": "gpt-5",
"tools": [
define_tool(
@@ -281,6 +285,7 @@ async def get_weather(args: WeatherArgs, inv):
return {"temperature": 72, "units": args.units}
session = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"tools": [
define_tool(
name="get_weather",
@@ -331,6 +336,7 @@ When Copilot invokes a tool, the client automatically:
```python
session = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"model": "gpt-5",
"system_message": {
"mode": "append",
@@ -348,6 +354,7 @@ session = await client.create_session({
```python
session = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"model": "gpt-5",
"system_message": {
"mode": "replace",
@@ -392,8 +399,14 @@ await session.send({
Sessions are independent and can run concurrently:
```python
session1 = await client.create_session({"model": "gpt-5"})
session2 = await client.create_session({"model": "claude-sonnet-4.5"})
session1 = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"model": "gpt-5",
})
session2 = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"model": "claude-sonnet-4.5",
})
await asyncio.gather(
session1.send({"prompt": "Hello from session 1"}),
@@ -407,6 +420,7 @@ Use custom API providers via `provider`:
```python
session = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"provider": {
"type": "openai",
"base_url": "https://api.openai.com/v1",
@@ -436,7 +450,7 @@ await client.delete_session(session_id)
```python
last_id = await client.get_last_session_id()
if last_id:
session = await client.resume_session(last_id)
session = await client.resume_session(last_id, on_permission_request=PermissionHandler.approve_all)
```
### Checking Connection State
@@ -452,7 +466,7 @@ state = client.get_state()
```python
try:
session = await client.create_session()
session = await client.create_session(on_permission_request=PermissionHandler.approve_all)
await session.send({"prompt": "Hello"})
except Exception as e:
print(f"Error: {e}")
@@ -487,7 +501,7 @@ ALWAYS use async context managers for automatic cleanup:
```python
async with CopilotClient() as client:
async with await client.create_session() as session:
async with await client.create_session(on_permission_request=PermissionHandler.approve_all) as session:
# Use session...
await session.send({"prompt": "Hello"})
# Session automatically destroyed
@@ -500,7 +514,7 @@ async with CopilotClient() as client:
client = CopilotClient()
try:
await client.start()
session = await client.create_session()
session = await client.create_session(on_permission_request=PermissionHandler.approve_all)
try:
# Use session...
pass
@@ -529,12 +543,15 @@ finally:
### Simple Query-Response
```python
from copilot import CopilotClient
from copilot import CopilotClient, PermissionHandler
import asyncio
async def main():
async with CopilotClient() as client:
async with await client.create_session({"model": "gpt-5"}) as session:
async with await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"model": "gpt-5",
}) as session:
done = asyncio.Event()
def handler(event):
@@ -574,7 +591,7 @@ async def send_and_wait(session, prompt: str):
return result[0] if result else None
async with await client.create_session() as session:
async with await client.create_session(on_permission_request=PermissionHandler.approve_all) as session:
await send_and_wait(session, "What is the capital of France?")
await send_and_wait(session, "What is its population?")
```
@@ -583,7 +600,7 @@ async with await client.create_session() as session:
```python
# Use built-in send_and_wait for simpler synchronous interaction
async with await client.create_session() as session:
async with await client.create_session(on_permission_request=PermissionHandler.approve_all) as session:
response = await session.send_and_wait(
{"prompt": "What is 2+2?"},
timeout=60.0
@@ -616,6 +633,7 @@ async def get_user(args, inv) -> dict:
return asdict(user)
session = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"tools": [
define_tool(
name="get_user",
@@ -697,6 +715,7 @@ options: MessageOptions = {
await session.send(options)
config: SessionConfig = {
"on_permission_request": PermissionHandler.approve_all,
"model": "gpt-5",
"streaming": True
}
@@ -775,7 +794,9 @@ def copilot_tool(
def calculate(expression: str) -> float:
return eval(expression)
session = await client.create_session({"tools": [calculate]})
session = await client.create_session({
"on_permission_request": PermissionHandler.approve_all,
"tools": [calculate]})
```
## Python-Specific Features