Logging and Chat History
The Dify client provides comprehensive logging functionality for both workflow and chat applications.
Quick Examples
# Get workflow logs
workflow_app = client.get_app(app_id="your-workflow-app-id")
# Get paginated logs
logs = workflow_app.get_logs(page=1, limit=10)
for entry in logs.data:
print(f"Workflow run {entry.workflow_run.id}: {entry.workflow_run.status}")
# Iterate through all logs
for entry in workflow_app.iter_logs(limit=10):
print(f"Log entry {entry.id} created at {entry.created_at}")
# Get workflow node executions
workflow_run_id = logs.data[0].workflow_run.id
executions = workflow_app.get_node_executions(workflow_run_id)
for node in executions.data:
print(f"Node {node.title} ({node.node_type}): {node.status}")
if node.error:
print(f"Error: {node.error}")
Chat Session
- class Chat
Represents a chat conversation session. Used for tracking and retrieving message history.
- __init__(client: DifyBaseClient, app: App, id: str, info: dict = None)
Initialize a new chat session.
- Parameters:
client – The Dify client instance
app – The parent application instance
id – Unique identifier for the chat session
info – Optional additional information about the chat session
- property messages(max_pages: int = 10) list
Retrieves chat messages for the conversation, with pagination support. Returns a list of message dictionaries.
- Parameters:
max_pages – Maximum number of pages to retrieve (default: 10)
- Returns:
List of message dictionaries containing conversation history
Workflow Logging
- class WorkflowLogEntry
Represents a single workflow execution log entry.
- workflow_run: WorkflowRun
Details about the workflow run.
Workflow Node Executions
- class WorkflowNodeExecution
Represents the execution of a single node in a workflow.
- class WorkflowNodeExecutions
Container for a list of node executions.
- data: List[WorkflowNodeExecution]
List of node executions.