Skip to content

Commit 0cf955b

Browse files
Merge pull request #49831 from buzahid/sk-agents
Modules/M04-develop-ai-agent-with-semantic-kernel updated code sample
2 parents b78c173 + 3288760 commit 0cf955b

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

learn-pr/wwl-data-ai/develop-ai-agent-with-semantic-kernel/includes/3-create-azure-ai-agent.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
**AzureAIAgent** is a specialized agent within the Semantic Kernel framework, designed to provide advanced conversational capabilities with seamless tool integration. It automates tool calling, eliminating the need for manual parsing and invocation. The agent also securely manages conversation history using threads, reducing the overhead of maintaining state. The AzureAIAgent class supports a variety of built-in tools, including file retrieval, code execution, and data interaction via Bing, Azure AI Search, Azure Functions, and OpenAPI.
1+
**AzureAIAgent** is a specialized agent within the Semantic Kernel framework, designed to provide advanced conversational capabilities with seamless tool integration. It automates tool calling, eliminating the need for manual parsing and invocation. The agent also securely manages conversation history using threads, reducing the overhead of maintaining state. The AzureAIAgent class supports many built-in tools, including file retrieval, code execution, and data interaction via Bing, Azure AI Search, Azure Functions, and OpenAPI.
22

33
## Creating an AzureAIAgent
44

@@ -12,11 +12,11 @@ To use an AzureAIAgent:
1212
1. Create an agent definition on the agent service provided by the client.
1313
1. Create an agent based on the definition.
1414

15-
Here is the code that illustrates how to create an AzureAIAgent:
15+
Here's the code that illustrates how to create an AzureAIAgent:
1616

1717
```python
1818
from azure.identity.aio import DefaultAzureCredential
19-
from semantic_kernel.agents import AzureAIAgent, AzureAIAgentSettings
19+
from semantic_kernel.agents import AzureAIAgent, AzureAIAgentThread, AzureAIAgentSettings
2020

2121
# Create an AzureAIAgentSettings object
2222
ai_agent_settings = AzureAIAgentSettings.create()
@@ -40,21 +40,23 @@ async with (@
4040
)
4141
```
4242

43-
Once your agent is defined, you can interact with your agent and invoke responses for inputs. To invoke responses, you create an agent thread and use the agent to add prompt and retrieve a response. For example:
43+
Once your agent is defined, you can create a thread to interact with your agent and invoke responses for inputs. For example:
4444

4545
```python
46-
thread: AzureAIAgentThread = AzureAIAgentThread()
46+
# Create the agent thread
47+
thread: AzureAIAgentThread = AzureAIAgentThread(client=client)
4748

4849
try:
49-
# Create a prompt
50-
prompt = "What are the largest semiconductor manufacturing companies?"
50+
# Create prompts
51+
prompt_messages = ["What are the largest semiconductor manufacturing companies?"]
5152

52-
# Instruct the agent to add a message to the thread
53-
await agent.add_chat_message(thread_id=thread.id, message=prompt)
53+
# Invoke a response from the agent
54+
response = await agent.get_response(messages=prompt_messages, thread_id=thread.id)
5455

55-
# Invoke the agent for response on the thread
56-
response = await agent.get_response(thread_id=thread.id)
56+
# View the response
57+
print(response)
5758
finally:
59+
# Clean up the thread
5860
await thread.delete() if thread else None
5961
```
6062

@@ -68,8 +70,8 @@ The Semantic Kernel AzureAIAgent object relies on the following components to fu
6870

6971
- **Agent service** - the AzureAIAgent client also contains an agent operations service. This service helps streamline the process of creating, managing, and running the agents for your project.
7072

71-
- **Agent definition** - the AzureAI Agent model created via the AzureAI Project client. This definition specifies the AI deployment model that should be used, as well as the name and instructions for the agent.
73+
- **Agent definition** - the AzureAI Agent model created via the AzureAI Project client. This definition specifies the AI deployment model that should be used, and the name and instructions for the agent.
7274

73-
- **AzureAIAgentThread** - automatically maintains the conversation history between agents and users, as well as the state. You can add messages to a thread and use the agent to invoke a response from the LLM.
75+
- **AzureAIAgentThread** - automatically maintains the conversation history between agents and users, and the state. You can add messages to a thread and use the agent to invoke a response from the LLM.
7476

7577
These components work together to allow you to create an agent with instructions to define its purpose and invoke responses from the AI model.

0 commit comments

Comments
 (0)