HEDit Python API¶
This page documents the Python modules and classes in HEDit.
API Models¶
The API request/response models are defined using Pydantic:
src.api.models ¶
Pydantic models for API requests and responses.
AnnotationRequest ¶
Bases: BaseModel
Request model for HED annotation generation.
Attributes:
| Name | Type | Description |
|---|---|---|
description | str | Natural language event description to annotate |
schema_version | str | HED schema version to use |
max_validation_attempts | int | Maximum validation retry attempts |
run_assessment | bool | Whether to run final assessment (adds extra time) |
model | str | None | Override model for annotation (BYOK mode only) |
provider | str | None | Override provider preference (BYOK mode only) |
temperature | float | None | Override LLM temperature (BYOK mode only) |
Source code in hedit/src/api/models.py
AnnotationResponse ¶
Bases: BaseModel
Response model for HED annotation generation.
Attributes:
| Name | Type | Description |
|---|---|---|
annotation | str | Generated HED annotation string |
is_valid | bool | Whether the annotation passed validation |
is_faithful | bool | Whether the annotation is faithful to description |
is_complete | bool | Whether the annotation is complete |
validation_attempts | int | Number of validation attempts made |
validation_errors | list[str] | List of validation errors (if any) |
validation_warnings | list[str] | List of validation warnings (if any) |
evaluation_feedback | str | Evaluation agent feedback |
assessment_feedback | str | Assessment agent feedback |
status | str | Overall workflow status |
Source code in hedit/src/api/models.py
ValidationRequest ¶
Bases: BaseModel
Request model for HED validation only.
Attributes:
| Name | Type | Description |
|---|---|---|
hed_string | str | HED annotation string to validate |
schema_version | str | HED schema version to use |
Source code in hedit/src/api/models.py
ValidationResponse ¶
Bases: BaseModel
Response model for HED validation.
Attributes:
| Name | Type | Description |
|---|---|---|
is_valid | bool | Whether the HED string is valid |
errors | list[str] | List of validation errors |
warnings | list[str] | List of validation warnings |
parsed_string | str | None | Normalized HED string (if valid) |
Source code in hedit/src/api/models.py
ImageAnnotationRequest ¶
Bases: BaseModel
Request model for image-based HED annotation generation.
Attributes:
| Name | Type | Description |
|---|---|---|
image | str | Base64 encoded image or data URI |
prompt | str | None | Optional custom prompt for vision model (uses default if not provided) |
schema_version | str | HED schema version to use |
max_validation_attempts | int | Maximum validation retry attempts |
run_assessment | bool | Whether to run final assessment (adds extra time) |
model | str | None | Override model for annotation (BYOK mode only) |
vision_model | str | None | Override vision model for image description (BYOK mode only) |
provider | str | None | Override provider preference (BYOK mode only) |
temperature | float | None | Override LLM temperature (BYOK mode only) |
Source code in hedit/src/api/models.py
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 206 | |
ImageAnnotationResponse ¶
Bases: BaseModel
Response model for image-based HED annotation generation.
Attributes:
| Name | Type | Description |
|---|---|---|
image_description | str | Generated description from vision model |
annotation | str | Generated HED annotation string |
is_valid | bool | Whether the annotation passed validation |
is_faithful | bool | Whether the annotation is faithful to description |
is_complete | bool | Whether the annotation is complete |
validation_attempts | int | Number of validation attempts made |
validation_errors | list[str] | List of validation errors (if any) |
validation_warnings | list[str] | List of validation warnings (if any) |
evaluation_feedback | str | Evaluation agent feedback |
assessment_feedback | str | Assessment agent feedback |
status | str | Overall workflow status |
image_metadata | dict | Metadata about the processed image |
Source code in hedit/src/api/models.py
HealthResponse ¶
Bases: BaseModel
Response model for health check.
Attributes:
| Name | Type | Description |
|---|---|---|
status | str | Service status |
version | str | API version |
llm_available | bool | Whether LLM is available |
validator_available | bool | Whether HED validator is available |
Source code in hedit/src/api/models.py
FeedbackRequest ¶
Bases: BaseModel
Request model for submitting user feedback.
Attributes:
| Name | Type | Description |
|---|---|---|
type | str | Feedback type (text or image annotation) |
description | str | None | Original input description (for text mode) |
image_description | str | None | Image description (for image mode) |
annotation | str | Generated HED annotation |
is_valid | bool | Whether the annotation was valid |
is_faithful | bool | None | Whether the annotation was faithful |
is_complete | bool | None | Whether the annotation was complete |
validation_errors | list[str] | List of validation errors |
validation_warnings | list[str] | List of validation warnings |
evaluation_feedback | str | Evaluation agent feedback |
assessment_feedback | str | Assessment agent feedback |
user_comment | str | None | Optional user comment about the annotation |
Source code in hedit/src/api/models.py
FeedbackResponse ¶
Bases: BaseModel
Response model for feedback submission.
Attributes:
| Name | Type | Description |
|---|---|---|
success | bool | Whether feedback was saved successfully |
feedback_id | str | Unique identifier for the feedback |
message | str | Status message |
Source code in hedit/src/api/models.py
CLI Module¶
The CLI is built with Typer:
src.cli.main ¶
HEDit CLI - Main entry point.
Command-line interface for generating HED annotations from natural language. Supports two execution modes: - API mode (default): Uses api.annotation.garden backend - Standalone mode: Runs LangGraph workflow locally (requires hedit[standalone])
get_executor(config, api_key, mode_override=None, user_id=None) ¶
Get the appropriate execution backend based on configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config | CLIConfig | CLI configuration | required |
api_key | str | None | OpenRouter API key | required |
mode_override | str | None | Override mode from --standalone/--api flags | None |
user_id | str | None | Custom user ID for cache optimization (default: auto-generated) | None |
Returns:
| Type | Description |
|---|---|
ExecutionBackend | Configured ExecutionBackend instance |
Raises:
| Type | Description |
|---|---|
Exit | If standalone mode requested but dependencies not available |
Source code in hedit/src/cli/main.py
version_callback(value) ¶
main(version=False) ¶
HEDit CLI - Generate HED annotations from natural language.
Convert event descriptions to valid HED (Hierarchical Event Descriptors) annotations using AI-powered multi-agent system.
Get started
hedit init --api-key YOUR_OPENROUTER_KEY hedit annotate "A red circle appears on screen"
Source code in hedit/src/cli/main.py
init(api_key=None, api_url=None, model=None, provider=None, temperature=None, standalone=False) ¶
Initialize HEDit CLI with your API key and preferences.
This saves your configuration to ~/.config/hedit/ so you don't need to provide the API key for every command.
Get an OpenRouter API key at: https://openrouter.ai/keys
Examples:
hedit init --api-key YOUR_KEY # API mode (default) hedit init --api-key YOUR_KEY --standalone # Standalone mode
Source code in hedit/src/cli/main.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |
annotate(description, api_key=None, api_url=None, model=None, eval_model=None, eval_provider=None, provider=None, temperature=None, schema_version=None, output_format='text', max_attempts=5, assessment=False, no_streaming=False, no_extend=False, standalone=False, api_mode=False, verbose=False, user_id=None) ¶
Generate HED annotation from a text description.
Examples:
hedit annotate "A red circle appears on the left side of the screen" hedit annotate "Participant pressed the spacebar" --schema 8.4.0 hedit annotate "Audio beep plays" -o json > result.json hedit annotate "..." --model gpt-4o-mini --temperature 0.2 hedit annotate "..." --standalone # Run locally hedit annotate "..." --no-streaming # Disable live progress hedit annotate "..." --standalone --no-extend # No tag extensions
Source code in hedit/src/cli/main.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 | |
annotate_image(image, prompt=None, api_key=None, api_url=None, model=None, eval_model=None, eval_provider=None, provider=None, temperature=None, schema_version=None, output_format='text', max_attempts=5, assessment=False, no_streaming=False, no_extend=False, standalone=False, api_mode=False, verbose=False, user_id=None) ¶
Generate HED annotation from an image.
First generates a description using a vision model, then annotates it.
Examples:
hedit annotate-image stimulus.png hedit annotate-image photo.jpg --prompt "Describe the experimental setup" hedit annotate-image screen.png -o json > result.json hedit annotate-image stimulus.png --standalone # Run locally hedit annotate-image stimulus.png --no-streaming # Disable live progress hedit annotate-image stimulus.png --standalone --no-extend # No tag extensions
Source code in hedit/src/cli/main.py
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 | |
validate(hed_string, api_key=None, api_url=None, schema_version=None, output_format='text', standalone=False, api_mode=False) ¶
Validate a HED annotation string.
Checks if the HED string is syntactically correct and semantically valid according to the HED schema.
Examples:
hedit validate "Sensory-event, Visual-presentation" hedit validate "(Red, Circle)" --schema 8.4.0 hedit validate "Event" -o json hedit validate "Event" --standalone # Validate locally with hedtools
Source code in hedit/src/cli/main.py
config_show(show_key=False) ¶
Show current configuration.
Source code in hedit/src/cli/main.py
config_set(key, value) ¶
Set a configuration value.
Examples:
hedit config set models.default gpt-4o hedit config set settings.temperature 0.2 hedit config set api.url https://api.example.com/hedit
Source code in hedit/src/cli/main.py
config_path() ¶
Show configuration file paths.
Source code in hedit/src/cli/main.py
config_clear_credentials(force=False) ¶
Remove stored API credentials.
Source code in hedit/src/cli/main.py
config_reset_cmd(force=False, clear_key=False) ¶
Reset configuration to defaults.
By default, this keeps your stored API key intact. Use --clear-key to also remove it.
Examples:
hedit config reset # Reset to defaults, keep API key hedit config reset --clear-key # Reset everything including API key hedit config reset -f # Reset without confirmation
Source code in hedit/src/cli/main.py
health(api_url=None, standalone=False, api_mode=False) ¶
Check health status of the execution backend.
Examples:
hedit health # Check API health hedit health --standalone # Check standalone mode dependencies
Source code in hedit/src/cli/main.py
show_telemetry_disclosure() ¶
Display first-run telemetry disclosure notice.
Source code in hedit/src/cli/main.py
Configuration¶
src.cli.config ¶
Configuration management for HEDit CLI.
Handles persistent storage of API keys and settings in a cross-platform config directory. Supports environment variables as fallback/override.
CredentialsConfig ¶
Bases: BaseModel
Credentials stored separately with restricted permissions.
Source code in hedit/src/cli/config.py
ModelsConfig ¶
Bases: BaseModel
Model configuration for different agents.
Source code in hedit/src/cli/config.py
ExecutionMode ¶
SettingsConfig ¶
Bases: BaseModel
General settings.
Source code in hedit/src/cli/config.py
OutputConfig ¶
Bases: BaseModel
Output formatting settings.
Source code in hedit/src/cli/config.py
APIConfig ¶
TelemetryConfig ¶
Bases: BaseModel
Telemetry configuration.
Source code in hedit/src/cli/config.py
CLIConfig ¶
Bases: BaseModel
Complete CLI configuration.
Source code in hedit/src/cli/config.py
ensure_config_dir() ¶
load_credentials() ¶
Load credentials from file or environment.
Environment variables take precedence over stored credentials.
Source code in hedit/src/cli/config.py
save_credentials(creds) ¶
Save credentials to file with restricted permissions.
Source code in hedit/src/cli/config.py
load_config() ¶
Load configuration from file.
Source code in hedit/src/cli/config.py
save_config(config) ¶
get_api_key(override=None) ¶
Get API key with priority: override > env > stored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
override | str | None | Explicit API key from command line | None |
Returns:
| Type | Description |
|---|---|
str | None | API key or None if not configured |
Source code in hedit/src/cli/config.py
get_effective_config(api_key=None, api_url=None, model=None, eval_model=None, eval_provider=None, provider=None, temperature=None, schema_version=None, output_format=None, mode=None, user_id=None) ¶
Get effective config with command-line overrides applied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key | str | None | Override API key | None |
api_url | str | None | Override API URL | None |
model | str | None | Override model (if non-default, clears provider unless explicitly set) | None |
eval_model | str | None | Override evaluation model (for consistent benchmarking) | None |
eval_provider | str | None | Override provider for evaluation model (e.g., "alibaba") | None |
provider | str | None | Override provider preference (e.g., "anthropic") | None |
temperature | float | None | Override temperature | None |
schema_version | str | None | Override schema version | None |
output_format | str | None | Override output format | None |
mode | str | None | Override execution mode ("api" or "standalone") | None |
user_id | str | None | Override user ID for cache optimization | None |
Returns:
| Type | Description |
|---|---|
tuple[CLIConfig, str | None] | Tuple of (effective config, effective API key) |
Note
When a custom model is specified without an explicit provider, the provider is cleared. This is because a pinned provider may only support specific models.
Source code in hedit/src/cli/config.py
update_config(key, value) ¶
Update a specific config value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | Dot-notation key (e.g., "models.default", "settings.temperature") | required |
value | Any | New value | required |
Source code in hedit/src/cli/config.py
clear_credentials() ¶
reset_config(preserve_credentials=True) ¶
Reset configuration to defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
preserve_credentials | bool | If True, keep BYOK API key intact (default: True) | True |
Returns:
| Type | Description |
|---|---|
CLIConfig | The new default configuration |
Source code in hedit/src/cli/config.py
get_machine_id() ¶
Get or generate a stable machine ID for cache optimization.
This ID is used by OpenRouter for sticky cache routing to reduce costs. It is NOT used for telemetry and is never transmitted except to OpenRouter.
The ID is generated once and persists across pip updates.
Returns:
| Type | Description |
|---|---|
str | 16-character hexadecimal machine ID |
Source code in hedit/src/cli/config.py
is_first_run() ¶
Check if this is the first time HEDit is run.
Returns:
| Type | Description |
|---|---|
bool | True if first run, False otherwise |
mark_first_run_complete() ¶
Mark first run as complete by creating the marker file.
get_config_paths() ¶
Get paths to config files for debugging.
API Client¶
src.cli.client ¶
HTTP client for HEDit API.
Handles all API communication with proper error handling and timeout management.
APIError ¶
Bases: Exception
API request error.
Source code in hedit/src/cli/client.py
HEDitClient ¶
Client for HEDit API.
Source code in hedit/src/cli/client.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | |
__init__(api_url, api_key=None, model=None, eval_model=None, eval_provider=None, provider=None, temperature=None, timeout=DEFAULT_TIMEOUT, user_id=None) ¶
Initialize client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_url | str | Base API URL | required |
api_key | str | None | OpenRouter API key for BYOK mode | None |
model | str | None | Model to use for annotation | None |
eval_model | str | None | Model for evaluation/assessment agents (for fair benchmarking) | None |
eval_provider | str | None | Provider for evaluation model (e.g., Cerebras for qwen models) | None |
provider | str | None | Provider preference (e.g., "Cerebras") | None |
temperature | float | None | LLM temperature (0.0-1.0) | None |
timeout | Timeout | Request timeout settings | DEFAULT_TIMEOUT |
user_id | str | None | Custom user ID for cache optimization (default: derived from API key) | None |
Source code in hedit/src/cli/client.py
annotate(description, schema_version='8.4.0', max_validation_attempts=5, run_assessment=False, no_extend=False) ¶
Generate HED annotation from text description.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
description | str | Natural language event description | required |
schema_version | str | HED schema version | '8.4.0' |
max_validation_attempts | int | Maximum validation retries | 5 |
run_assessment | bool | Whether to run assessment | False |
no_extend | bool | If True, prohibit tag extensions | False |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Annotation response dictionary |
Source code in hedit/src/cli/client.py
annotate_stream(description, schema_version='8.4.0', max_validation_attempts=5, run_assessment=False, no_extend=False) ¶
Generate HED annotation with streaming progress.
Yields SSE events as (event_type, data) tuples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
description | str | Natural language event description | required |
schema_version | str | HED schema version | '8.4.0' |
max_validation_attempts | int | Maximum validation retries | 5 |
run_assessment | bool | Whether to run assessment | False |
no_extend | bool | If True, prohibit tag extensions | False |
Yields:
| Type | Description |
|---|---|
str | Tuple of (event_type, event_data) for each SSE event. |
dict[str, Any] | Event types: "progress", "validation", "result", "error", "done" |
Source code in hedit/src/cli/client.py
annotate_image(image_path, prompt=None, schema_version='8.4.0', max_validation_attempts=5, run_assessment=False, no_extend=False) ¶
Generate HED annotation from image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path | Path | str | Path to image file | required |
prompt | str | None | Optional custom prompt for vision model | None |
schema_version | str | HED schema version | '8.4.0' |
max_validation_attempts | int | Maximum validation retries | 5 |
run_assessment | bool | Whether to run assessment | False |
no_extend | bool | If True, prohibit tag extensions | False |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Annotation response dictionary |
Source code in hedit/src/cli/client.py
annotate_image_stream(image_path, prompt=None, schema_version='8.4.0', max_validation_attempts=5, run_assessment=False, no_extend=False) ¶
Generate HED annotation from image with streaming progress.
Yields SSE events as (event_type, data) tuples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_path | Path | str | Path to image file | required |
prompt | str | None | Optional custom prompt for vision model | None |
schema_version | str | HED schema version | '8.4.0' |
max_validation_attempts | int | Maximum validation retries | 5 |
run_assessment | bool | Whether to run assessment | False |
no_extend | bool | If True, prohibit tag extensions | False |
Yields:
| Type | Description |
|---|---|
str | Tuple of (event_type, event_data) for each SSE event. |
dict[str, Any] | Event types: "progress", "image_description", "validation", "result", "error", "done" |
Source code in hedit/src/cli/client.py
validate(hed_string, schema_version='8.4.0') ¶
Validate HED string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hed_string | str | HED annotation to validate | required |
schema_version | str | HED schema version | '8.4.0' |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Validation response dictionary |
Source code in hedit/src/cli/client.py
health() ¶
Check API health.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Health status dictionary |
Source code in hedit/src/cli/client.py
version() ¶
Get API version info.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Version information dictionary |
Source code in hedit/src/cli/client.py
create_client(config, api_key=None) ¶
Create API client from config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config | CLIConfig | CLI configuration | required |
api_key | str | None | API key (overrides config) | None |
Returns:
| Type | Description |
|---|---|
HEDitClient | Configured HEDitClient |
Source code in hedit/src/cli/client.py
Workflow¶
The multi-agent annotation workflow:
src.agents.workflow ¶
LangGraph workflow for HED annotation generation.
This module defines the multi-agent workflow that orchestrates annotation, validation, evaluation, and assessment.
HedAnnotationWorkflow ¶
Multi-agent workflow for HED annotation generation and validation.
The workflow follows this pattern: 1. Annotation: Generate HED tags from natural language 2. Validation: Check HED compliance 3. If errors and attempts < max: Return to annotation with feedback 4. If valid: Proceed to evaluation 5. Evaluation: Assess faithfulness to original description 6. If needs refinement: Return to annotation 7. If faithful: Proceed to assessment 8. Assessment: Final comparison for completeness 9. End: Return final annotation with feedback
Source code in hedit/src/agents/workflow.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 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 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 | |
__init__(llm, evaluation_llm=None, assessment_llm=None, feedback_llm=None, schema_dir=None, validator_path=None, use_js_validator=True, enable_semantic_search=True) ¶
Initialize the workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm | BaseChatModel | Language model for annotation agent | required |
evaluation_llm | BaseChatModel | None | Language model for evaluation agent (defaults to llm) | None |
assessment_llm | BaseChatModel | None | Language model for assessment agent (defaults to llm) | None |
feedback_llm | BaseChatModel | None | Language model for feedback summarization (defaults to llm) | None |
schema_dir | Path | str | None | Directory containing JSON schemas | None |
validator_path | Path | None | Path to hed-javascript for validation | None |
use_js_validator | bool | Whether to use JavaScript validator | True |
enable_semantic_search | bool | Whether to use hed-lsp CLI for tag suggestions | True |
Source code in hedit/src/agents/workflow.py
run(input_description, schema_version='8.4.0', max_validation_attempts=3, max_total_iterations=None, run_assessment=False, no_extend=False, config=None) async ¶
Run the complete annotation workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_description | str | Natural language event description | required |
schema_version | str | HED schema version to use | '8.4.0' |
max_validation_attempts | int | Maximum validation retry attempts | 3 |
max_total_iterations | int | None | Maximum total iterations (default: max_validation_attempts + 1) | None |
run_assessment | bool | Whether to run final assessment (default: False) | False |
no_extend | bool | If True, prohibit tag extensions (use only existing vocabulary) | False |
config | dict | None | Optional LangGraph config (e.g., recursion_limit) | None |
Returns:
| Type | Description |
|---|---|
HedAnnotationState | Final workflow state with annotation and feedback |
Source code in hedit/src/agents/workflow.py
Validation¶
src.validation.hed_validator ¶
HED validation using Python and JavaScript validators.
This module provides integration with HED validation tools. The validator factory supports JavaScript (most detailed) and Python (always available fallback) backends.
ValidationIssue dataclass ¶
Represents a single validation issue (error or warning).
Attributes:
| Name | Type | Description |
|---|---|---|
code | str | Issue code (e.g., 'TAG_INVALID') |
level | Literal['error', 'warning'] | Severity level ('error' or 'warning') |
message | str | Human-readable error message |
tag | str | None | The problematic tag (if applicable) |
context | dict | None | Additional context information |
Source code in hedit/src/validation/hed_validator.py
ValidationResult dataclass ¶
Result of HED string validation.
Attributes:
| Name | Type | Description |
|---|---|---|
is_valid | bool | Whether the HED string is valid |
errors | list[ValidationIssue] | List of error issues |
warnings | list[ValidationIssue] | List of warning issues |
parsed_string | str | None | Successfully parsed HED string (if valid) |
Source code in hedit/src/validation/hed_validator.py
HedPythonValidator ¶
Validates HED strings using the Python HED tools.
Source code in hedit/src/validation/hed_validator.py
__init__(schema) ¶
Initialize validator with a HED schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema | HedSchema | HedSchema object to validate against | required |
validate(hed_string) ¶
Validate a HED string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hed_string | str | HED annotation string to validate | required |
Returns:
| Type | Description |
|---|---|
ValidationResult | ValidationResult with errors and warnings |
Source code in hedit/src/validation/hed_validator.py
HedJavaScriptValidator ¶
Validates HED strings using the JavaScript HED validator.
This provides more detailed feedback than the Python validator. Requires Node.js and the hed-javascript package.
Source code in hedit/src/validation/hed_validator.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
__init__(validator_path, schema_version='8.4.0') ¶
Initialize JavaScript validator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validator_path | Path | Path to hed-javascript repository | required |
schema_version | str | HED schema version to use | '8.4.0' |
Source code in hedit/src/validation/hed_validator.py
validate(hed_string) ¶
Validate a HED string using JavaScript validator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hed_string | str | HED annotation string to validate | required |
Returns:
| Type | Description |
|---|---|
ValidationResult | ValidationResult with detailed errors and warnings |
Source code in hedit/src/validation/hed_validator.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 | |
is_js_validator_available(validator_path=None) ¶
Check if JavaScript validator is available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validator_path | Path | str | None | Path to hed-javascript. If None, uses HED_VALIDATOR_PATH env var. | None |
Returns:
| Type | Description |
|---|---|
bool | True if Node.js is installed and hed-javascript is available. |
Source code in hedit/src/validation/hed_validator.py
get_validator(schema_version='8.4.0', prefer_js=True, require_js=False, validator_path=None) ¶
Get the appropriate HED validator based on availability and preferences.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema_version | str | HED schema version (e.g., "8.3.0", "8.4.0") | '8.4.0' |
prefer_js | bool | If True, prefer JavaScript validator when available. | True |
require_js | bool | If True, raise error if JavaScript validator unavailable (no fallback) | False |
validator_path | Path | str | None | Path to hed-javascript. If None, uses HED_VALIDATOR_PATH env var. | None |
Returns:
| Type | Description |
|---|---|
HedPythonValidator | HedJavaScriptValidator | Configured validator instance |
Raises:
| Type | Description |
|---|---|
RuntimeError | If require_js=True and JavaScript validator is unavailable |