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}")
# Get agent/chat conversation logs
agent_app = client.get_app(app_id="your-agent-app-id")
conversations = agent_app.get_logs(page=1, limit=10)
for conversation in conversations.data:
print(f"Conversation {conversation.id}: {conversation.name}")
# Get messages for a conversation
conversation_id = conversations.data[0].id
messages = agent_app.get_messages(conversation_id=conversation_id, limit=10)
for message in messages.data:
print(f"Message: {message.query}")
if message.answer:
print(f"Answer: {message.answer}")
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.
-
id: str
Unique identifier for the log entry.
-
workflow_run: WorkflowRun
Details about the workflow run.
-
created_from: str
Source from which the workflow was created.
-
created_by_role: str
Role of the user who created the workflow run.
-
created_by_account: Dict | None
Account information of the creator.
-
created_by_end_user: Dict
End user information.
-
created_at: int
Timestamp when the log entry was created.
-
class WorkflowRun
Contains information about a specific workflow run.
-
id: str
Unique identifier for the workflow run.
-
version: str
Version of the workflow.
-
status: str
Current status of the workflow run.
-
error: str | None
Error message if the workflow run failed.
-
elapsed_time: float
Time taken to execute the workflow.
-
total_tokens: int
Total number of tokens used.
-
total_steps: int
Total number of steps executed.
-
created_at: int
Timestamp when the workflow run was created.
-
finished_at: int
Timestamp when the workflow run finished.
-
exceptions_count: int
Number of exceptions encountered during execution.
Workflow Node Executions
-
class WorkflowNodeExecution
Represents the execution of a single node in a workflow.
-
id: str
Unique identifier for the node execution.
-
node_type: str
Type of the workflow node.
-
title: str
Title of the node.
-
status: str
Execution status of the node.
-
error: str | None
Error message if the node execution failed.
-
elapsed_time: float
Time taken to execute the node.
-
inputs: Dict[str, Any] | None
Input parameters provided to the node.
-
outputs: Dict[str, Any] | None
Output values produced by the node.
-
process_data: Dict[str, Any] | None
Process data during node execution.
-
index: int
Index of the node execution.
-
predecessor_node_id: str | None
ID of the predecessor node.
-
node_id: str
ID of the node being executed.
-
execution_metadata: WorkflowNodeExecutionMetadata | None
Metadata about the node execution.
Additional extra data.
-
created_at: int
Timestamp when the node execution was created.
-
created_by_role: str
Role of the user who triggered the execution.
-
created_by_account: Dict[str, Any] | None
Account information of the creator.
-
created_by_end_user: Dict[str, Any]
End user information.
-
finished_at: int
Timestamp when the node execution finished.
-
class WorkflowNodeExecutionMetadata
Metadata about workflow node execution.
-
parallel_id: str | None
ID for parallel execution.
-
parallel_start_node_id: str | None
ID of the starting node in parallel execution.
-
tool_info: Dict[str, Any] | None
Information about tools used.
-
total_tokens: int | None
Total tokens used.
-
total_price: str | None
Total price of execution.
-
currency: str | None
Currency for the price.
-
class WorkflowNodeExecutions
Container for a list of node executions.
-
data: List[WorkflowNodeExecution]
List of node executions.
Agent and Chat Logging
-
class AgentConversation
Represents a single agent or chat conversation.
-
id: str
Unique identifier for the conversation.
-
status: str
Current status of the conversation.
-
from_source: str
Source from which the conversation originated.
-
from_end_user_id: str | None
ID of the end user who started the conversation.
-
from_end_user_session_id: str | None
Session ID of the end user.
-
from_account_id: str | None
Account ID of the creator.
-
from_account_name: str | None
Name of the account creator.
-
name: str
Name of the conversation.
-
summary: str
Summary of the conversation.
-
read_at: int | None
Timestamp when the conversation was last read.
-
created_at: int
Timestamp when the conversation was created.
-
updated_at: int
Timestamp when the conversation was last updated.
-
annotated: bool
Whether the conversation has been annotated.
-
agent_model_config: Dict
Model configuration for the agent (aliased as “model_config” in API).
-
message_count: int
Number of messages in the conversation.
-
user_feedback_stats: Dict
Statistics about user feedback.
-
admin_feedback_stats: Dict
Statistics about admin feedback.
-
status_count: Dict
Count of different statuses.
Chat Messages
-
class ChatMessage
Represents a single chat message in a conversation.
-
id: str
Unique identifier for the message.
-
conversation_id: str
ID of the conversation this message belongs to.
-
inputs: Dict[str, Any] | None
Input parameters provided with the message.
-
query: str | None
The user’s query or question.
-
answer: str | None
The assistant’s answer.
-
message: Dict[str, Any] | None
Full message object with additional metadata.
-
feedback: Dict[str, Any] | None
User feedback on the message.
-
created_at: int
Timestamp when the message was created.
-
created_by_role: str | None
Role of the user who created the message.
-
created_by_account: Dict[str, Any] | None
Account information of the creator.
-
created_by_end_user: Dict[str, Any] | None
End user information.
-
from_source: str | None
Source from which the message originated.
-
from_end_user_id: str | None
ID of the end user.
-
from_end_user_session_id: str | None
Session ID of the end user.
-
from_account_id: str | None
Account ID of the creator.
-
from_account_name: str | None
Name of the account creator.
-
class PaginatedChatMessages
Paginated response containing chat messages.
-
data: List[ChatMessage]
List of chat messages in the current page.
-
page: int
Current page number.
-
limit: int
Number of items per page.
-
total: int
Total number of items.
-
has_more: bool
Whether there are more pages available.
-
class PaginatedAgentLogs
Paginated response containing agent conversation logs.
-
data: List[AgentConversation]
List of conversations in the current page.
-
page: int
Current page number.
-
limit: int
Number of items per page.
-
total: int
Total number of items.
-
has_more: bool
Whether there are more pages available.