solidworks_mcp.agents¶
solidworks_mcp.agents ¶
Agent-testing utilities for SolidWorks MCP custom agents.
Attributes¶
DEFAULT_DB_PATH
module-attribute
¶
__all__
module-attribute
¶
__all__ = ['DEFAULT_DB_PATH', 'DocsPlan', 'ErrorRecord', 'ManufacturabilityReview', 'RecoverableFailure', 'ToolRoutingDecision', 'build_local_retrieval_index', 'find_conversation_events', 'get_design_session', 'find_recent_errors', 'find_run_timeline', 'init_db', 'insert_evidence_link', 'insert_model_state_snapshot', 'insert_plan_checkpoint', 'insert_sketch_graph_snapshot', 'insert_tool_call_record', 'insert_conversation_event', 'list_evidence_links', 'list_model_state_snapshots', 'list_plan_checkpoints', 'list_sketch_graph_snapshots', 'list_tool_call_records', 'pretty_json', 'run_validated_prompt', 'update_plan_checkpoint', 'upsert_design_session']
Classes¶
DocsPlan ¶
Bases: BaseModel
Validation shape for docs-engineering responses.
Attributes:
| Name | Type | Description |
|---|---|---|
audience |
str
|
The audience value. |
decisions |
list[ToolRoutingDecision]
|
The decisions value. |
demo_steps |
list[str]
|
The demo steps value. |
objective |
str
|
The objective value. |
sections |
list[str]
|
The sections 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. |
ManufacturabilityReview ¶
Bases: BaseModel
Validation shape for printability-focused agent responses.
Attributes:
| Name | Type | Description |
|---|---|---|
assumptions |
list[Assumption]
|
The assumptions value. |
build_volume_check |
str
|
The build volume check value. |
orientation_guidance |
str
|
The orientation guidance value. |
recommendations |
list[Recommendation]
|
The recommendations value. |
summary |
str
|
The summary value. |
tolerance_clearance_notes |
list[str]
|
The tolerance clearance notes value. |
RecoverableFailure ¶
Bases: BaseModel
Typed failure output used when agent needs user-guided retry.
Attributes:
| Name | Type | Description |
|---|---|---|
explanation |
str
|
The explanation value. |
remediation_steps |
list[str]
|
The remediation steps value. |
retry_focus |
str | None
|
The retry focus value. |
should_retry |
bool
|
The should retry value. |
ToolRoutingDecision ¶
Bases: BaseModel
Validation shape for tool-selection/skills documentation prompts.
Attributes:
| Name | Type | Description |
|---|---|---|
fallback_strategy |
list[str]
|
The fallback strategy value. |
intent |
str
|
The intent value. |
selected_tool_group |
str
|
The selected tool group value. |
why |
str
|
The why value. |
Functions¶
build_local_retrieval_index ¶
build_local_retrieval_index(*, output_path: Path | None = None, worked_examples_path: Path | None = None, tool_catalog_dir: Path | None = None, db_path: Path | None = None, max_recent_errors: int = 200) -> dict[str, Any]
Build a JSON retrieval index from local audits, tool docs, and failures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
Path | None
|
The output path value. Defaults to None. |
None
|
worked_examples_path
|
Path | None
|
The worked examples path value. Defaults to None. |
None
|
tool_catalog_dir
|
Path | None
|
The tool catalog dir value. Defaults to None. |
None
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
max_recent_errors
|
int
|
The max recent errors value. Defaults to 200. |
200
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: A dictionary containing the resulting values. |
Source code in src/solidworks_mcp/agents/retrieval_index.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
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_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_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
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
pretty_json ¶
Return pretty JSON for test output snapshots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
BaseModel
|
The model value. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The resulting text value. |
Source code in src/solidworks_mcp/agents/harness.py
run_validated_prompt
async
¶
run_validated_prompt(*, agent_file_name: str, model_name: str, user_prompt: str, result_type: type[TModel], max_retries_on_recoverable: int = 1, db_path: Path | None = None) -> TModel | RecoverableFailure
Run one prompt through PydanticAI and validate the output schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_file_name
|
str
|
The agent file name value. |
required |
model_name
|
str
|
Embedding model name to use. |
required |
user_prompt
|
str
|
The user prompt value. |
required |
result_type
|
type[TModel]
|
The result type value. |
required |
max_retries_on_recoverable
|
int
|
The max retries on recoverable value. Defaults to 1. |
1
|
db_path
|
Path | None
|
The db path value. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
TModel | RecoverableFailure
|
TModel | RecoverableFailure: The result produced by the operation. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
Pydantic_ai is not importable. Install dependencies and retry. |
Source code in src/solidworks_mcp/agents/harness.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
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
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. |