Skip to content

Commit abc8810

Browse files
authored
Merge pull request #275263 from anthonychu/20240513-sessions-update
[Container Apps] Minor updates to sessions
2 parents db171f9 + 57e59c7 commit abc8810

File tree

6 files changed

+80
-61
lines changed

6 files changed

+80
-61
lines changed

articles/container-apps/sessions-code-interpreter.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,22 @@ The identifier must be a string that is 4 to 128 characters long and can contain
102102

103103
### Authentication
104104

105-
Authentication is handled using Microsoft Entra (formerly Azure Active Directory) tokens. Valid Microsoft Entra tokens are generated by an identity belonging to the *Azure ContainerApps Session Creator* or *Contributor* role on the session pool.
105+
Authentication is handled using Microsoft Entra (formerly Azure Active Directory) tokens. Valid Microsoft Entra tokens are generated by an identity belonging to the *Azure ContainerApps Session Creator* and *Contributor* roles on the session pool.
106+
107+
To assign the roles to an identity, use the following Azure CLI commands:
108+
109+
```bash
110+
# Assign the Azure ContainerApps Session Creator role using its ID
111+
az role assignment create \
112+
--role "0fb8eba5-a2bb-4abe-b1c1-49dfad359bb0" \
113+
--assignee <PRINCIPAL_ID> \
114+
--scope <SESSION_POOL_RESOURCE_ID>
115+
116+
az role assignment create \
117+
--role "Contributor" \
118+
--assignee <PRINCIPAL_ID> \
119+
--scope <SESSION_POOL_RESOURCE_ID>
120+
```
106121

107122
If you're using an LLM framework integration, the framework handles the token generation and management for you. Ensure that the application is configured with a managed identity with the necessary role assignments on the session pool.
108123

articles/container-apps/sessions-tutorial-langchain.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ react_agent = agents.create_react_agent(
5959
)
6060
```
6161

62-
When it needs to perform calculations, the agent uses the *SessionPythonREPLTool* to run the code. The code is executed in a session in the session pool. By default, a random session identifier is generated when you instantiate the tool. If the agent runs multiple Python code snippets, it uses the same session.
62+
When it needs to perform calculations, the agent uses the *SessionPythonREPLTool* to run the code. The code is executed in a session in the session pool. By default, a random session identifier is generated when you instantiate the tool. If the agent uses the tool to run multiple Python code snippets, it uses the same session. To ensure each end user has a unique session, use a separate agent and tool for each user.
6363

6464
*SessionPythonREPLTool* is available in the [`langchain-azure-dynamic-sessions`](https://pypi.org/project/langchain-azure-dynamic-sessions/) package.
6565

articles/container-apps/sessions-tutorial-llamaindex.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ code_interpreter_tool = AzureCodeInterpreterToolSpec(
5353
agent = ReActAgent.from_tools(code_interpreter_tool.to_tool_list(), llm=llm, verbose=True)
5454
```
5555

56-
When it needs to perform calculations, the agent uses the code interpreter in *AzureCodeInterpreterToolSpec* to run the code. The code is executed in a session in the session pool. By default, a random session identifier is generated when you instantiate the tool. If the agent runs multiple Python code snippets, it uses the same session.
56+
When it needs to perform calculations, the agent uses the code interpreter in *AzureCodeInterpreterToolSpec* to run the code. The code is executed in a session in the session pool. By default, a random session identifier is generated when you instantiate the tool. If the agent uses the same tool to run multiple Python code snippets, it uses the same session. To ensure each end user has a unique session, use a separate agent and tool for each user.
5757

