Skip to content
Open
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(PermissionHandler.approve_all, "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(
lambda req, inv: PermissionRequestResult(kind="approved"),
"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(
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(
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(
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(
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(
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(
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 @@ -70,10 +70,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(
lambda req, inv: PermissionRequestResult(kind="approved"),
"gpt-4.1",
)

await session.send({
"prompt": "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(PermissionHandler.approve_all, "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(PermissionHandler.approve_all, "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", 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(
lambda req, inv: {"kind": "approved"},
"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(
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(
lambda req, inv: PermissionRequestResult(kind="approved"),
"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(
lambda req, inv: PermissionRequestResult(kind="approved"),
"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(
lambda req, inv: PermissionRequestResult(kind="approved"),
"gpt-4.1",
)

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