diff --git a/daprdocs/content/en/developing-ai/dapr-agents/dapr-agents-core-concepts.md b/daprdocs/content/en/developing-ai/dapr-agents/dapr-agents-core-concepts.md index aedba05a229..f8d615a49b8 100644 --- a/daprdocs/content/en/developing-ai/dapr-agents/dapr-agents-core-concepts.md +++ b/daprdocs/content/en/developing-ai/dapr-agents/dapr-agents-core-concepts.md @@ -119,6 +119,26 @@ In Summary: - `DurableAgent` (Workflow-backed): Interaction is asynchronous—you trigger the agent once, and it runs autonomously in the background until completion. The conversation state and the execution are persisted and can resume across failures or restarts. +#### Replay-Aware Logging + +Because `DurableAgent` relies on Dapr Workflows, the underlying execution model uses event sourcing. This means the workflow code is re-executed (replayed) from the beginning to rebuild local state after awaiting external activities or tool calls. + +To prevent duplicate logs from polluting your output during these rehydration cycles, Dapr Agents provides a `ContextAwareLogger`. This logger automatically hooks into the `DaprWorkflowContext` and silently suppresses log records when the workflow is actively replaying. + +```python +from dapr_agents.utils import get_context_aware_logger +from dapr_agents.workflow.decorators import workflow_entry + +# Initialize the logger at the module level +logger = get_context_aware_logger(__name__) + +@workflow_entry +def my_workflow(self, ctx: DaprWorkflowContext, wf_input: dict) -> str: + # This will only print once, even if the workflow suspends and replays 5 times + logger.info("Starting workflow execution...") + # ... +``` + ## Core Agent Features An agentic system is a distributed system that requires a variety of behaviors and supporting infrastructure.