5858
*AzureCodeInterpreterToolSpec* is available in the [`llama-index-tools-azure-code-interpreter`](https://pypi.org/project/llama-index-tools-azure-code-interpreter/) package.
5959

articles/container-apps/sessions-tutorial-semantic-kernel.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ sessions_tool = SessionsPythonTool(
5454
kernel.add_plugin(sessions_tool, "SessionsTool")
5555
```
5656

57-
When it needs to perform calculations, the agent uses the code interpreter in *SessionsPythonTool* to run the code. The code is executed in a session in the session pool. By default, a random session identifier is generated when you instantiate the tool. If the agent runs multiple Python code snippets, it uses the same session.
57+
When it needs to perform calculations, the kernel uses the code interpreter in *SessionsPythonTool* to run the code. The code is executed in a session in the session pool. By default, a random session identifier is generated when you instantiate the tool. If the kernel uses the tool to run multiple Python code snippets, it uses the same session. To ensure each end user has a unique session, use a separate kernel and tool for each user.
5858

5959
*SessionsPythonTool* is available in version `0.9.8b1` or later of the [`semantic-kernel`](https://pypi.org/project/semantic-kernel/) package.
6060

includes/container-apps/sessions-tutorial-deploy.md

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -42,63 +42,65 @@ You then need to configure managed identity for the app and assign it the proper
4242
--system-assigned
4343
```
4444

45-
1. Retrieve the managed identity's principal ID:
46-
47-
```bash
48-
az containerapp show \
49-
--name $CONTAINER_APP_NAME \
50-
--resource-group $RESOURCE_GROUP_NAME \
51-
--query identity.principalId \
52-
--output tsv
53-
```
54-
55-
1. Retrieve the session pool resource ID:
56-
57-
```bash
58-
az containerapp sessionpool show \
59-
--name $SESSION_POOL_NAME \
60-
--resource-group $RESOURCE_GROUP_NAME \
61-
--query id \
62-
--output tsv
63-
```
64-
65-
1. Assign the managed identity the `Azure ContainerApps Session Creator` and `Contributor` roles on the session pool:
66-
67-
Before you run the following command, replace `<PRINCIPAL_ID>` and `<SESSION_POOL_RESOURCE_ID>` with the values you retrieved in the previous steps.
68-
69-
```bash
70-
# Assign the Azure ContainerApps Session Creator role using its ID
71-
az role assignment create \
72-
--role "0fb8eba5-a2bb-4abe-b1c1-49dfad359bb0" \
73-
--assignee <PRINCIPAL_ID> \
74-
--scope <SESSION_POOL_RESOURCE_ID>
75-
76-
az role assignment create \
77-
--role "Contributor" \
78-
--assignee <PRINCIPAL_ID> \
79-
--scope <SESSION_POOL_RESOURCE_ID>
80-
```
81-
82-
1. Retrieve the Azure OpenAI account resource ID:
83-
84-
```bash
85-
az cognitiveservices account show \
86-
--name $AZURE_OPENAI_NAME \
87-
--resource-group $RESOURCE_GROUP_NAME \
88-
--query id \
89-
--output tsv
90-
```
91-
92-
1. Assign the managed identity the `Cognitive Services OpenAI User` role on the Azure OpenAI account:
93-
94-
Before you run the following command, replace `<PRINCIPAL_ID>` and `<AZURE_OPENAI_RESOURCE_ID>` with the values you retrieved in the previous steps.
95-
96-
```bash
97-
az role assignment create \
98-
--role "Cognitive Services OpenAI User" \
99-
--assignee <PRINCIPAL_ID> \
100-
--scope <AZURE_OPENAI_RESOURCE_ID>
101-
```
45+
1. For the app to access Azure OpenAI and the session pool, you need to assign the managed identity the proper roles.
46+
47+
1. Retrieve the managed identity's principal ID:
48+
49+
```bash
50+
az containerapp show \
51+
--name $CONTAINER_APP_NAME \
52+
--resource-group $RESOURCE_GROUP_NAME \
53+
--query identity.principalId \
54+
--output tsv
55+
```
56+
57+
1. Retrieve the session pool resource ID:
58+
59+
```bash
60+
az containerapp sessionpool show \
61+
--name $SESSION_POOL_NAME \
62+
--resource-group $RESOURCE_GROUP_NAME \
63+
--query id \
64+
--output tsv
65+
```
66+
67+
1. Assign the managed identity the `Azure ContainerApps Session Creator` and `Contributor` roles on the session pool:
68+
69+
Before you run the following command, replace `<PRINCIPAL_ID>` and `<SESSION_POOL_RESOURCE_ID>` with the values you retrieved in the previous steps.
70+
71+
```bash
72+
# Assign the Azure ContainerApps Session Creator role using its ID
73+
az role assignment create \
74+
--role "0fb8eba5-a2bb-4abe-b1c1-49dfad359bb0" \
75+
--assignee <PRINCIPAL_ID> \
76+
--scope <SESSION_POOL_RESOURCE_ID>
77+
78+
az role assignment create \
79+
--role "Contributor" \
80+
--assignee <PRINCIPAL_ID> \
81+
--scope <SESSION_POOL_RESOURCE_ID>
82+
```
83+
84+
1. Retrieve the Azure OpenAI account resource ID:
85+
86+
```bash
87+
az cognitiveservices account show \
88+
--name $AZURE_OPENAI_NAME \
89+
--resource-group $RESOURCE_GROUP_NAME \
90+
--query id \
91+
--output tsv
92+
```
93+
94+
1. Assign the managed identity the `Cognitive Services OpenAI User` role on the Azure OpenAI account:
95+
96+
Before you run the following command, replace `<PRINCIPAL_ID>` and `<AZURE_OPENAI_RESOURCE_ID>` with the values you retrieved in the previous steps.
97+
98+
```bash
99+
az role assignment create \
100+
--role "Cognitive Services OpenAI User" \
101+
--assignee <PRINCIPAL_ID> \
102+
--scope <AZURE_OPENAI_RESOURCE_ID>
103+
```
102104
103105
1. Retrieve the app's fully qualified domain name (FQDN):
104106

includes/container-apps/sessions-tutorial-run-local.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,5 @@ ms.author: antchu
1919
1. Enter `What time is it right now?` in the `message` field and select **Execute**.
2020

2121
The agent responds with the current time. In the terminal, you see the logs showing the agent generated Python code to get the current time and ran it in a code interpreter session.
22+
23+
1. To stop the app, enter `Ctrl+C` in the terminal.

0 commit comments

Comments
 (0)