Skip to content

Commit 6e13513

Browse files
committed
updating rest api
1 parent 699d00b commit 6e13513

File tree

1 file changed

+66
-61
lines changed

1 file changed

+66
-61
lines changed

articles/ai-services/agents/how-to/tools/sharepoint-samples.md

Lines changed: 66 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -17,76 +17,81 @@ zone_pivot_groups: selection-sharepoint
1717

1818
Use this article to find step-by-step instructions and code samples for using the Sharepoint tool in Azure AI Foundry Agent Service.
1919

20-
## Step 1: Create a project client
21-
22-
Create a client object, which will contain the connection string for connecting to your AI project and other resources.
23-
24-
```python
25-
import os
26-
from azure.ai.projects import AIProjectClient
27-
from azure.identity import DefaultAzureCredential
28-
from azure.ai.projects.models import SharepointTool
20+
## Step 1: Create an agent
21+
22+
Follow the [REST API Quickstart](../../quickstart.md?pivots=rest-api#api-call-information) to set the right values for the environment variables `AGENT_TOKEN`, `AZURE_AI_FOUNDRY_PROJECT_ENDPOINT` and `API_VERSION`.
23+
24+
```bash
25+
curl --request POST \
26+
--url $AZURE_AI_FOUNDRY_PROJECT_ENDPOINT/assistants?api-version=$API_VERSION \
27+
-H "Authorization: Bearer $AGENT_TOKEN" \
28+
-H "Content-Type: application/json" \
29+
-d '{
30+
"instructions": "You are a helpful agent.",
31+
"name": "my-agent",
32+
"model": "gpt-4o",
33+
"tools": [
34+
{
35+
"type": "sharepoint_grounding",
36+
"sharepoint_grounding": {
37+
"connections": [
38+
{
39+
"connection_id": "/subscriptions/<sub-id>/resourceGroups/<your-rg-name>/providers/Microsoft.CognitiveServices/accounts/<your-ai-services-name>/projects/<your-project-name>/connections/<your-sharepoint-connection-name>"
40+
}
41+
]
42+
}
43+
}
44+
]
45+
}'
2946
```
3047

31-
## Step 2: Create an Agent with the SharePoint tool enabled
32-
33-
To make the SharePoint tool available to your agent, use a connection to initialize the tool and attach it to the agent. You can find your connection in the **connected resources** section of your project in the Azure AI Foundry portal.
48+
## Create a thread
3449

35-
```python
36-
# Initialize Sharepoint tool with connection id
37-
sharepoint_connection = project_client.connections.get(
38-
connection_name="CONNECTION_NAME",
39-
)
40-
conn_id = sharepoint_connection.id
41-
print(conn_id)
42-
sharepoint = SharepointTool(connection_id=conn_id)
43-
44-
# Create agent with SharePoint tool and process assistant run
45-
with project_client:
46-
agent = project_client.agents.create_agent(
47-
model=os.environ["MODEL_NAME"],
48-
name="my-assistant",
49-
instructions="You are a helpful assistant",
50-
tools=sharepoint.definitions,
51-
headers={"x-ms-enable-preview": "true"},
52-
)
53-
print(f"Created agent, ID: {agent.id}")
50+
```bash
51+
curl --request POST \
52+
--url $AZURE_AI_FOUNDRY_PROJECT_ENDPOINT/threads?api-version=$API_VERSION \
53+
-H "Authorization: Bearer $AGENT_TOKEN" \
54+
-H "Content-Type: application/json" \
55+
-d ''
5456
```
5557

56-
## Step 3: Create a thread
57-
58-
```python
59-
# Create thread for communication
60-
thread = project_client.agents.create_thread()
61-
print(f"Created thread, ID: {thread.id}")
62-
63-
# Create message to thread
64-
# Remember to update the message with your data
65-
message = project_client.agents.create_message(
66-
thread_id=thread.id,
67-
role="user",
68-
content="<ask questions specific to your SharePoint documents>",
69-
)
70-
print(f"Created message, ID: {message.id}")
58+
### Add a user question to the thread
59+
60+
```bash
61+
curl --request POST \
62+
--url $AZURE_AI_FOUNDRY_PROJECT_ENDPOINT/threads/thread_abc123/messages?api-version=$API_VERSION \
63+
-H "Authorization: Bearer $AGENT_TOKEN" \
64+
-H "Content-Type: application/json" \
65+
-d '{
66+
"role": "user",
67+
"content": "What is the weather in Seattle?"
68+
}'
7169
```
7270

73-
## Step 4: Create a run and check the output
71+
## Run the thread
7472

75-
Create a run and observe that the model uses the SharePoint tool to provide a response to the user's question.
73+
```bash
74+
curl --request POST \
75+
--url $AZURE_AI_FOUNDRY_PROJECT_ENDPOINT/threads/thread_abc123/runs?api-version=$API_VERSION \
76+
-H "Authorization: Bearer $AGENT_TOKEN" \
77+
-H "Content-Type: application/json" \
78+
-d '{
79+
"assistant_id": "asst_abc123",
80+
}'
81+
```
7682

77-
```python
78-
# Create and process agent run in thread with tools
79-
run = project_client.agents.create_and_process_run(thread_id=thread.id, assistant_id=agent.id)
80-
print(f"Run finished with status: {run.status}")
83+
## Retrieve the status of the run
8184

82-
if run.status == "failed":
83-
print(f"Run failed: {run.last_error}")
85+
```bash
86+
curl --request GET \
87+
--url $AZURE_AI_FOUNDRY_PROJECT_ENDPOINT/threads/thread_abc123/runs/run_abc123?api-version=$API_VERSION \
88+
-H "Authorization: Bearer $AGENT_TOKEN"
89+
```
8490

85-
# Delete the assistant when done
86-
project_client.agents.delete_agent(agent.id)
87-
print("Deleted agent")
91+
## Retrieve the agent response
8892

89-
# Fetch and log all messages
90-
messages = project_client.agents.list_messages(thread_id=thread.id)
91-
print(f"Messages: {messages}")
92-
```
93+
```bash
94+
curl --request GET \
95+
--url $AZURE_AI_FOUNDRY_PROJECT_ENDPOINT/threads/thread_abc123/messages?api-version=$API_VERSION \
96+
-H "Authorization: Bearer $AGENT_TOKEN"
97+
```

0 commit comments

Comments
 (0)