Skip to content

Commit e7bb06d

Browse files
authored
Merge branch 'v1.16' into docs/agents-metadata
2 parents 5e188ff + e60c52d commit e7bb06d

File tree

4 files changed

+190
-2
lines changed

4 files changed

+190
-2
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
type: docs
3+
title: "LangGraph"
4+
linkTitle: "LangGraph"
5+
weight: 25
6+
description: "Dapr first-class integrations with LangGraph Agents"
7+
---
8+
9+
### What is the Dapr LangGraph integration?
10+
11+
Dapr provides LangGraph agents a first class integration to agent session management (checkpointers).
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
---
2+
type: docs
3+
title: "Agent Sessions"
4+
linkTitle: "Agent Sessions"
5+
weight: 30
6+
description: "How to use Dapr reliably and securely manage LangGraph Agent Checkpointers"
7+
---
8+
9+
## Overview
10+
11+
The Dapr Python SDK provides integration with LangGraph Checkpointer using the `dapr-ext-langgraph` extension.
12+
13+
## Getting Started
14+
15+
Initialize Dapr locally to set up a self-hosted environment for development. This process fetches and installs the Dapr sidecar binaries, runs essential services as Docker containers, and prepares a default components folder for your application. For detailed steps, see the official [guide on initializing Dapr locally]({{% ref install-dapr-cli.md %}}).
16+
17+
To initialize the Dapr control plane containers and create a default configuration file, run:
18+
19+
```bash
20+
dapr init
21+
```
22+
23+
Verify you have container instances with `daprio/dapr`, `openzipkin/zipkin`, and `redis` images running:
24+
25+
```bash
26+
docker ps
27+
```
28+
29+
### Install Python
30+
31+
{{% alert title="Note" color="info" %}}
32+
Make sure you have Python already installed. `Python >=3.10`. For installation instructions, visit the official [Python installation guide](https://www.python.org/downloads/).
33+
{{% /alert %}}
34+
35+
### Download Dependencies
36+
37+
Download and install the Dapr LangGraph extension with:
38+
39+
{{< tabpane text=true >}}
40+
41+
{{% tab header="Stable" %}}
42+
43+
```bash
44+
pip install dapr-ext-langgraph langchain_openai langchain_core langgraph langgraph-prebuilt
45+
```
46+
47+
{{% /tab %}}
48+
49+
{{% tab header="Development" %}}
50+
{{% alert title="Note" color="warning" %}}
51+
The development package will contain features and behavior that will be compatible with the pre-release version of the Dapr runtime. Make sure to uninstall any stable versions of the Python SDK extension before installing the `dapr-dev` package.
52+
{{% /alert %}}
53+
54+
```bash
55+
pip install dapr-ext-langgraph-dev langchain_openai langchain_core langgraph langgraph-prebuilt
56+
```
57+
58+
{{% /tab %}}
59+
60+
{{< /tabpane >}}
61+
62+
### Create a LangGraph Agent
63+
64+
To let Dapr handle the agent memory, utilize the `DaprCheckpointer` as the checkpointer object when compiling the graph. Pass the checkpointer just like any other checkpointer provider:
65+
66+
```python
67+
from dapr.ext.langgraph import DaprCheckpointer
68+
from langchain_openai import ChatOpenAI
69+
from langchain_core.messages import HumanMessage, SystemMessage
70+
from langgraph.graph import START, MessagesState, StateGraph
71+
from langgraph.prebuilt import ToolNode, tools_condition
72+
73+
74+
def add(a: int, b: int) -> int:
75+
"""Adds a and b.
76+
77+
Args:
78+
a: first int
79+
b: second int
80+
"""
81+
return a + b
82+
83+
tools = [add]
84+
llm = ChatOpenAI(model="gpt-4o")
85+
llm_with_tools = llm.bind_tools(tools)
86+
87+
sys_msg = SystemMessage(
88+
content='You are a helpful assistant tasked with performing arithmetic on a set of inputs.'
89+
)
90+
91+
def assistant(state: MessagesState):
92+
return {'messages': [llm_with_tools.invoke([sys_msg] + state['messages'])]}
93+
94+
builder = StateGraph(MessagesState)
95+
builder.add_node('assistant', assistant)
96+
builder.add_node('tools', ToolNode(tools))
97+
builder.add_edge(START, 'assistant')
98+
builder.add_conditional_edges(
99+
'assistant',
100+
tools_condition,
101+
)
102+
builder.add_edge('tools', 'assistant')
103+
104+
memory = DaprCheckpointer(store_name='statestore', key_prefix='dapr')
105+
react_graph_memory = builder.compile(checkpointer=memory)
106+
107+
config = {'configurable': {'thread_id': '1'}}
108+
109+
messages = [HumanMessage(content='Add 3 and 4.')]
110+
messages = react_graph_memory.invoke({'messages': messages}, config)
111+
for m in messages['messages']:
112+
m.pretty_print()
113+
```
114+
115+
### Set an OpenAI API key
116+
117+
```bash
118+
export OPENAI_API_KEY=sk-...
119+
```
120+
121+
### Create a Python venv
122+
123+
```bash
124+
python -m venv .venv
125+
source .venv/bin/activate # On Windows: .venv\Scripts\activate
126+
```
127+
128+
## Create the database component
129+
130+
The component file is how Dapr connects to your databae. The full list of supported databases can be found [here]({{% ref supported-state-stores %}}). Create a `components` directory and this file in it:
131+
132+
```yaml
133+
apiVersion: dapr.io/v1alpha1
134+
kind: Component
135+
metadata:
136+
name: statestore
137+
spec:
138+
type: state.redis
139+
version: v1
140+
metadata:
141+
- name: redisHost
142+
value: localhost:6379
143+
- name: redisPassword
144+
value: ""
145+
```
146+
147+
## Next Steps
148+
149+
Now that you have a LangGraph agent using Dapr to manage the agent sessions, explore more you can do with the [State API]({{% ref "state-management-overview" %}}) and how to enable [resiliency policies]({{% ref resiliency-overview %}}) for enhanced reliability.

daprdocs/content/en/developing-ai/agent-integrations/openai-agents/_index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
type: docs
3-
title: "OpenAI Agents"
4-
linkTitle: "OpenAI Agents"
3+
title: "OpenAI"
4+
linkTitle: "OpenAI"
55
weight: 25
66
description: "Dapr first-class integrations for OpenAI Agents"
77
---

daprdocs/content/en/developing-ai/dapr-agents/dapr-agents-patterns.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,34 @@ The Durable Agent enables the concept of "headless agents" - autonomous systems
436436

437437
These options make it easy to process requests asynchronously and integrate seamlessly into larger distributed systems.
438438

439+
### Retry Policy
440+
441+
The Durable Agent supports Dapr Workflow's `RetryPolicy` with the its `WorkflowRetryPolicy`:
442+
443+
- `max_attempts`: max_attempts: Maximum number of retry attempts for workflow operations. Default is 1 (no retries). Set `DAPR_API_MAX_RETRIES` environment variable to override default.
444+
- `initial_backoff_seconds`: Initial backoff duration in seconds. Default is 5 seconds.
445+
- `max_backoff_seconds`: Maximum backoff duration in seconds. Default is 30 seconds.
446+
- `backoff_multiplier`: Backoff multiplier for exponential backoff. Default is 1.5.
447+
- `retry_timeout`: Total timeout for all retries in seconds.
448+
449+
All of the fields are optional. It can be passed to the Durable Agent during instantiation:
450+
451+
```python
452+
from dapr_agents.agents.configs import WorkflowRetryPolicy
453+
travel_planner = DurableAgent(
454+
name="TravelBuddy",
455+
...
456+
retry_policy=WorkflowRetryPolicy(
457+
max_attempts=5,
458+
initial_backoff_seconds=10,
459+
max_backoff_seconds=60,
460+
backoff_multiplier=2.0,
461+
retry_timeout=300,
462+
)
463+
...
464+
)
465+
```
466+
439467

440468
## Choosing the Right Pattern
441469

0 commit comments

Comments
 (0)