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) |
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) |
Source code in hedit/src/api/models.py
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. Uses the HEDit API (api.annotation.garden/hedit) with bring-your-own-key (BYOK) support.
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) ¶
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
Source code in hedit/src/cli/main.py
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 | |
annotate(description, api_key=None, api_url=None, model=None, provider=None, temperature=None, schema_version=None, output_format='text', max_attempts=5, assessment=False, verbose=False) ¶
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
Source code in hedit/src/cli/main.py
annotate_image(image, prompt=None, api_key=None, api_url=None, model=None, provider=None, temperature=None, schema_version=None, output_format='text', max_attempts=5, assessment=False, verbose=False) ¶
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
Source code in hedit/src/cli/main.py
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 | |
validate(hed_string, api_key=None, api_url=None, schema_version=None, output_format='text') ¶
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
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
health(api_url=None) ¶
Check API health status.
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
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 ¶
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, provider=None, temperature=None, schema_version=None, output_format=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 |
provider | str | None | Override provider preference (e.g., "Cerebras") | None |
temperature | float | None | Override temperature | None |
schema_version | str | None | Override schema version | None |
output_format | str | None | Override output format | 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 the default provider (Cerebras) only supports 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() ¶
get_config_paths() ¶
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
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 | |
__init__(api_url, api_key=None, model=None, provider=None, temperature=None, timeout=DEFAULT_TIMEOUT) ¶
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 |
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 |
Source code in hedit/src/cli/client.py
annotate(description, schema_version='8.3.0', max_validation_attempts=5, run_assessment=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.3.0' |
max_validation_attempts | int | Maximum validation retries | 5 |
run_assessment | bool | Whether to run assessment | False |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Annotation response dictionary |
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) ¶
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 |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Annotation response dictionary |
Source code in hedit/src/cli/client.py
validate(hed_string, schema_version='8.3.0') ¶
Validate HED string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hed_string | str | HED annotation to validate | required |
schema_version | str | HED schema version | '8.3.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
21 22 23 24 25 26 27 28 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 | |
__init__(llm, evaluation_llm=None, assessment_llm=None, feedback_llm=None, schema_dir=None, validator_path=None, use_js_validator=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 |
Source code in hedit/src/agents/workflow.py
run(input_description, schema_version='8.3.0', max_validation_attempts=5, max_total_iterations=10, run_assessment=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.3.0' |
max_validation_attempts | int | Maximum validation retry attempts | 5 |
max_total_iterations | int | Maximum total iterations to prevent infinite loops | 10 |
run_assessment | bool | Whether to run final assessment (default: False) | 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 both Python and JavaScript validators.
This module provides integration with HED validation tools, primarily using the JavaScript validator for comprehensive feedback, with Python fallback.
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
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 | |
__init__(validator_path, schema_version='8.3.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.3.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
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 | |