Database
Sheds light on the database schema
Overview
This database schema defines a set of models designed to capture various aspects of an application related to projects, user interactions, traces, system information, errors, and different types of calls (LLM, Tool, and Agent). These models have specific relationships and foreign key constraints to ensure data integrity and consistency.
Database Models
UserInteractionModel
TraceModel
ProjectInfoModel
SystemInfoModel
ErrorModel
LLMCallModel
ToolCallModel
AgentCallModel
MetricModel
The relationships between these models are established using SQLAlchemy's relationship
function.
Model Descriptions
UserInteractionModel
This model represents a user's interaction with the application, such as an input or output. Each interaction is associated with a project, a trace, and agent. The model stores the following information:
id
: Unique identifier for the user interaction.project_id
: Foreign key referencing theProjectInfoModel
.trace_id
: Foreign key referencing theTraceModel
.agent_id
: Foreign key referencing theAgentCallModel
.interaction_type
: The type of interaction, either 'input' or 'output'.content
: The content of the interaction.timestamp
: The timestamp of the interaction.
Relationships:
trace
: Relationship withTraceModel
.project
: Relationship withProjectInfoModel
.agent
: Relationship withAgentCallModel
.
Example usage:
TraceModel
This model represents a trace of the application's execution. Each trace is associated with a project and can have various related entities, such as system information, errors, LLM calls, tool calls, agent calls, and user interactions. The model stores the following information:
id
: Unique identifier for the trace.project_id
: Foreign key referencing theProjectInfoModel
.start_time
: The start time of the trace.end_time
: The end time of the trace.duration
: The duration of the trace.
Relationships:
project
: Relationship with ProjectInfoModel
.
system_info
: One-to-one relationship with SystemInfoModel
.
errors
: One-to-many relationship with ErrorModel
.
llm_calls
: One-to-many relationship with LLMCallModel
.
tool_calls
: One-to-many relationship with ToolCallModel
.
agent_calls
: One-to-many relationship with AgentCallModel
.
user_interactions
: One-to-many relationship with UserInteractionModel
.
metrics
: One-to-many relationship with MetricModel
.
Example usage:
ProjectInfoModel
This model represents information about a project, such as its name, start and end times, duration, total cost, and total tokens. The model has relationships with various other entities, such as traces, user interactions, LLM calls, tool calls, agent calls, and system information. The model stores the following information:
id
: Unique identifier for the project.project_name
: The name of the project.start_time
: The start time of the project.end_time
: The end time of the project.duration
: The duration of the project.total_cost
: The total cost of the project.total_tokens
: The total number of tokens used in the project.
Relationships:
traces
: One-to-many relationship with TraceModel
.
llm_calls
: One-to-many relationship with LLMCallModel
.
tool_calls
: One-to-many relationship with ToolCallModel
.
agent_calls
: One-to-many relationship with AgentCallModel
.
system_info
: One-to-one relationship with SystemInfoModel
.
errors
: One-to-many relationship with ErrorModel
.
user_interactions
: One-to-many relationship with UserInteractionModel
.
Example usage:
SystemInfoModel
This model represents information about the system on which the application was running, such as the operating system, Python version, CPU and GPU information, disk information, and installed packages. The model is associated with a project and a trace. The model stores the following information:
id
: Unique identifier for the system information.project_id
: Foreign key referencing theProjectInfoModel
.os_name
: The name of the operating system.os_version
: The version of the operating system.python_version
: The version of Python.cpu_info
: Information about the CPU.gpu_info
: Information about the GPU (if available).disk_info
: Information about the disk.memory_total
: The total memory of the system.installed_packages
: A list of installed packages.trace_id
: Foreign key referencing theTraceModel
.Relationships:
trace
: Relationship with TraceModel
.
project
: Relationship with ProjectInfoModel
.
Example usage:
ErrorModel
This model represents errors that occurred during the application's execution. Each error is associated with a project, a trace, and possibly an agent, tool call, or LLM call. The model stores the following information:
id
: Unique identifier for the error.project_id
: Foreign key referencing theProjectInfoModel
.trace_id
: Foreign key referencing theTraceModel
.agent_id
: Foreign key referencing theAgentCallModel
.tool_call_id
: Foreign key referencing theToolCallModel
.llm_call_id
: Foreign key referencing theLLMCallModel
.error_type
: The type of error, either 'LLM', 'Tool', or 'Agent'.error_message
: The error message.timestamp
: The timestamp of the error.
Example usage:
LLMCallModel
This model represents a call to a Large Language Model (LLM). Each LLM call is associated with a project, an agent (if applicable), and a trace. The model stores the following information:
id
: Unique identifier for the LLM call.project_id
: Foreign key referencing theProjectInfoModel
.agent_id
: Foreign key referencing theAgentCallModel
.name
: The name of the LLM.model
: The model used for the LLM call.input_prompt
: The input prompt for the LLM call.output
: The output of the LLM call.tool_call
: The tool call associated with the LLM call (if applicable).start_time
: The start time of the LLM call.end_time
: The end time of the LLM call.duration
: The duration of the LLM call.token_usage
: The token usage for the LLM call.cost
: The cost of the LLM call.memory_used
: The memory used by the LLM call.trace_id
: Foreign key referencing theTraceModel
.
Example usage:
ToolCallModel
This model represents a call to a tool. Each tool call is associated with a project, an agent (if applicable), and a trace. The model stores the following information:
id
: Unique identifier for the tool call.project_id
: Foreign key referencing theProjectInfoModel
.agent_id
: Foreign key referencing theAgentCallModel
.name
: The name of the tool.input_parameters
: The input parameters for the tool call.output
: The output of the tool call.start_time
: The start time of the tool call.end_time
: The end time of the tool call.duration
: The duration of the tool call.memory_used
: The memory used by the tool call.trace_id
: Foreign key referencing theTraceModel
.network_calls
: The network calls made by the tool (if applicable).
Example usage:
AgentCallModel
This model represents a call to an agent. Each agent call is associated with a project and a trace, and can have related LLM calls, tool calls, and user interactions. The model stores the following information:
id
: Unique identifier for the agent call.project_id
: Foreign key referencing theProjectInfoModel
.name
: The name of the agent.start_time
: The start time of the agent call.end_time
: The end time of the agent call.trace_id
: Foreign key referencing theTraceModel
.llm_call_ids
: The IDs of the related LLM calls.tool_call_ids
: The IDs of the related tool calls.user_interaction_ids
: The IDs of the related user interactions.
Example usage:
MetricModel
This model represents a metric calculated for a trace. Each metric is associated with a trace and stores the following information:
id
: Unique identifier for the metric.trace_id
: Foreign key referencing theTraceModel
.metric_name
: The name of the metric.score
: The score of the metric.reason
: The reason for the metric score.result_detail
: Additional details about the metric result.config
: The configuration used to calculate the metric.start_time
: The start time of the metric calculation.end_time
: The end time of the metric calculation.duration
: The duration of the metric calculation.timestamp
: The timestamp of the metric calculation.
Example usage:
Relationships Summary
ProjectInfoModel ↔ TraceModel: One-to-Many
ProjectInfoModel ↔ UserInteractionModel, LLMCallModel, ToolCallModel, AgentCallModel: One-to-Many
ProjectInfoModel ↔ SystemInfoModel: One-to-One
TraceModel ↔ UserInteractionModel, ErrorModel, LLMCallModel, ToolCallModel, AgentCallModel: One-to-Many
AgentCallModel ↔ LLMCallModel, ToolCallModel, UserInteractionModel: One-to-Many
Last updated