Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
2 changes: 1 addition & 1 deletion docs/auth/byok.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ const client = new CopilotClient({

```python
from copilot import CopilotClient
from copilot.types import ModelInfo, ModelCapabilities, ModelSupports, ModelLimits
from copilot.client import ModelInfo, ModelCapabilities, ModelSupports, ModelLimits

client = CopilotClient({
"on_list_models": lambda: [
Expand Down
2 changes: 1 addition & 1 deletion docs/features/custom-agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const session = await client.createSession({

```python
from copilot import CopilotClient
from copilot.types import PermissionRequestResult
from copilot.session import PermissionRequestResult

client = CopilotClient()
await client.start()
Expand Down
2 changes: 1 addition & 1 deletion docs/features/image-input.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ await session.send({

```python
from copilot import CopilotClient
from copilot.types import PermissionRequestResult
from copilot.session import PermissionRequestResult

client = CopilotClient()
await client.start()
Expand Down
2 changes: 1 addition & 1 deletion docs/features/skills.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ await session.sendAndWait({ prompt: "Review this code for security issues" });

```python
from copilot import CopilotClient
from copilot.types import PermissionRequestResult
from copilot.session import PermissionRequestResult

async def main():
client = CopilotClient()
Expand Down
4 changes: 2 additions & 2 deletions docs/features/steering-and-queueing.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ await session.send({

```python
from copilot import CopilotClient
from copilot.types import PermissionRequestResult
from copilot.session import PermissionRequestResult

async def main():
client = CopilotClient()
Expand Down Expand Up @@ -229,7 +229,7 @@ await session.send({

```python
from copilot import CopilotClient
from copilot.types import PermissionRequestResult
from copilot.session import PermissionRequestResult

async def main():
client = CopilotClient()
Expand Down
15 changes: 10 additions & 5 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ Create `main.py`:

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

async def main():
client = CopilotClient()
Expand Down Expand Up @@ -275,7 +276,8 @@ Update `main.py`:
```python
import asyncio
import sys
from copilot import CopilotClient, PermissionHandler
from copilot import CopilotClient
from copilot.session import PermissionHandler
from copilot.generated.session_events import SessionEventType

async def main():
Expand Down Expand Up @@ -651,7 +653,8 @@ Update `main.py`:
import asyncio
import random
import sys
from copilot import CopilotClient, PermissionHandler
from copilot import CopilotClient
from copilot.session import PermissionHandler
from copilot.tools import define_tool
from copilot.generated.session_events import SessionEventType
from pydantic import BaseModel, Field
Expand Down Expand Up @@ -919,7 +922,8 @@ Create `weather_assistant.py`:
import asyncio
import random
import sys
from copilot import CopilotClient, PermissionHandler
from copilot import CopilotClient
from copilot.session import PermissionHandler
from copilot.tools import define_tool
from copilot.generated.session_events import SessionEventType
from pydantic import BaseModel, Field
Expand Down Expand Up @@ -1312,7 +1316,8 @@ const session = await client.createSession({ onPermissionRequest: approveAll });
<summary><strong>Python</strong></summary>

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

client = CopilotClient({
"cli_url": "localhost:4321"
Expand Down
2 changes: 1 addition & 1 deletion docs/hooks/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type ErrorOccurredHandler = (

<!-- docs-validate: hidden -->
```python
from copilot.types import ErrorOccurredHookInput, HookInvocation, ErrorOccurredHookOutput
from copilot.session import ErrorOccurredHookInput, ErrorOccurredHookOutput
from typing import Callable, Awaitable

ErrorOccurredHandler = Callable[
Expand Down
2 changes: 1 addition & 1 deletion docs/hooks/post-tool-use.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type PostToolUseHandler = (

<!-- docs-validate: hidden -->
```python
from copilot.types import PostToolUseHookInput, HookInvocation, PostToolUseHookOutput
from copilot.session import PostToolUseHookInput, PostToolUseHookOutput
from typing import Callable, Awaitable

PostToolUseHandler = Callable[
Expand Down
2 changes: 1 addition & 1 deletion docs/hooks/pre-tool-use.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type PreToolUseHandler = (

<!-- docs-validate: hidden -->
```python
from copilot.types import PreToolUseHookInput, HookInvocation, PreToolUseHookOutput
from copilot.session import PreToolUseHookInput, PreToolUseHookOutput
from typing import Callable, Awaitable

PreToolUseHandler = Callable[
Expand Down
4 changes: 2 additions & 2 deletions docs/hooks/session-lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type SessionStartHandler = (

<!-- docs-validate: hidden -->
```python
from copilot.types import SessionStartHookInput, HookInvocation, SessionStartHookOutput
from copilot.session import SessionStartHookInput, SessionStartHookOutput
from typing import Callable, Awaitable

SessionStartHandler = Callable[
Expand Down Expand Up @@ -249,7 +249,7 @@ type SessionEndHandler = (

<!-- docs-validate: hidden -->
```python
from copilot.types import SessionEndHookInput, HookInvocation
from copilot.session import SessionEndHookInput
from typing import Callable, Awaitable

SessionEndHandler = Callable[
Expand Down
2 changes: 1 addition & 1 deletion docs/hooks/user-prompt-submitted.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type UserPromptSubmittedHandler = (

<!-- docs-validate: hidden -->
```python
from copilot.types import UserPromptSubmittedHookInput, HookInvocation, UserPromptSubmittedHookOutput
from copilot.session import UserPromptSubmittedHookInput, UserPromptSubmittedHookOutput
from typing import Callable, Awaitable

UserPromptSubmittedHandler = Callable[
Expand Down
46 changes: 26 additions & 20 deletions docs/setup/azure-managed-identity.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ import asyncio
import os

from azure.identity import DefaultAzureCredential
from copilot import CopilotClient, PermissionHandler
from copilot import CopilotClient
from copilot.session import ProviderConfig, SessionConfig

COGNITIVE_SERVICES_SCOPE = "https://cognitiveservices.azure.com/.default"

Expand All @@ -58,14 +59,15 @@ async def main():
await client.start()

session = await client.create_session(
on_permission_request=PermissionHandler.approve_all,
model="gpt-4.1",
provider={
"type": "openai",
"base_url": f"{foundry_url.rstrip('/')}/openai/v1/",
"bearer_token": token, # Short-lived bearer token
"wire_api": "responses",
},
SessionConfig(
model="gpt-4.1",
provider=ProviderConfig(
type="openai",
base_url=f"{foundry_url.rstrip('/')}/openai/v1/",
bearer_token=token, # Short-lived bearer token
wire_api="responses",
),
)
)

response = await session.send_and_wait({"prompt": "Hello from Managed Identity!"})
Expand All @@ -83,7 +85,8 @@ Bearer tokens expire (typically after ~1 hour). For servers or long-running agen

```python
from azure.identity import DefaultAzureCredential
from copilot import CopilotClient, PermissionHandler
from copilot import CopilotClient
from copilot.session import ProviderConfig, SessionConfig

COGNITIVE_SERVICES_SCOPE = "https://cognitiveservices.azure.com/.default"

Expand All @@ -97,21 +100,24 @@ class ManagedIdentityCopilotAgent:
self.credential = DefaultAzureCredential()
self.client = CopilotClient()

def _get_provider_config(self) -> dict:
"""Build a provider config dict with a fresh bearer token."""
def _get_session_config(self) -> SessionConfig:
"""Build a SessionConfig with a fresh bearer token."""
token = self.credential.get_token(COGNITIVE_SERVICES_SCOPE).token
return {
"type": "openai",
"base_url": f"{self.foundry_url}/openai/v1/",
"bearer_token": token,
"wire_api": "responses",
}
return SessionConfig(
model=self.model,
provider=ProviderConfig(
type="openai",
base_url=f"{self.foundry_url}/openai/v1/",
bearer_token=token,
wire_api="responses",
),
)

async def chat(self, prompt: str) -> str:
"""Send a prompt and return the response text."""
# Fresh token for each session
provider = self._get_provider_config()
session = await self.client.create_session(on_permission_request=PermissionHandler.approve_all, model=self.model, provider=provider)
config = self._get_session_config()
session = await self.client.create_session(config)

response = await session.send_and_wait({"prompt": prompt})
await session.disconnect()
Expand Down
Loading
Loading