Skip to content

Commit b1d12f5

Browse files
author
ecfan
committed
Fix dupe content
1 parent 90c5cae commit b1d12f5

1 file changed

Lines changed: 61 additions & 169 deletions

File tree

articles/logic-apps/add-agent-action-create-run-workflow.md

Lines changed: 61 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ Azure Logic Apps supports 1,400+ connectors and native, built-in data operations
3939

4040
This article shows how to a workflow from Azure Logic Apps as an agent action tool in Foundry. A wizard guides you through how to set up the action. You can then edit the workflow or extend the workflow in the workflow designer for Azure Logic Apps.
4141

42-
> [!NOTE]
43-
>
44-
> This article refers to the [Microsoft Foundry (classic)](/azure/foundry-classic/what-is-foundry#microsoft-foundry-portals) portal. For more information about the new portal, see the new [Microsoft Foundry portal](/azure/foundry/what-is-foundry)?
45-
4642
For more information, see:
4743

4844
- [What is Azure Logic Apps?](/azure/logic-apps/logic-apps-overview)
4945
- [Consumption logic app workflow - Hosting options](/azure/logic-apps/logic-apps-overview#create-and-deploy-to-different-environments)
5046

47+
> [!NOTE]
48+
>
49+
> This article refers to the [Microsoft Foundry (classic)](/azure/foundry-classic/what-is-foundry#microsoft-foundry-portals) portal. For more information about the new portal, see the new [Microsoft Foundry portal](/azure/foundry/what-is-foundry)
50+
5151
## Prerequisites
5252

5353
- An Azure account and subscription. [Get a free Azure account](https://azure.microsoft.com/pricing/purchase-options/azure-account?cid=msft_learn).
@@ -90,10 +90,10 @@ For more information, see:
9090

9191
:::image type="content" source="media/add-agent-action-create-run-workflow/foundry-logic-apps-arch.png" alt-text="Architecture diagram that shows relationship between example agent in Foundry and example logic app workflow in multitenant Azure Logic Apps." border="false" lightbox="media/add-agent-action-create-run-workflow/foundry-logic-apps-arch.png":::
9292

93-
For more information, see:
93+
For more information, see:
9494

95-
- [Quickstart: Create an example Consumption logic app workflow using the Azure portal](/azure/logic-apps/quickstart-create-example-consumption-workflow)
96-
- [What are connectors in Azure Logic Apps](/azure/connectors/introduction)
95+
- [Quickstart: Create an example Consumption logic app workflow using the Azure portal](/azure/logic-apps/quickstart-create-example-consumption-workflow)
96+
- [What are connectors in Azure Logic Apps](/azure/connectors/introduction)
9797

9898
- Set up the following environment variables with information from your Foundry project:
9999

@@ -251,6 +251,20 @@ To try the new agent action by using the **Agents playground**, follow these ste
251251

252252
:::image type="content" source="media/add-agent-action-create-run-workflow/test-action.png" alt-text="Screenshot shows Foundry window with Agents playground page, test prompt about London weather with format instructions, and response." lightbox="media/add-agent-action-create-run-workflow/test-action.png":::
253253

254+
## 6: Delete resources
255+
256+
If you don't need the resources that you created for this guide, delete them so you don't continue getting charged. You can either follow these steps to delete the resource group that contains these resources, or you can delete each resource individually.
257+
258+
1. In the Foundry portal, to remove the action from the agent, next to the action name, select the ellipses (**...**) button, and then select **Remove**.
259+
260+
1. In the [Azure portal](https://portal.azure.com) title bar search box, enter **resource groups**, and select **Resource groups**.
261+
262+
1. Find the resource group that contains your deployed hub resources.
263+
264+
1. On the **Overview** page toolbar, select **Delete resource group**.
265+
266+
1. When the confirmation pane appears, enter the resource group name, and select **Delete**.
267+
254268
:::zone-end
255269

256270
:::zone pivot="python"
@@ -292,41 +306,43 @@ project_client = AIProjectClient(
292306

293307
## 3: Register your logic app
294308

295-
Register your Consumption logic app workflow by providing its name and trigger information. For the sample code, see the [AzureLogicAppTool utility on GitHub](https://github.com/azure-ai-foundry/foundry-samples/blob/main/samples-classic/python/getting-started-agents/logic_apps/user_logic_apps.py).
309+
Register your Consumption logic app resource by providing the trigger name and information. To find the `AzureLogicAppTool` utility code, visit the [full sample on GitHub](https://github.com/azure-ai-foundry/foundry-samples/blob/main/samples-classic/python/getting-started-agents/logic_apps/user_logic_apps.py).
296310

297311
```python
298312
from user_logic_apps import AzureLogicAppTool
299313

300-
# Extract subscription and resource group from environment variables
314+
# Logic app details
315+
LOGIC_APP_NAME = "your_logic_app_name"
316+
TRIGGER_NAME = "your_trigger_name"
317+
318+
# Register the logic app name with the agent tool utility by extracting the following values from environment variables
301319
subscription_id = os.environ["SUBSCRIPTION_ID"]
302320
resource_group = os.environ["resource_group_name"]
303321

304-
# Logic app details
305-
logic_app_name = "<LOGIC_APP_NAME>"
306-
trigger_name = "<TRIGGER_NAME>"
307-
308322
# Create and initialize AzureLogicAppTool utility
309323
logic_app_tool = AzureLogicAppTool(subscription_id, resource_group)
310-
logic_app_tool.register_logic_app(logic_app_name, trigger_name)
311-
print(f"Registered logic app '{logic_app_name}' with trigger '{trigger_name}'.")
324+
logic_app_tool.register_logic_app(LOGIC_APP_NAME, TRIGGER_NAME)
325+
print(f"Registered logic app '{LOGIC_APP_NAME}' with trigger '{TRIGGER_NAME}'.")
312326
```
313327

314-
## 4: Create an agent and connect a logic app workflow as a tool through an action
328+
## 4: Create an agent with a logic app workflow as an action (tool)
315329

316-
The following code creates an agent and adds an action that runs a logic app workflow as a tool. For this example, the logic app workflow sends an email.
330+
The following code creates an agent and attaches the logic app as an agent action or tool. In this example, the logic app workflow sends an email.
317331

318332
```python
319333
from azure.ai.agents.models import ToolSet, FunctionTool
320334
from user_functions import fetch_current_datetime
321335
from user_logic_apps import create_send_email_function
322336

323-
# Create the specialized "send_email_via_logic_app" function
324-
send_email_func = create_send_email_function(logic_app_tool, logic_app_name)
337+
# Create the logic app action for the agent
338+
send_email_func = create_send_email_function(
339+
logic_app_tool, logic_app_name
340+
)
325341

326-
# Prepare the function tools for the agent
342+
# Prepare the action tool for the agent
327343
functions_to_use = {fetch_current_datetime, send_email_func}
328344

329-
# Create an agent
345+
# Create an agent and assign the toolset
330346
functions = FunctionTool(functions=functions_to_use)
331347
toolset = ToolSet()
332348
toolset.add(functions)
@@ -342,7 +358,7 @@ print(f"Created agent, ID: {agent.id}")
342358

343359
## 5: Create a thread for communication
344360

345-
The following code creates a thread to commuicate between the project client and your agent.
361+
The following code creates a thread and adds a user message to start the conversation between the project client and your agent.
346362

347363
```python
348364
# Create a thread for communication
@@ -351,29 +367,42 @@ print(f"Created thread, ID: {thread.id}")
351367

352368
# Create a message in the thread
353369
message = project_client.agents.messages.create(
354-
thread_id=thread.id,
355-
role="user",
356-
content="Hello, send an email to <RECIPIENT_EMAIL> with the date and time in '%Y-%m-%d %H:%M:%S' format.",
370+
thread_id=thread.id,
371+
role="user",
372+
content="Hello, send an email to <RECIPIENT_EMAIL> with the date and time in '%Y-%m-%d %H:%M:%S' format.",
357373
)
358374
print(f"Created message, ID: {message['id']}")
359375
```
360376

361-
## 6: Test your agent
377+
## 6: Test your agent and the action
362378

363379
To test how well the agent performs the task, run the agent, observe how the model uses the logic app tool, and check the output.
364380

365381
```python
366-
# Create and process an agent run in the thread
367-
run = project_client.agents.runs.create_and_process(thread_id=thread.id, agent_id=agent.id)
382+
# Create and run the agent on the thread
383+
run = project_client.agents.runs.create_and_process(
384+
thread_id=thread.id, agent_id=agent.id
385+
)
368386
print(f"Run finished with status: {run.status}")
369387

370388
if run.status == "failed":
371-
print(f"Run failed: {run.last_error}")
389+
print(f"Run failed: {run.last_error}")
372390

373-
# Fetch and log all messages
391+
# Fetch, log, and display all messages
374392
messages = project_client.agents.messages.list(thread_id=thread.id)
375393
for message in messages:
376-
print(f"Role: {message['role']}, Content: {message['content']}")
394+
if msg.txt = msg.text_messages[-1]
395+
print(f"Role: {msg.role}: {last_text.text.value}")
396+
```
397+
398+
## 7: Clean up resources
399+
400+
Delete the agent when you finish to clean up resources so you don't continue getting charged.
401+
402+
```python
403+
# Delete the agent
404+
project_client.agents.delete_agent(agent.id)
405+
print("Deleted agent.")
377406
```
378407

379408
:::zone-end
@@ -458,144 +487,7 @@ If you make changes to the weather workflow or want to test a different workflow
458487

459488
On the **Output** tab, the **Response Body** contains the results and response from the workflow.
460489

461-
1. If your workflow run produces errors or requires troubleshooting, open the workflow's run history. Examine each operation's inputs and outputs by using the relevant steps in [View workflow run history](view-workflow-status-run-history.md)).
462-
463-
## 6: Delete resources
464-
465-
If you don't need the resources that you created for this guide, delete them so you don't continue getting charged. You can either follow these steps to delete the resource group that contains these resources, or you can delete each resource individually.
466-
467-
1. In the Foundry portal, to remove the action from the agent, next to the action name, select the ellipses (**...**) button, and then select **Remove**.
468-
469-
1. In the [Azure portal](https://portal.azure.com) title bar search box, enter **resource groups**, and select **Resource groups**.
470-
471-
1. Find the resource group that contains your deployed hub resources.
472-
473-
1. On the **Overview** page toolbar, select **Delete resource group**.
474-
475-
1. When the confirmation pane appears, enter the resource group name, and select **Delete**.
476-
477-
:::zone-end
478-
479-
:::zone pivot="python"
480-
481-
## 1: Create a project client
482-
483-
To connect to your Foundry project and other resources, follow these steps to create a client object:
484-
485-
```python
486-
import os
487-
from azure.ai.projects import AIProjectClient
488-
from azure.identity import DefaultAzureCredential
489-
490-
# Initialize the AIProjectClient
491-
project_client = AIProjectClient(
492-
endpoint=os.environ["PROJECT_ENDPOINT"],
493-
credential=DefaultAzureCredential()
494-
)
495-
```
496-
497-
## 2: Register your logic app
498-
499-
Register your Consumption logic app resource by providing the trigger name and information. To find the `AzureLogicAppTool` utility code, visit the [full sample on GitHub](https://github.com/azure-ai-foundry/foundry-samples/blob/main/samples-classic/python/getting-started-agents/logic_apps/user_logic_apps.py).
500-
501-
```python
502-
from user_logic_apps import AzureLogicAppTool
503-
504-
# Logic app details
505-
LOGIC_APP_NAME = "your_logic_app_name"
506-
TRIGGER_NAME = "your_trigger_name"
507-
508-
# Register the logic app name with the agent tool utility by extracting the following values from environment variables
509-
subscription_id = os.environ["SUBSCRIPTION_ID"]
510-
resource_group = os.environ["resource_group_name"]
511-
512-
# Create and initialize AzureLogicAppTool utility
513-
logic_app_tool = AzureLogicAppTool(subscription_id, resource_group)
514-
logic_app_tool.register_logic_app(LOGIC_APP_NAME, TRIGGER_NAME)
515-
print(f"Registered logic app '{LOGIC_APP_NAME}' with trigger '{TRIGGER_NAME}'.")
516-
```
517-
518-
## 3: Create an agent with a logic app workflow as an action (tool)
519-
520-
The following code creates an agent and attaches the logic app as an agent action or tool. In this example, the logic app workflow sends an email.
521-
522-
```python
523-
from azure.ai.agents.models import ToolSet, FunctionTool
524-
from user_functions import fetch_current_datetime
525-
from user_logic_apps import create_send_email_function
526-
527-
# Create the logic app action for the agent
528-
send_email_func = create_send_email_function(
529-
logic_app_tool, logic_app_name
530-
)
531-
532-
# Prepare the action tool for the agent
533-
functions_to_use = {fetch_current_datetime, send_email_func}
534-
535-
# Create an agent and assign the toolset
536-
functions = FunctionTool(functions=functions_to_use)
537-
toolset = ToolSet()
538-
toolset.add(functions)
539-
540-
agent = project_client.agents.create_agent(
541-
model=os.environ["MODEL_DEPLOYMENT_NAME"],
542-
name="SendEmailAgent",
543-
instructions="You're a specialized agent for sending emails.",
544-
toolset=toolset,
545-
)
546-
print(f"Created agent, ID: {agent.id}")
547-
```
548-
549-
## 4: Create a thread for communication
550-
551-
The following code creates a thread and adds a user message to start the conversation between the project client and your agent.
552-
553-
```python
554-
# Create a thread for communication
555-
thread = project_client.agents.threads.create()
556-
print(f"Created thread, ID: {thread.id}")
557-
558-
# Create a message in the thread
559-
message = project_client.agents.messages.create(
560-
thread_id=thread.id,
561-
role="user",
562-
content="Hello, send an email to <RECIPIENT_EMAIL> with the date and time in '%Y-%m-%d %H:%M:%S' format.",
563-
)
564-
print(f"Created message, ID: {message['id']}")
565-
```
566-
567-
## 5: Test your agent
568-
569-
To test how well the agent performs the task, run the agent, observe how the model uses the logic app tool, and check the output.
570-
571-
```python
572-
# Create and run the agent on the thread
573-
run = project_client.agents.runs.create_and_process(
574-
thread_id=thread.id, agent_id=agent.id
575-
)
576-
print(f"Run finished with status: {run.status}")
577-
578-
if run.status == "failed":
579-
print(f"Run failed: {run.last_error}")
580-
581-
# Fetch, log, and display all messages
582-
messages = project_client.agents.messages.list(thread_id=thread.id)
583-
for message in messages:
584-
if msg.txt = msg.text_messages[-1]
585-
print(f"Role: {msg.role}: {last_text.text.value}")
586-
```
587-
588-
## 6: Clean up resources
589-
590-
Delete the agent when you finish to clean up resources so you don't continue getting charged.
591-
592-
```python
593-
# Delete the agent
594-
project_client.agents.delete_agent(agent.id)
595-
print("Deleted agent.")
596-
```
597-
598-
:::zone-end
490+
1. If your workflow run produces errors or requires troubleshooting, open the workflow's run history. Examine each operation's inputs and outputs by using the relevant steps in [View workflow run history](view-workflow-status-run-history.md).
599491

600492
## Billing and pricing
601493

0 commit comments

Comments
 (0)