Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8283fb9
Refactor `CopilotClient.create_session()` to have parameters
brettcannon Feb 25, 2026
84372b7
Address PR review comments for create_session refactor
brettcannon Feb 26, 2026
6b03aae
Add test for None permission handler validation
brettcannon Feb 26, 2026
3a6773f
Merge branch 'main' of https://github.com/github/copilot-sdk into cre…
brettcannon Feb 26, 2026
95341f8
Merge remote-tracking branch 'upstream/main' into create_session
brettcannon Feb 27, 2026
402dc80
Merge remote-tracking branch 'upstream/main' into create_session
brettcannon Mar 12, 2026
90b0e46
Merge with main
brettcannon Mar 12, 2026
56b51cd
Resolve merge conflicts with main
brettcannon Mar 13, 2026
768ddc8
Fix test to use SubprocessConfig instead of dict
brettcannon Mar 13, 2026
bae8862
Change the call signature of `resume_session()`
brettcannon Mar 13, 2026
d3295ae
Merge remote-tracking branch 'upstream' into create_session
brettcannon Mar 16, 2026
2b9bdf1
Fix formatting
brettcannon Mar 16, 2026
92d2ef8
Make on_permission_request and model keyword-only in Python SDK
brettcannon Mar 16, 2026
a71f8b0
Fix Python E2E tests for keyword-only create_session parameters
brettcannon Mar 16, 2026
b6c8fd6
Fix formatting
brettcannon Mar 16, 2026
d68f2a4
Format docstrings
brettcannon Mar 16, 2026
ed3954c
Merge remote-tracking branch 'upstream/main' into create_session
brettcannon Mar 18, 2026
efba357
Merge remote-tracking branch 'upstream/main' into create_session
brettcannon Mar 19, 2026
f2af0ae
Fix a merge mistake
brettcannon Mar 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions docs/auth/byok.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Azure AI Foundry (formerly Azure OpenAI) is a common BYOK deployment target for
```python
import asyncio
import os
from copilot import CopilotClient
from copilot import CopilotClient, PermissionHandler

FOUNDRY_MODEL_URL = "https://your-resource.openai.azure.com/openai/v1/"
# Set FOUNDRY_API_KEY environment variable
Expand All @@ -32,14 +32,11 @@ async def main():
client = CopilotClient()
await client.start()

session = await client.create_session({
"model": "gpt-5.2-codex", # Your deployment name
"provider": {
"type": "openai",
"base_url": FOUNDRY_MODEL_URL,
"wire_api": "responses", # Use "completions" for older models
"api_key": os.environ["FOUNDRY_API_KEY"],
},
session = await client.create_session(on_permission_request=PermissionHandler.approve_all, model="gpt-5.2-codex", provider={
"type": "openai",
"base_url": FOUNDRY_MODEL_URL,
"wire_api": "responses", # Use "completions" for older models
"api_key": os.environ["FOUNDRY_API_KEY"],
})

done = asyncio.Event()
Expand Down
19 changes: 10 additions & 9 deletions docs/features/custom-agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ from copilot.types import PermissionRequestResult
client = CopilotClient()
await client.start()

session = await client.create_session({
"model": "gpt-4.1",
"custom_agents": [
session = await client.create_session(
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approved"),
model="gpt-4.1",
custom_agents=[
{
"name": "researcher",
"display_name": "Research Agent",
Expand All @@ -88,8 +89,7 @@ session = await client.create_session({
"prompt": "You are a code editor. Make minimal, surgical changes to files as requested.",
},
],
"on_permission_request": lambda req, inv: PermissionRequestResult(kind="approved"),
})
)
```

