Skip to content

Commit 5c8a9c1

Browse files
committed
Added required Conversation/OpenAI component setup and updated the sample agent to use AgentMemoryConfig.
Signed-off-by: Roberto Rodriguez <9653181+Cyb3rWard0g@users.noreply.github.com>
1 parent 1816a8c commit 5c8a9c1

File tree

1 file changed

+39
-14
lines changed

1 file changed

+39
-14
lines changed

daprdocs/content/en/developing-applications/dapr-agents/dapr-agents-getting-started.md

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,11 @@ Make sure you have Python already installed. `Python >=3.10`. For installation i
5353

5454
Let's create a weather assistant agent that demonstrates tool calling with Dapr state management used for conversation memory.
5555

56-
### 1. Create the environment file
56+
### 1. Create the Dapr components
5757

58-
Create a `.env` file with your OpenAI API key:
58+
Create a `components` directory and add two files:
5959

60-
```env
61-
OPENAI_API_KEY=your_api_key_here
62-
```
63-
64-
This API key is essential for agents to communicate with the LLM, as the default LLM client in the agent uses OpenAI's services. If you don't have an API key, you can [create one here](https://platform.openai.com/api-keys).
65-
66-
### 2. Create the Dapr component
67-
68-
Create a `components` directory and add `historystore.yaml`:
60+
`historystore.yaml`:
6961

7062
```yaml
7163
apiVersion: dapr.io/v1alpha1
@@ -84,36 +76,69 @@ spec:
8476
8577
This component will be used to store the conversation history, as LLMs are stateless and every chat interaction needs to send all the previous conversations to maintain context.
8678
79+
`openai.yaml`:
80+
81+
```yaml
82+
apiVersion: dapr.io/v1alpha1
83+
kind: Component
84+
metadata:
85+
name: openai
86+
spec:
87+
type: conversation.openai
88+
version: v1
89+
metadata:
90+
- name: key
91+
value: "{{OPENAI_API_KEY}}"
92+
- name: model
93+
value: gpt-5-2025-08-07
94+
- name: temperature
95+
value: 1
96+
```
97+
98+
This component wires the default `DaprChatClient` to OpenAI via the Conversation API. The `{{OPENAI_API_KEY}}` placeholder picks up the value from your `.env` file, so you only need to set the key once. You can also tweak metadata (model, temperature, baseUrl, etc.) to point at compatible OpenAI-style providers.
99+
100+
Replace the placeholder with your actual OpenAI key (either by resolving the template at runtime or by editing the file directly). This API key is essential for agents to communicate with the LLM, as the default chat client talks to OpenAI-compatible endpoints. If you don't have an API key, you can [create one here](https://platform.openai.com/api-keys).
101+
87102
### 3. Create the agent with weather tool
88103

89104
Create `weather_agent.py`:
90105

91106
```python
92107
import asyncio
93108
from dapr_agents import tool, Agent
109+
from dapr_agents.agents.configs import AgentMemoryConfig
94110
from dapr_agents.memory import ConversationDaprStateMemory
95111
from dotenv import load_dotenv
96112
97113
load_dotenv()
98114
115+
99116
@tool
100117
def get_weather() -> str:
101118
"""Get current weather."""
102119
return "It's 72°F and sunny"
103120
121+
104122
async def main():
123+
memory_config = AgentMemoryConfig(
124+
store=ConversationDaprStateMemory(
125+
store_name="historystore",
126+
session_id="hello-world",
127+
)
128+
)
129+
105130
agent = Agent(
106131
name="WeatherAgent",
107132
role="Weather Assistant",
108133
instructions=["Help users with weather information"],
109-
memory=ConversationDaprStateMemory(store_name="historystore", session_id="hello-world"),
134+
memory=memory_config,
110135
tools=[get_weather],
111136
)
112137
113138
# First interaction
114139
response1 = await agent.run("Hi! My name is John. What's the weather?")
115140
print(f"Agent: {response1}")
116-
141+
117142
# Second interaction - agent should remember the name
118143
response2 = await agent.run("What's my name?")
119144
print(f"Agent: {response2}")
@@ -184,4 +209,4 @@ Here you can browse the state store used in the agent and explore its data.
184209
## Next Steps
185210

186211
Now that you have Dapr Agents installed and running, explore more advanced examples and patterns in the [quickstarts]({{% ref dapr-agents-quickstarts.md %}}) section to learn about multi-agent workflows, durable agents, and integration with Dapr's powerful distributed capabilities.
187-
212+

0 commit comments

Comments
 (0)