solidworks_mcp.agents.history_db¶
solidworks_mcp.agents.history_db ¶
SQLModel persistence for agent runs and tool-error cataloging.
Attributes¶
DEFAULT_DB_PATH
module-attribute
¶
Classes¶
AgentRun ¶
Bases: SQLModel
One recorded agent run.
Attributes:
| Name | Type | Description |
|---|---|---|
agent_name |
str
|
The agent name value. |
created_at |
str
|
The created at value. |
id |
int | None
|
The id value. |
model_name |
str | None
|
The model name value. |
output_json |
str | None
|
The output json value. |
prompt |
str
|
The prompt value. |
run_id |
str
|
The run id value. |
status |
str
|
The status value. |
ConversationEvent ¶
Bases: SQLModel
One message or system event in a conversation, linked to a run context.
Attributes:
| Name | Type | Description |
|---|---|---|
content_snippet |
str
|
The content snippet value. |
conversation_id |
str
|
The conversation id value. |
created_at |
str
|
The created at value. |
event_type |
str
|
The event type value. |
id |
int | None
|
The id value. |
metadata_json |
str | None
|
The metadata json value. |
role |
str | None
|
The role value. |
run_id |
str | None
|
The run id value. |
DesignSession ¶
Bases: SQLModel
Persistent interactive design session metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
accepted_family |
str | None
|
The accepted family value. |
created_at |
str
|
The created at value. |
current_checkpoint_index |
int
|
The current checkpoint index value. |
id |
int | None
|
The id value. |
metadata_json |
str | None
|
The metadata json value. |
session_id |
str
|
The session id value. |
source_mode |
str
|
The source mode value. |
status |
str
|
The status value. |
updated_at |
str
|
The updated at value. |
user_goal |
str
|
The user goal value. |
ErrorCatalog ¶
Bases: SQLModel
Persisted error records for recovery recommendations.
Attributes:
| Name | Type | Description |
|---|---|---|
created_at |
str
|
The created at value. |
error_message |
str
|
The error message value. |
error_type |
str
|
The error type value. |
id |
int | None
|
The id value. |
remediation |
str
|
The remediation value. |
root_cause |
str
|
The root cause value. |
run_id |
str | None
|
The run id value. |
source |
str
|
The source value. |
tool_name |
str
|
The tool name value. |
ErrorRecord ¶
Bases: BaseModel
A normalized error record from an MCP call or planning step.
Attributes:
| Name | Type | Description |
|---|---|---|
error_message |
str
|
The error message value. |
error_type |
str
|
The error type value. |
remediation |
str
|
The remediation value. |
root_cause |
str
|
The root cause value. |
source |
str
|
The source value. |
tool_name |
str
|
The tool name value. |
EvidenceLink ¶
Bases: SQLModel
Evidence references used to justify planning decisions.
Attributes:
| Name | Type | Description |
|---|---|---|
checkpoint_id |
int | None
|
The checkpoint id value. |
created_at |
str
|
The created at value. |
id |
int | None
|
The id value. |
payload_json |
str | None
|
The payload json value. |
rationale |
str | None
|
The rationale value. |
relevance_score |
float | None
|
The relevance score value. |
session_id |
str
|
The session id value. |
source_id |
str
|
The source id value. |
source_type |
str
|
The source type value. |
ModelStateSnapshot ¶
Bases: SQLModel
Rollback/diff snapshot of model state at a checkpoint.
Attributes:
| Name | Type | Description |
|---|---|---|
checkpoint_id |
int | None
|
The checkpoint id value. |
created_at |
str
|
The created at value. |
feature_tree_json |
str | None
|
The feature tree json value. |
id |
int | None
|
The id value. |
mass_properties_json |
str | None
|
The mass properties json value. |
model_path |
str | None
|
The model path value. |
screenshot_path |
str | None
|
The screenshot path value. |
session_id |
str
|
The session id value. |
state_fingerprint |
str | None
|
The state fingerprint value. |
PlanCheckpoint ¶
Bases: SQLModel
One approval boundary in an interactive design session.
Attributes:
| Name | Type | Description |
|---|---|---|
approved_by_user |
bool
|
The approved by user value. |
checkpoint_index |
int
|
The checkpoint index value. |
created_at |
str
|
The created at value. |
executed |
bool
|
The executed value. |
id |
int | None
|
The id value. |
planned_action_json |
str
|
The planned action json value. |
result_json |
str | None
|
The result json value. |
rollback_snapshot_id |
int | None
|
The rollback snapshot id value. |
session_id |
str
|
The session id value. |
title |
str
|
The title value. |
updated_at |
str
|
The updated at value. |
SketchGraphSnapshot ¶
Bases: SQLModel
Lightweight relational sketch graph storage (Section F).
Attributes:
| Name | Type | Description |
|---|---|---|
created_at |
str
|
The created at value. |
edges_json |
str
|
The edges json value. |
graph_format |
str
|
The graph format value. |
id |
int | None
|
The id value. |
metadata_json |
str | None
|
The metadata json value. |
model_path |
str | None
|
The model path value. |
nodes_json |
str
|
The nodes json value. |
session_id |
str
|
The session id value. |
ToolCallRecord ¶
Bases: SQLModel
Execution log for tool calls scoped to session/checkpoint.
Attributes:
| Name | Type | Description |
|---|---|---|
checkpoint_id |
int | None
|
The checkpoint id value. |
created_at |
str
|
The created at value. |
id |
int | None
|
The id value. |
input_json |
str | None
|
The input json value. |
latency_ms |
float | None
|
The latency ms value. |
output_json |
str | None
|
The output json value. |
run_id |
str | None
|
The run id value. |
session_id |
str
|
The session id value. |
success |
bool
|
The success value. |
tool_name |
str
|
The tool name value. |
ToolEvent ¶
Bases: SQLModel
One tool lifecycle event linked to a run.
Attributes:
| Name | Type | Description |
|---|---|---|
created_at |
str
|
The created at value. |
id |
int | None
|
The id value. |
payload_json |
str | None
|
The payload json value. |
phase |
str
|
The phase value. |
run_id |
str
|
The run id value. |
tool_name |
str
|
The tool name value. |
Functions¶
_build_engine ¶
Build a local SQLite engine from the configured path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
SQLAlchemy engine instance for the resolved SQLite path. |
Source code in src/solidworks_mcp/agents/history_db.py
_utc_now_iso ¶
Build internal utc now iso.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The resulting text value. |
find_conversation_events ¶
Retrieve all events for a conversation, ordered by creation time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_id
|
str
|
The conversation id value. |
required |
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: A list containing the resulting items. |
Source code in src/solidworks_mcp/agents/history_db.py
find_recent_errors ¶
Return recent errors so agents can avoid repeated failing states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
limit
|
int
|
The limit value. Defaults to 20. |
20
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: A list containing the resulting items. |
Source code in src/solidworks_mcp/agents/history_db.py
find_run_timeline ¶
Reconstruct a complete timeline for one run, joining runs, tool events, and conversation events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_id
|
str
|
The run id value. |
required |
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: A dictionary containing the resulting values. |
Source code in src/solidworks_mcp/agents/history_db.py
get_design_session ¶
Return one session row as a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
dict[str, Any] | None: A dictionary containing the resulting values. |
Source code in src/solidworks_mcp/agents/history_db.py
init_db ¶
Create SQLModel tables used by the lightweight agent memory system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Path |
Path
|
The result produced by the operation. |
Source code in src/solidworks_mcp/agents/history_db.py
insert_conversation_event ¶
insert_conversation_event(*, conversation_id: str, event_type: str, content_snippet: str, role: str | None = None, run_id: str | None = None, metadata_json: str | None = None, db_path: Path | None = None) -> None
Record a conversation event (message, system event, or tool call) linked to a run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conversation_id
|
str
|
The conversation id value. |
required |
event_type
|
str
|
The event type value. |
required |
content_snippet
|
str
|
The content snippet value. |
required |
role
|
str | None
|
The role value. Defaults to None. |
None
|
run_id
|
str | None
|
The run id value. Defaults to None. |
None
|
metadata_json
|
str | None
|
The metadata json value. Defaults to None. |
None
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
None. |
Source code in src/solidworks_mcp/agents/history_db.py
insert_error ¶
Persist an error with normalized root cause and remediation guidance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
ErrorRecord
|
The record value. |
required |
run_id
|
str | None
|
The run id value. Defaults to None. |
None
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
None. |
Source code in src/solidworks_mcp/agents/history_db.py
insert_evidence_link ¶
insert_evidence_link(*, session_id: str, source_type: str, source_id: str, checkpoint_id: int | None = None, relevance_score: float | None = None, rationale: str | None = None, payload_json: str | None = None, db_path: Path | None = None) -> None
Insert one evidence row used by planning/classification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
source_type
|
str
|
The source type value. |
required |
source_id
|
str
|
The source id value. |
required |
checkpoint_id
|
int | None
|
The checkpoint id value. Defaults to None. |
None
|
relevance_score
|
float | None
|
The relevance score value. Defaults to None. |
None
|
rationale
|
str | None
|
The rationale value. Defaults to None. |
None
|
payload_json
|
str | None
|
The payload json value. Defaults to None. |
None
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
None. |
Source code in src/solidworks_mcp/agents/history_db.py
insert_model_state_snapshot ¶
insert_model_state_snapshot(*, session_id: str, checkpoint_id: int | None = None, model_path: str | None = None, feature_tree_json: str | None = None, mass_properties_json: str | None = None, screenshot_path: str | None = None, state_fingerprint: str | None = None, db_path: Path | None = None) -> int
Insert model snapshot row and return snapshot ID for rollback tracking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
checkpoint_id
|
int | None
|
The checkpoint id value. Defaults to None. |
None
|
model_path
|
str | None
|
The model path value. Defaults to None. |
None
|
feature_tree_json
|
str | None
|
The feature tree json value. Defaults to None. |
None
|
mass_properties_json
|
str | None
|
The mass properties json value. Defaults to None. |
None
|
screenshot_path
|
str | None
|
The screenshot path value. Defaults to None. |
None
|
state_fingerprint
|
str | None
|
The state fingerprint value. Defaults to None. |
None
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The computed numeric result. |
Source code in src/solidworks_mcp/agents/history_db.py
insert_plan_checkpoint ¶
insert_plan_checkpoint(*, session_id: str, checkpoint_index: int, title: str, planned_action_json: str, approved_by_user: bool = False, executed: bool = False, result_json: str | None = None, rollback_snapshot_id: int | None = None, db_path: Path | None = None) -> int
Insert a new checkpoint and return its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
checkpoint_index
|
int
|
The checkpoint index value. |
required |
title
|
str
|
The title value. |
required |
planned_action_json
|
str
|
The planned action json value. |
required |
approved_by_user
|
bool
|
The approved by user value. Defaults to False. |
False
|
executed
|
bool
|
The executed value. Defaults to False. |
False
|
result_json
|
str | None
|
The result json value. Defaults to None. |
None
|
rollback_snapshot_id
|
int | None
|
The rollback snapshot id value. Defaults to None. |
None
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The computed numeric result. |
Source code in src/solidworks_mcp/agents/history_db.py
insert_run ¶
insert_run(*, run_id: str, agent_name: str, prompt: str, status: str, output_json: str | None, model_name: str | None, db_path: Path | None = None) -> None
Record one prompt run and optionally the validated output payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_id
|
str
|
The run id value. |
required |
agent_name
|
str
|
The agent name value. |
required |
prompt
|
str
|
The prompt value. |
required |
status
|
str
|
The status value. |
required |
output_json
|
str | None
|
The output json value. |
required |
model_name
|
str | None
|
Embedding model name to use. |
required |
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
None. |
Source code in src/solidworks_mcp/agents/history_db.py
insert_sketch_graph_snapshot ¶
insert_sketch_graph_snapshot(*, session_id: str, nodes_json: str, edges_json: str, model_path: str | None = None, graph_format: str = 'json', metadata_json: str | None = None, db_path: Path | None = None) -> None
Store lightweight sketch graph snapshots in SQLite (Section F).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
nodes_json
|
str
|
The nodes json value. |
required |
edges_json
|
str
|
The edges json value. |
required |
model_path
|
str | None
|
The model path value. Defaults to None. |
None
|
graph_format
|
str
|
The graph format value. Defaults to "json". |
'json'
|
metadata_json
|
str | None
|
The metadata json value. Defaults to None. |
None
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
None. |
Source code in src/solidworks_mcp/agents/history_db.py
insert_tool_call_record ¶
insert_tool_call_record(*, session_id: str, tool_name: str, checkpoint_id: int | None = None, run_id: str | None = None, input_json: str | None = None, output_json: str | None = None, success: bool = True, latency_ms: float | None = None, db_path: Path | None = None) -> None
Insert one tool call execution record.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
tool_name
|
str
|
The tool name value. |
required |
checkpoint_id
|
int | None
|
The checkpoint id value. Defaults to None. |
None
|
run_id
|
str | None
|
The run id value. Defaults to None. |
None
|
input_json
|
str | None
|
The input json value. Defaults to None. |
None
|
output_json
|
str | None
|
The output json value. Defaults to None. |
None
|
success
|
bool
|
The success value. Defaults to True. |
True
|
latency_ms
|
float | None
|
The latency ms value. Defaults to None. |
None
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
None. |
Source code in src/solidworks_mcp/agents/history_db.py
insert_tool_event ¶
insert_tool_event(*, run_id: str, tool_name: str, phase: str, payload_json: str | None, db_path: Path | None = None) -> None
Store lifecycle events around MCP tool usage to aid troubleshooting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_id
|
str
|
The run id value. |
required |
tool_name
|
str
|
The tool name value. |
required |
phase
|
str
|
The phase value. |
required |
payload_json
|
str | None
|
The payload json value. |
required |
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
None. |
Source code in src/solidworks_mcp/agents/history_db.py
list_evidence_links ¶
list_evidence_links(session_id: str, checkpoint_id: int | None = None, db_path: Path | None = None) -> list[dict[str, Any]]
List evidence rows for a session and optional checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
checkpoint_id
|
int | None
|
The checkpoint id value. Defaults to None. |
None
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: A list containing the resulting items. |
Source code in src/solidworks_mcp/agents/history_db.py
list_model_state_snapshots ¶
List snapshots for a session newest first for diff/rollback flows.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: A list containing the resulting items. |
Source code in src/solidworks_mcp/agents/history_db.py
list_plan_checkpoints ¶
List all checkpoints for a session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: A list containing the resulting items. |
Source code in src/solidworks_mcp/agents/history_db.py
list_sketch_graph_snapshots ¶
list_sketch_graph_snapshots(session_id: str, model_path: str | None = None, db_path: Path | None = None) -> list[dict[str, Any]]
List sketch graph snapshots for a session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
model_path
|
str | None
|
The model path value. Defaults to None. |
None
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: A list containing the resulting items. |
Source code in src/solidworks_mcp/agents/history_db.py
list_tool_call_records ¶
list_tool_call_records(session_id: str, checkpoint_id: int | None = None, db_path: Path | None = None) -> list[dict[str, Any]]
List tool call records for a session and optional checkpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
checkpoint_id
|
int | None
|
The checkpoint id value. Defaults to None. |
None
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
list[dict[str, Any]]: A list containing the resulting items. |
Source code in src/solidworks_mcp/agents/history_db.py
replace_plan_checkpoints ¶
replace_plan_checkpoints(*, session_id: str, checkpoints: list[dict[str, Any]], db_path: Path | None = None) -> None
Replace all session checkpoints with a new ordered checkpoint list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
checkpoints
|
list[dict[str, Any]]
|
Replacement checkpoint records. |
required |
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
None. |
Source code in src/solidworks_mcp/agents/history_db.py
update_plan_checkpoint ¶
update_plan_checkpoint(checkpoint_id: int, *, approved_by_user: bool | None = None, executed: bool | None = None, result_json: str | None = None, rollback_snapshot_id: int | None = None, db_path: Path | None = None) -> None
Patch checkpoint approval/execution fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint_id
|
int
|
The checkpoint id value. |
required |
approved_by_user
|
bool | None
|
The approved by user value. Defaults to None. |
None
|
executed
|
bool | None
|
The executed value. Defaults to None. |
None
|
result_json
|
str | None
|
The result json value. Defaults to None. |
None
|
rollback_snapshot_id
|
int | None
|
The rollback snapshot id value. Defaults to None. |
None
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
None. |
Source code in src/solidworks_mcp/agents/history_db.py
update_plan_checkpoint_planned_action ¶
update_plan_checkpoint_planned_action(checkpoint_id: int, *, planned_action_json: str, executed: bool | None = None, result_json: str | None = None, db_path: Path | None = None) -> None
Update checkpoint planned-action JSON and optional execution status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint_id
|
int
|
Target checkpoint row ID. |
required |
planned_action_json
|
str
|
New planned action payload encoded as JSON string. |
required |
executed
|
bool | None
|
Optional executed flag override. |
None
|
result_json
|
str | None
|
Optional result payload override. |
None
|
db_path
|
Path | None
|
Optional SQLite path override. |
None
|
Source code in src/solidworks_mcp/agents/history_db.py
upsert_design_session ¶
upsert_design_session(*, session_id: str, user_goal: str, source_mode: str = 'model', accepted_family: str | None = None, status: str = 'active', current_checkpoint_index: int = 0, metadata_json: str | None = None, db_path: Path | None = None) -> None
Create or update one interactive design session row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session_id
|
str
|
The session id value. |
required |
user_goal
|
str
|
The user goal value. |
required |
source_mode
|
str
|
The source mode value. Defaults to "model". |
'model'
|
accepted_family
|
str | None
|
The accepted family value. Defaults to None. |
None
|
status
|
str
|
The status value. Defaults to "active". |
'active'
|
current_checkpoint_index
|
int
|
The current checkpoint index value. Defaults to 0. |
0
|
metadata_json
|
str | None
|
The metadata json value. Defaults to None. |
None
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
None |
None
|
None. |