Skip to content

Commit 592008f

Browse files
committed
Modernized the Durable Agent pattern with config-class wiring plus AgentRunner execution options.
Signed-off-by: Roberto Rodriguez <9653181+Cyb3rWard0g@users.noreply.github.com>
1 parent 5c8a9c1 commit 592008f

File tree

1 file changed

+57
-10
lines changed

1 file changed

+57
-10
lines changed

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

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,19 @@ The Durable Agent also enables the "headless agents" approach where autonomous s
362362
**Implementation with Dapr Agents:**
363363

364364
```python
365+
import asyncio
366+
365367
from dapr_agents import DurableAgent
368+
from dapr_agents.agents.configs import (
369+
AgentExecutionConfig,
370+
AgentMemoryConfig,
371+
AgentPubSubConfig,
372+
AgentRegistryConfig,
373+
AgentStateConfig,
374+
)
375+
from dapr_agents.memory import ConversationDaprStateMemory
376+
from dapr_agents.storage.daprstores.stateservice import StateStoreService
377+
from dapr_agents.workflow.runners import AgentRunner
366378

367379
travel_planner = DurableAgent(
368380
name="TravelBuddy",
@@ -371,23 +383,58 @@ travel_planner = DurableAgent(
371383
instructions=[
372384
"Find flights to destinations",
373385
"Remember user preferences",
374-
"Provide clear flight info"
386+
"Provide clear flight info",
375387
],
376388
tools=[search_flights],
377-
message_bus_name="messagepubsub",
378-
state_store_name="workflowstatestore",
379-
state_key="workflow_state",
380-
agents_registry_store_name="workflowstatestore",
381-
agents_registry_key="agents_registry",
389+
pubsub=AgentPubSubConfig(
390+
pubsub_name="messagepubsub",
391+
agent_topic="travel.requests",
392+
broadcast_topic="travel.broadcast",
393+
),
394+
state=AgentStateConfig(
395+
store=StateStoreService(store_name="workflowstatestore"),
396+
),
397+
registry=AgentRegistryConfig(
398+
store=StateStoreService(store_name="registrystatestore"),
399+
team_name="travel-team",
400+
),
401+
execution=AgentExecutionConfig(max_iterations=3),
402+
memory=AgentMemoryConfig(
403+
store=ConversationDaprStateMemory(
404+
store_name="conversationstore",
405+
session_id="travel-session",
406+
)
407+
),
382408
)
409+
410+
async def main():
411+
travel_planner.start()
412+
runner = AgentRunner()
413+
try:
414+
result = await runner.run(
415+
travel_planner,
416+
payload={"task": "Find weekend flights to Paris"},
417+
)
418+
print(result)
419+
finally:
420+
runner.shutdown()
421+
travel_planner.stop()
422+
423+
asyncio.run(main())
383424
```
384425
The implementation follows Dapr's sidecar architecture model, where all infrastructure concerns are handled by the Dapr runtime:
385426
- **Persistent Memory** - Agent state is stored in Dapr's state store, surviving process crashes
386427
- **Workflow Orchestration** - All agent interactions managed through Dapr's workflow system
387-
- **Service Exposure** - REST endpoints for workflow management come out of the box
388-
- **Pub/Sub Input/Output** - Event-driven messaging through Dapr's pub/sub system for seamless integration
428+
- **Service Exposure** - `AgentRunner.serve()` exposes REST endpoints (e.g., `POST /run`) that schedule the agent's `@workflow_entry`
429+
- **Pub/Sub Input/Output** - `AgentRunner.subscribe()` scans the agent for `@message_router` methods and wires the configured topics with schema validation
430+
431+
The Durable Agent enables the concept of "headless agents" - autonomous systems that operate without direct user interaction. Depending on the scenario you can:
432+
433+
1. **Run** durable workflows programmatically (`runner.run` as shown above)
434+
2. **Subscribe** the agent to topics so other services can trigger it via pub/sub (`runner.subscribe`)
435+
3. **Serve** the agent behind a FastAPI app with built-in `/run` and status endpoints (`runner.serve`)
389436

390-
The Durable Agent enables the concept of "headless agents" - autonomous systems that operate without direct user interaction. Dapr's Durable Agent exposes both REST and Pub/Sub APIs, making it ideal for long-running operations that are triggered by other applications or external events. This allows agents to run in the background, processing requests asynchronously and integrating seamlessly into larger distributed systems.
437+
These options make it easy to process requests asynchronously and integrate seamlessly into larger distributed systems.
391438

392439

393440
## Choosing the Right Pattern
@@ -397,4 +444,4 @@ The journey from simple agentic workflows to fully autonomous agents represents
397444
- **Start with simpler patterns** like Augmented LLM and Prompt Chaining for well-defined tasks where predictability is crucial
398445
- **Progress to more dynamic patterns** like Parallelization and Orchestrator-Workers as your needs grow more complex
399446
- **Consider fully autonomous agents** only for open-ended tasks where the benefits of flexibility outweigh the need for strict control
400-
447+

0 commit comments

Comments
 (0)