🚀 Major Enhancement: Workflow-Based Tool Architecture v5.5.0 (#95)
* WIP: new workflow architecture * WIP: further improvements and cleanup * WIP: cleanup and docks, replace old tool with new * WIP: cleanup and docks, replace old tool with new * WIP: new planner implementation using workflow * WIP: precommit tool working as a workflow instead of a basic tool Support for passing False to use_assistant_model to skip external models completely and use Claude only * WIP: precommit workflow version swapped with old * WIP: codereview * WIP: replaced codereview * WIP: replaced codereview * WIP: replaced refactor * WIP: workflow for thinkdeep * WIP: ensure files get embedded correctly * WIP: thinkdeep replaced with workflow version * WIP: improved messaging when an external model's response is received * WIP: analyze tool swapped * WIP: updated tests * Extract only the content when building history * Use "relevant_files" for workflow tools only * WIP: updated tests * Extract only the content when building history * Use "relevant_files" for workflow tools only * WIP: fixed get_completion_next_steps_message missing param * Fixed tests Request for files consistently * Fixed tests Request for files consistently * Fixed tests * New testgen workflow tool Updated docs * Swap testgen workflow * Fix CI test failures by excluding API-dependent tests - Update GitHub Actions workflow to exclude simulation tests that require API keys - Fix collaboration tests to properly mock workflow tool expert analysis calls - Update test assertions to handle new workflow tool response format - Ensure unit tests run without external API dependencies in CI 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * WIP - Update tests to match new tools * WIP - Update tests to match new tools --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
parent
4dae6e457e
commit
69a3121452
163
tools/shared/schema_builders.py
Normal file
163
tools/shared/schema_builders.py
Normal file
@@ -0,0 +1,163 @@
|
||||
"""
|
||||
Core schema building functionality for Zen MCP tools.
|
||||
|
||||
This module provides base schema generation functionality for simple tools.
|
||||
Workflow-specific schema building is located in workflow/schema_builders.py
|
||||
to maintain proper separation of concerns.
|
||||
"""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from .base_models import COMMON_FIELD_DESCRIPTIONS
|
||||
|
||||
|
||||
class SchemaBuilder:
|
||||
"""
|
||||
Base schema builder for simple MCP tools.
|
||||
|
||||
This class provides static methods to build consistent schemas for simple tools.
|
||||
Workflow tools use WorkflowSchemaBuilder in workflow/schema_builders.py.
|
||||
"""
|
||||
|
||||
# Common field schemas that can be reused across all tool types
|
||||
COMMON_FIELD_SCHEMAS = {
|
||||
"temperature": {
|
||||
"type": "number",
|
||||
"description": COMMON_FIELD_DESCRIPTIONS["temperature"],
|
||||
"minimum": 0.0,
|
||||
"maximum": 1.0,
|
||||
},
|
||||
"thinking_mode": {
|
||||
"type": "string",
|
||||
"enum": ["minimal", "low", "medium", "high", "max"],
|
||||
"description": COMMON_FIELD_DESCRIPTIONS["thinking_mode"],
|
||||
},
|
||||
"use_websearch": {
|
||||
"type": "boolean",
|
||||
"description": COMMON_FIELD_DESCRIPTIONS["use_websearch"],
|
||||
"default": True,
|
||||
},
|
||||
"continuation_id": {
|
||||
"type": "string",
|
||||
"description": COMMON_FIELD_DESCRIPTIONS["continuation_id"],
|
||||
},
|
||||
"images": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": COMMON_FIELD_DESCRIPTIONS["images"],
|
||||
},
|
||||
}
|
||||
|
||||
# Simple tool-specific field schemas (workflow tools use relevant_files instead)
|
||||
SIMPLE_FIELD_SCHEMAS = {
|
||||
"files": {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": COMMON_FIELD_DESCRIPTIONS["files"],
|
||||
},
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def build_schema(
|
||||
tool_specific_fields: dict[str, dict[str, Any]] = None,
|
||||
required_fields: list[str] = None,
|
||||
model_field_schema: dict[str, Any] = None,
|
||||
auto_mode: bool = False,
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
Build complete schema for simple tools.
|
||||
|
||||
Args:
|
||||
tool_specific_fields: Additional fields specific to the tool
|
||||
required_fields: List of required field names
|
||||
model_field_schema: Schema for the model field
|
||||
auto_mode: Whether the tool is in auto mode (affects model requirement)
|
||||
|
||||
Returns:
|
||||
Complete JSON schema for the tool
|
||||
"""
|
||||
properties = {}
|
||||
|
||||
# Add common fields (temperature, thinking_mode, etc.)
|
||||
properties.update(SchemaBuilder.COMMON_FIELD_SCHEMAS)
|
||||
|
||||
# Add simple tool-specific fields (files field for simple tools)
|
||||
properties.update(SchemaBuilder.SIMPLE_FIELD_SCHEMAS)
|
||||
|
||||
# Add model field if provided
|
||||
if model_field_schema:
|
||||
properties["model"] = model_field_schema
|
||||
|
||||
# Add tool-specific fields if provided
|
||||
if tool_specific_fields:
|
||||
properties.update(tool_specific_fields)
|
||||
|
||||
# Build required fields list
|
||||
required = required_fields or []
|
||||
if auto_mode and "model" not in required:
|
||||
required.append("model")
|
||||
|
||||
# Build the complete schema
|
||||
schema = {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"type": "object",
|
||||
"properties": properties,
|
||||
"additionalProperties": False,
|
||||
}
|
||||
|
||||
if required:
|
||||
schema["required"] = required
|
||||
|
||||
return schema
|
||||
|
||||
@staticmethod
|
||||
def get_common_fields() -> dict[str, dict[str, Any]]:
|
||||
"""Get the standard field schemas for simple tools."""
|
||||
return SchemaBuilder.COMMON_FIELD_SCHEMAS.copy()
|
||||
|
||||
@staticmethod
|
||||
def create_field_schema(
|
||||
field_type: str,
|
||||
description: str,
|
||||
enum_values: list[str] = None,
|
||||
minimum: float = None,
|
||||
maximum: float = None,
|
||||
items_type: str = None,
|
||||
default: Any = None,
|
||||
) -> dict[str, Any]:
|
||||
"""
|
||||
Helper method to create field schemas with common patterns.
|
||||
|
||||
Args:
|
||||
field_type: JSON schema type ("string", "number", "array", etc.)
|
||||
description: Human-readable description of the field
|
||||
enum_values: For enum fields, list of allowed values
|
||||
minimum: For numeric fields, minimum value
|
||||
maximum: For numeric fields, maximum value
|
||||
items_type: For array fields, type of array items
|
||||
default: Default value for the field
|
||||
|
||||
Returns:
|
||||
JSON schema object for the field
|
||||
"""
|
||||
schema = {
|
||||
"type": field_type,
|
||||
"description": description,
|
||||
}
|
||||
|
||||
if enum_values:
|
||||
schema["enum"] = enum_values
|
||||
|
||||
if minimum is not None:
|
||||
schema["minimum"] = minimum
|
||||
|
||||
if maximum is not None:
|
||||
schema["maximum"] = maximum
|
||||
|
||||
if items_type and field_type == "array":
|
||||
schema["items"] = {"type": items_type}
|
||||
|
||||
if default is not None:
|
||||
schema["default"] = default
|
||||
|
||||
return schema
|
||||
Reference in New Issue
Block a user