You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: daprdocs/content/en/developing-applications/dapr-agents/dapr-agents-getting-started.md
+39-14Lines changed: 39 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,19 +53,11 @@ Make sure you have Python already installed. `Python >=3.10`. For installation i
53
53
54
54
Let's create a weather assistant agent that demonstrates tool calling with Dapr state management used for conversation memory.
55
55
56
-
### 1. Create the environment file
56
+
### 1. Create the Dapr components
57
57
58
-
Create a `.env` file with your OpenAI API key:
58
+
Create a `components` directory and add two files:
59
59
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`:
69
61
70
62
```yaml
71
63
apiVersion: dapr.io/v1alpha1
@@ -84,36 +76,69 @@ spec:
84
76
85
77
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.
86
78
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
+
87
102
### 3. Create the agent with weather tool
88
103
89
104
Create `weather_agent.py`:
90
105
91
106
```python
92
107
import asyncio
93
108
from dapr_agents import tool, Agent
109
+
from dapr_agents.agents.configs import AgentMemoryConfig
94
110
from dapr_agents.memory import ConversationDaprStateMemory
95
111
from dotenv import load_dotenv
96
112
97
113
load_dotenv()
98
114
115
+
99
116
@tool
100
117
def get_weather() -> str:
101
118
"""Get current weather."""
102
119
return "It's 72°F and sunny"
103
120
121
+
104
122
async def main():
123
+
memory_config = AgentMemoryConfig(
124
+
store=ConversationDaprStateMemory(
125
+
store_name="historystore",
126
+
session_id="hello-world",
127
+
)
128
+
)
129
+
105
130
agent = Agent(
106
131
name="WeatherAgent",
107
132
role="Weather Assistant",
108
133
instructions=["Help users with weather information"],
response1 = await agent.run("Hi! My name is John. What's the weather?")
115
140
print(f"Agent: {response1}")
116
-
141
+
117
142
# Second interaction - agent should remember the name
118
143
response2 = await agent.run("What's my name?")
119
144
print(f"Agent: {response2}")
@@ -184,4 +209,4 @@ Here you can browse the state store used in the agent and explore its data.
184
209
## Next Steps
185
210
186
211
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.
0 commit comments