</details>
Expand Down Expand Up @@ -258,8 +258,9 @@ const session = await client.createSession({

<!-- docs-validate: skip -->
```python
session = await client.create_session({
"custom_agents": [
session = await client.create_session(
on_permission_request=PermissionHandler.approve_all,
custom_agents=[
{
"name": "researcher",
"prompt": "You are a research assistant. Analyze code and answer questions.",
Expand All @@ -269,8 +270,8 @@ session = await client.create_session({
"prompt": "You are a code editor. Make minimal, surgical changes.",
},
],
"agent": "researcher", # Pre-select the researcher agent
})
agent="researcher", # Pre-select the researcher agent
)
```

</details>
Expand Down
40 changes: 20 additions & 20 deletions docs/features/hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ from copilot import CopilotClient
client = CopilotClient()
await client.start()

session = await client.create_session({
"hooks": {
session = await client.create_session(
on_permission_request=lambda req, inv: {"kind": "approved"},
hooks={
"on_session_start": on_session_start,
"on_pre_tool_use": on_pre_tool_use,
"on_post_tool_use": on_post_tool_use,
# ... add only the hooks you need
},
"on_permission_request": lambda req, inv: {"kind": "approved"},
})
)
```

</details>
Expand Down Expand Up @@ -245,10 +245,10 @@ async def on_pre_tool_use(input_data, invocation):
}
return {"permissionDecision": "allow"}

session = await client.create_session({
"hooks": {"on_pre_tool_use": on_pre_tool_use},
"on_permission_request": lambda req, inv: {"kind": "approved"},
})
session = await client.create_session(
on_permission_request=lambda req, inv: {"kind": "approved"},
hooks={"on_pre_tool_use": on_pre_tool_use},
)
```

</details>
Expand Down Expand Up @@ -567,16 +567,16 @@ async def on_session_end(input_data, invocation):
await f.write(json.dumps(audit_log, indent=2))
return None

session = await client.create_session({
"hooks": {
session = await client.create_session(
on_permission_request=lambda req, inv: {"kind": "approved"},
hooks={
"on_session_start": on_session_start,
"on_user_prompt_submitted": on_user_prompt_submitted,
"on_pre_tool_use": on_pre_tool_use,
"on_post_tool_use": on_post_tool_use,
"on_session_end": on_session_end,
},
"on_permission_request": lambda req, inv: {"kind": "approved"},
})
)
```

</details>
Expand Down Expand Up @@ -666,13 +666,13 @@ async def on_error_occurred(input_data, invocation):
])
return None

session = await client.create_session({
"hooks": {
session = await client.create_session(
on_permission_request=lambda req, inv: {"kind": "approved"},
hooks={
"on_session_end": on_session_end,
"on_error_occurred": on_error_occurred,
},
"on_permission_request": lambda req, inv: {"kind": "approved"},
})
)
```

</details>
Expand Down Expand Up @@ -905,15 +905,15 @@ async def on_session_end(input_data, invocation):
)
return None

session = await client.create_session({
"hooks": {
session = await client.create_session(
on_permission_request=lambda req, inv: {"kind": "approved"},
hooks={
"on_session_start": on_session_start,
"on_user_prompt_submitted": on_user_prompt_submitted,
"on_pre_tool_use": on_pre_tool_use,
"on_session_end": on_session_end,
},
"on_permission_request": lambda req, inv: {"kind": "approved"},
})
)
```

</details>
Expand Down
8 changes: 4 additions & 4 deletions docs/features/image-input.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ from copilot.types import PermissionRequestResult
client = CopilotClient()
await client.start()

session = await client.create_session({
"model": "gpt-4.1",
"on_permission_request": lambda req, inv: PermissionRequestResult(kind="approved"),
})
session = await client.create_session(
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approved"),
model="gpt-4.1",
)

await session.send(
"Describe what you see in this image",
Expand Down
39 changes: 18 additions & 21 deletions docs/features/mcp.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,32 +59,29 @@ const session = await client.createSession({

```python
import asyncio
from copilot import CopilotClient
from copilot import CopilotClient, PermissionHandler

async def main():
client = CopilotClient()
await client.start()

session = await client.create_session({
"model": "gpt-5",
"mcp_servers": {
# Local MCP server (stdio)
"my-local-server": {
"type": "local",
"command": "python",
"args": ["./mcp_server.py"],
"env": {"DEBUG": "true"},
"cwd": "./servers",
"tools": ["*"],
"timeout": 30000,
},
# Remote MCP server (HTTP)
"github": {
"type": "http",
"url": "https://api.githubcopilot.com/mcp/",
"headers": {"Authorization": "Bearer ${TOKEN}"},
"tools": ["*"],
},
session = await client.create_session(on_permission_request=PermissionHandler.approve_all, model="gpt-5", mcp_servers={
# Local MCP server (stdio)
"my-local-server": {
"type": "local",
"command": "python",
"args": ["./mcp_server.py"],
"env": {"DEBUG": "true"},
"cwd": "./servers",
"tools": ["*"],
"timeout": 30000,
},
# Remote MCP server (HTTP)
"github": {
"type": "http",
"url": "https://api.githubcopilot.com/mcp/",
"headers": {"Authorization": "Bearer ${TOKEN}"},
"tools": ["*"],
},
})

Expand Down
9 changes: 3 additions & 6 deletions docs/features/session-persistence.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,13 @@ await session.sendAndWait({ prompt: "Analyze my codebase" });
### Python

```python
from copilot import CopilotClient
from copilot import CopilotClient, PermissionHandler

client = CopilotClient()
await client.start()

# Create a session with a meaningful ID
session = await client.create_session({
"session_id": "user-123-task-456",
"model": "gpt-5.2-codex",
})
session = await client.create_session(on_permission_request=PermissionHandler.approve_all, model="gpt-5.2-codex", session_id="user-123-task-456")

# Do some work...
await session.send_and_wait({"prompt": "Analyze my codebase"})
Expand Down Expand Up @@ -160,7 +157,7 @@ await session.sendAndWait({ prompt: "What did we discuss earlier?" });

```python
# Resume from a different client instance (or after restart)
session = await client.resume_session("user-123-task-456")
session = await client.resume_session("user-123-task-456", on_permission_request=PermissionHandler.approve_all)

# Continue where you left off
await session.send_and_wait({"prompt": "What did we discuss earlier?"})
Expand Down
21 changes: 12 additions & 9 deletions docs/features/skills.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ async def main():
client = CopilotClient()
await client.start()

session = await client.create_session({
"model": "gpt-4.1",
"skill_directories": [
session = await client.create_session(
on_permission_request=lambda req, inv: {"kind": "approved"},
model="gpt-4.1",
skill_directories=[
"./skills/code-review",
"./skills/documentation",
],
"on_permission_request": lambda req, inv: PermissionRequestResult(kind="approved"),
})
)

# Copilot now has access to skills in those directories
await session.send_and_wait({"prompt": "Review this code for security issues"})
Expand Down Expand Up @@ -160,10 +160,13 @@ const session = await client.createSession({
<summary><strong>Python</strong></summary>

```python
session = await client.create_session({
"skill_directories": ["./skills"],
"disabled_skills": ["experimental-feature", "deprecated-tool"],
})
from copilot import PermissionHandler

session = await client.create_session(
on_permission_request=PermissionHandler.approve_all,
skill_directories=["./skills"],
disabled_skills=["experimental-feature", "deprecated-tool"],
)
```

</details>
Expand Down
24 changes: 12 additions & 12 deletions docs/features/steering-and-queueing.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ async def main():
client = CopilotClient()
await client.start()

session = await client.create_session({
"model": "gpt-4.1",
"on_permission_request": lambda req, inv: PermissionRequestResult(kind="approved"),
})
session = await client.create_session(
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approved"),
model="gpt-4.1",
)

# Start a long-running task
msg_id = await session.send({
Expand Down Expand Up @@ -235,10 +235,10 @@ async def main():
client = CopilotClient()
await client.start()

session = await client.create_session({
"model": "gpt-4.1",
"on_permission_request": lambda req, inv: PermissionRequestResult(kind="approved"),
})
session = await client.create_session(
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approved"),
model="gpt-4.1",
)

# Send an initial task
await session.send({"prompt": "Set up the project structure"})
Expand Down Expand Up @@ -431,10 +431,10 @@ await session.send({
<summary><strong>Python</strong></summary>

```python
session = await client.create_session({
"model": "gpt-4.1",
"on_permission_request": lambda req, inv: PermissionRequestResult(kind="approved"),
})
session = await client.create_session(
on_permission_request=lambda req, inv: PermissionRequestResult(kind="approved"),
model="gpt-4.1",
)

# Start a task
await session.send({"prompt": "Refactor the database layer"})
Expand Down
Loading
Loading