RQC API Reference¶
Complete API reference for Remote Quick Commands.
Main Classes¶
RemoteQuickCommand ¶
Synchronous client for executing Remote QuickCommands (RQC).
This client provides a high-level interface for executing Remote Quick Commands against the StackSpot AI API with built-in support for:
- Automatic polling until execution completes
- Exponential backoff with retries for transient failures
- Thread-based concurrency for batch execution
- Request/response logging to disk for debugging
Example
rqc = RemoteQuickCommand(slug_name="my-quick-command") request = RqcRequest(payload={"prompt": "Hello!"}) response = rqc.execute(request) if response.is_completed(): ... print(response.result)
Attributes:
| Name | Type | Description |
|---|---|---|
slug_name |
The Quick Command slug name to execute. |
|
base_url |
The base URL for the StackSpot AI API. |
|
options |
Consolidated configuration options (resolved with defaults from config). |
|
http_client |
HttpClient
|
HTTP client for API calls (default: EnvironmentAwareHttpClient). |
listeners |
list[RqcEventListener]
|
List of event listeners for observing execution lifecycle. |
Source code in src/stkai/rqc/_remote_quick_command.py
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 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 538 539 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 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 | |
Functions¶
execute ¶
Executes a Remote QuickCommand synchronously and waits for its completion (blocking).
This method sends a single request to the remote StackSpot AI QuickCommand API, monitors its execution until a terminal status is reached (COMPLETED, FAILURE, ERROR, or TIMEOUT), and returns an RqcResponse object containing the result or error details.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
RqcRequest
|
The RqcRequest instance representing the command to execute. |
required |
result_handler
|
RqcResultHandler | None
|
Optional custom handler used to process the raw response. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
RqcResponse |
RqcResponse
|
The final response object, always returned even if an error occurs. |
Source code in src/stkai/rqc/_remote_quick_command.py
execute_many ¶
execute_many(request_list: list[RqcRequest], result_handler: RqcResultHandler | None = None) -> list[RqcResponse]
Executes multiple RQC requests concurrently, waits for their completion (blocking), and returns their responses.
Each request is executed in parallel threads using the internal thread-pool.
Returns a list of RqcResponse objects in the same order as requests_list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request_list
|
list[RqcRequest]
|
List of RqcRequest objects to execute. |
required |
result_handler
|
RqcResultHandler | None
|
Optional custom handler used to process the raw response. |
None
|
Returns:
| Type | Description |
|---|---|
list[RqcResponse]
|
List[RqcResponse]: One response per request. |
Source code in src/stkai/rqc/_remote_quick_command.py
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 | |
Data Models¶
RqcRequest
dataclass
¶
Represents a Remote QuickCommand request.
This immutable class encapsulates all data needed to execute a Remote Quick Command, including the payload to send and optional metadata for tracking purposes.
Attributes:
| Name | Type | Description |
|---|---|---|
payload |
Any
|
The input data to send to the Quick Command. Can be any JSON-serializable object. |
id |
str
|
Unique identifier for this request. Auto-generated as UUID if not provided. |
metadata |
dict[str, Any]
|
Optional dictionary for storing custom metadata (e.g., source file, context). |
Example
request = RqcRequest( ... payload={"prompt": "Analyze this code", "code": "def foo(): pass"}, ... id="my-custom-id", ... metadata={"source": "main.py", "line": 42} ... )
Source code in src/stkai/rqc/_models.py
Functions¶
to_input_data ¶
write_to_file ¶
Persists the request payload to a JSON file for debugging purposes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
Path
|
Directory where the JSON file will be saved. |
required |
tracking_id
|
str | None
|
Optional tracking ID for file naming. If None, uses request id. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the created JSON file. |
The file is named {tracking_id}-request.json where tracking_id is either
the provided tracking_id or the request id.
Source code in src/stkai/rqc/_models.py
RqcResponse
dataclass
¶
Represents the full Remote QuickCommand response.
This immutable class contains the execution result, status, and any error information from a Remote Quick Command execution.
Attributes:
| Name | Type | Description |
|---|---|---|
request |
RqcRequest
|
The original RqcRequest that generated this response. |
status |
RqcExecutionStatus
|
The final status of the execution (COMPLETED, FAILURE, ERROR, or TIMEOUT). |
result |
Any | None
|
The processed result from the result handler (only set when COMPLETED). |
error |
str | None
|
Error message describing what went wrong (only set on non-COMPLETED status). |
raw_response |
Any | None
|
The raw JSON response from the StackSpot AI API (for debugging). |
execution_id |
str | None
|
The server-assigned execution ID, or None if execution was never created. |
Example
response = rqc.execute(request) if response.is_completed(): ... print(response.result) ... else: ... print(f"Error: {response.error}")
Source code in src/stkai/rqc/_models.py
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 | |
Attributes¶
raw_result
property
¶
Extracts the 'result' field from the raw API response, if available.
Functions¶
is_pending ¶
is_created ¶
is_running ¶
is_completed ¶
is_failure ¶
is_error ¶
is_timeout ¶
error_with_details ¶
Returns a dictionary with error details for non-completed responses.
Source code in src/stkai/rqc/_models.py
write_to_file ¶
Persists the response to a JSON file for debugging purposes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
Path
|
Directory where the JSON file will be saved. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the created JSON file. |
The file is named {tracking_id}-response-{status}.json where tracking_id
is either the execution_id (if available) or the request id.
Source code in src/stkai/rqc/_models.py
RqcExecutionStatus ¶
Bases: StrEnum
Status of an RQC execution lifecycle.
Attributes:
| Name | Type | Description |
|---|---|---|
PENDING |
Client-side status before request is submitted to server. |
|
CREATED |
Server acknowledged the request and created an execution. |
|
RUNNING |
Execution is currently being processed by the server. |
|
COMPLETED |
Execution finished successfully with a result. |
|
FAILURE |
Execution failed on the server-side (StackSpot AI returned an error). |
|
ERROR |
Client-side error occurred (network issues, invalid response, handler errors). |
|
TIMEOUT |
Any timeout, client or server-side (e.g., poll_max_duration, poll_overload_timeout, HTTP request timeout, HTTP 408, or HTTP 504). |
Source code in src/stkai/rqc/_models.py
Functions¶
from_server
classmethod
¶
Safely converts a server status string to an RqcExecutionStatus.
Only accepts server-side statuses (CREATED, RUNNING, COMPLETED, FAILURE). Returns None for None, empty strings, unknown values, or client-side-only statuses (PENDING, ERROR, TIMEOUT).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | None
|
The status string to convert, or None. |
required |
Returns:
| Type | Description |
|---|---|
RqcExecutionStatus | None
|
The corresponding RqcExecutionStatus, or None if the value is not |
RqcExecutionStatus | None
|
a recognized server-side status. |
Source code in src/stkai/rqc/_models.py
from_exception
classmethod
¶
Determine the appropriate status for an exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc
|
Exception
|
The exception that occurred during RQC execution. |
required |
Returns:
| Type | Description |
|---|---|
RqcExecutionStatus
|
TIMEOUT for timeout exceptions, ERROR for all others. |
Example
try: ... execution_id = rqc._create_execution(request) ... except Exception as e: ... status = RqcExecutionStatus.from_exception(e) ... # status is TIMEOUT if e is a timeout, ERROR otherwise
Source code in src/stkai/rqc/_models.py
Configuration Options¶
RqcOptions
dataclass
¶
Consolidated configuration options for RemoteQuickCommand.
Groups all options for RQC execution into a single configuration object. Fields set to None will use values from global config (STKAI.config.rqc).
Attributes:
| Name | Type | Description |
|---|---|---|
create_execution |
CreateExecutionOptions | None
|
Options for the create-execution phase. |
get_result |
GetResultOptions | None
|
Options for the get-result (polling) phase. |
max_workers |
int | None
|
Maximum number of threads for batch execution (execute_many). |
Example
Customize only what you need - rest comes from STKAI.config¶
options = RqcOptions( ... create_execution=CreateExecutionOptions(retry_max_retries=5), ... ) rqc = RemoteQuickCommand(slug_name="my-command", options=options)
Source code in src/stkai/rqc/_remote_quick_command.py
Functions¶
with_defaults_from ¶
Returns a new RqcOptions with None values filled from config.
User-provided values take precedence; None values use config defaults. This follows the Single Source of Truth principle where STKAI.config is the authoritative source for default values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
RqcConfig
|
The RqcConfig to use for default values. |
required |
Returns:
| Type | Description |
|---|---|
RqcOptions
|
A new RqcOptions with all fields resolved (no None values). |
Example
options = RqcOptions( ... create_execution=CreateExecutionOptions(retry_max_retries=5), ... ) resolved = options.with_defaults_from(STKAI.config.rqc) resolved.create_execution.retry_max_retries # 5 (user-defined) resolved.create_execution.retry_initial_delay # from config
Source code in src/stkai/rqc/_remote_quick_command.py
CreateExecutionOptions
dataclass
¶
Options for the create-execution phase.
Controls retry behavior and timeouts when creating a new RQC execution. Fields set to None will use values from global config (STKAI.config.rqc).
Attributes:
| Name | Type | Description |
|---|---|---|
retry_max_retries |
int | None
|
Maximum retry attempts for failed create-execution calls. Use 0 to disable retries (single attempt only). Use 3 for 4 total attempts (1 original + 3 retries). |
retry_initial_delay |
float | None
|
Initial delay in seconds for the first retry attempt. Subsequent retries use exponential backoff (delay doubles each attempt). |
request_timeout |
int | None
|
HTTP request timeout in seconds. |
Source code in src/stkai/rqc/_remote_quick_command.py
GetResultOptions
dataclass
¶
Options for the get-result (polling) phase.
Controls polling behavior and timeouts when waiting for execution completion. Fields set to None will use values from global config (STKAI.config.rqc).
Attributes:
| Name | Type | Description |
|---|---|---|
poll_interval |
float | None
|
Seconds to wait between polling status checks. |
poll_max_duration |
float | None
|
Maximum seconds to wait before timing out. |
poll_overload_timeout |
float | None
|
Maximum seconds to tolerate CREATED status before assuming server overload. |
request_timeout |
int | None
|
HTTP request timeout in seconds. |
Source code in src/stkai/rqc/_remote_quick_command.py
Result Handlers¶
RqcResultHandler ¶
Bases: ABC
Abstract base class for result handlers.
Result handlers are responsible for transforming the raw API response into a more useful format. Implement this class to create custom handlers.
Example
class MyHandler(RqcResultHandler): ... def handle_result(self, context: RqcResultContext) -> Any: ... return context.raw_result.upper()
Source code in src/stkai/rqc/_handlers.py
Functions¶
handle_result
abstractmethod
¶
Process the result and return the transformed value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
RqcResultContext
|
The RqcResultContext containing the raw result and request info. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The transformed result value. |
Note
Any exception raised will be wrapped in RqcResultHandlerError.
Source code in src/stkai/rqc/_handlers.py
RqcResultContext
dataclass
¶
Context passed to result handlers during processing.
This immutable class provides result handlers with all the information needed to process an execution result, including the original request and the raw result from the API.
Attributes:
| Name | Type | Description |
|---|---|---|
request |
RqcRequest
|
The original RqcRequest. |
raw_result |
Any
|
The unprocessed result from the StackSpot AI API. |
execution_id |
str
|
The server-assigned execution ID for this execution. |
handled |
bool
|
Flag indicating if a previous handler has already processed this result. |
Source code in src/stkai/rqc/_handlers.py
JsonResultHandler ¶
Bases: RqcResultHandler
Handler that parses JSON results into Python objects.
This is the default handler used by RemoteQuickCommand. It handles common response formats from StackSpot AI, including:
- Raw JSON strings
- JSON wrapped in markdown code blocks (
json ...) - Already-parsed dict objects (returns a deep copy)
Example
handler = JsonResultHandler() context = RqcResultContext(request=req, raw_result='{"key": "value"}') result = handler.handle_result(context) print(result) # {'key': 'value'}
Source code in src/stkai/rqc/_handlers.py
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 | |
Functions¶
handle_result ¶
Parses the raw result as JSON.
Handles markdown code block wrappers (json ...) automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
RqcResultContext
|
The result context containing the raw result. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Parsed Python object (dict, list, etc.) or None if result is empty. |
Raises:
| Type | Description |
|---|---|
JSONDecodeError
|
If the result is not valid JSON. |
TypeError
|
If the result is neither a string nor a dict. |
Examples:
- '{"ok": true}' -> {'ok': True}
- '
json\n{"x":1}\n' -> {'x': 1}
Source code in src/stkai/rqc/_handlers.py
chain_with
staticmethod
¶
Creates a chained handler with JSON parsing followed by another handler.
This is a convenience method for the common pattern of first parsing JSON and then applying additional transformations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other_handler
|
RqcResultHandler
|
Handler to execute after JSON parsing. |
required |
Returns:
| Type | Description |
|---|---|
RqcResultHandler
|
A ChainedResultHandler that first parses JSON, then applies other_handler. |
Example
handler = JsonResultHandler.chain_with(MyCustomHandler())
Source code in src/stkai/rqc/_handlers.py
RawResultHandler ¶
Bases: RqcResultHandler
Handler that returns the raw result without transformation.
Use this handler when you want to access the unprocessed API response, for example when debugging or when the result is not JSON.
Source code in src/stkai/rqc/_handlers.py
ChainedResultHandler ¶
Bases: RqcResultHandler
Handler that chains multiple handlers in sequence.
Each handler processes the result from the previous handler, allowing for complex transformation pipelines.
Example
handler = ChainedResultHandler.of([JsonResultHandler(), MyCustomHandler()])
First parses JSON, then applies custom transformation¶
Attributes:
| Name | Type | Description |
|---|---|---|
chained_handlers |
Sequence of handlers to execute in order. |
Source code in src/stkai/rqc/_handlers.py
Functions¶
__init__ ¶
Initialize with a sequence of handlers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chained_handlers
|
Sequence[RqcResultHandler]
|
Handlers to execute in order. |
required |
handle_result ¶
Executes each handler in sequence, passing results through the chain.
Source code in src/stkai/rqc/_handlers.py
of
staticmethod
¶
Factory method to create a ChainedResultHandler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handlers
|
RqcResultHandler | Sequence[RqcResultHandler]
|
A single handler or sequence of handlers. |
required |
Returns:
| Type | Description |
|---|---|
ChainedResultHandler
|
A ChainedResultHandler wrapping the provided handlers. |
Source code in src/stkai/rqc/_handlers.py
Event Listeners¶
RqcEventListener ¶
Base class for observing RQC execution lifecycle events.
Listeners are read-only observers: they can react to events, log, notify, or collect metrics, but should NOT modify the request or response.
The context dict is shared across all listener calls for a single execution,
allowing listeners to store and retrieve state (e.g., start time for telemetry).
All methods have default empty implementations, so subclasses only need to override the methods they care about.
Example
class MetricsListener(RqcEventListener): ... def on_before_execute(self, request, context): ... context['start_time'] = time.time() ... ... def on_after_execute(self, request, response, context): ... duration = time.time() - context['start_time'] ... statsd.timing('rqc.duration', duration)
Source code in src/stkai/rqc/_event_listeners.py
Functions¶
on_before_execute ¶
Called before starting the execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
RqcRequest
|
The request about to be executed. |
required |
context
|
dict[str, Any]
|
Mutable dict for sharing state between listener calls. |
required |
Source code in src/stkai/rqc/_event_listeners.py
on_status_change ¶
on_status_change(request: RqcRequest, old_status: RqcExecutionStatus, new_status: RqcExecutionStatus, context: dict[str, Any]) -> None
Called when the execution status changes throughout the lifecycle.
This method is invoked at key state transitions: - PENDING → CREATED: Execution was successfully created on the server. - PENDING → ERROR/TIMEOUT: Failed to create execution (network error, timeout, etc.). - CREATED → RUNNING: Server started processing the execution. - RUNNING → COMPLETED: Execution finished successfully. - RUNNING → FAILURE: Execution failed on the server-side. - Any → TIMEOUT: Polling timed out waiting for completion.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
RqcRequest
|
The request being executed. |
required |
old_status
|
RqcExecutionStatus
|
The previous status. |
required |
new_status
|
RqcExecutionStatus
|
The new status. |
required |
context
|
dict[str, Any]
|
Mutable dict for sharing state between listener calls. |
required |
Source code in src/stkai/rqc/_event_listeners.py
on_after_execute ¶
Called after execution completes (success or failure).
Check response.status or response.is_completed() to determine the outcome.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
RqcRequest
|
The executed request. |
required |
response
|
RqcResponse
|
The final response (always provided, check status for outcome). |
required |
context
|
dict[str, Any]
|
Mutable dict for sharing state between listener calls. |
required |
Source code in src/stkai/rqc/_event_listeners.py
RqcPhasedEventListener ¶
Bases: RqcEventListener
Abstract listener that exposes granular hooks for each execution phase.
This class implements the base RqcEventListener methods and delegates to phase-specific methods, making it easier to implement listeners focused on specific phases of the execution lifecycle.
Phase 1 - Create Execution
- on_create_execution_start: Before POST to create execution
- on_create_execution_end: After creation (success or failure)
Phase 2 - Get Result (Polling): - on_get_result_start: Before polling loop starts - on_get_result_end: After polling completes (any terminal status)
Example
class MetricsListener(RqcPhasedEventListener): ... def on_create_execution_start(self, request, context): ... context['create_start'] = time.time() ... ... def on_create_execution_end(self, request, status, response, context): ... duration = time.time() - context['create_start'] ... if status == RqcExecutionStatus.CREATED: ... statsd.timing('rqc.create.success', duration) ... else: ... statsd.timing('rqc.create.failure', duration)
Source code in src/stkai/rqc/_event_listeners.py
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 | |
Functions¶
on_create_execution_start ¶
Called before attempting to create the execution on the server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
RqcRequest
|
The request about to be submitted. |
required |
context
|
dict[str, Any]
|
Mutable dict for sharing state between listener calls. |
required |
Source code in src/stkai/rqc/_event_listeners.py
on_create_execution_end ¶
on_create_execution_end(request: RqcRequest, status: RqcExecutionStatus, response: RqcResponse | None, context: dict[str, Any]) -> None
Called after the create-execution phase completes (success or failure).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
RqcRequest
|
The request that was submitted. |
required |
status
|
RqcExecutionStatus
|
The resulting status (CREATED on success, ERROR/TIMEOUT on failure). |
required |
response
|
RqcResponse | None
|
The RqcResponse if creation failed (contains error details), None if creation succeeded (polling will start). |
required |
context
|
dict[str, Any]
|
Mutable dict for sharing state between listener calls. |
required |
Source code in src/stkai/rqc/_event_listeners.py
on_get_result_start ¶
Called before starting the polling loop.
Only called if create-execution succeeded (request.execution_id is set).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
RqcRequest
|
The request with execution_id already assigned. |
required |
context
|
dict[str, Any]
|
Mutable dict for sharing state between listener calls. |
required |
Source code in src/stkai/rqc/_event_listeners.py
on_get_result_end ¶
Called after the polling phase completes (any terminal status).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
RqcRequest
|
The executed request. |
required |
response
|
RqcResponse
|
The final response (COMPLETED, FAILURE, ERROR, or TIMEOUT). |
required |
context
|
dict[str, Any]
|
Mutable dict for sharing state between listener calls. |
required |
Source code in src/stkai/rqc/_event_listeners.py
on_before_execute ¶
Delegates to on_create_execution_start.
on_status_change ¶
on_status_change(request: RqcRequest, old_status: RqcExecutionStatus, new_status: RqcExecutionStatus, context: dict[str, Any]) -> None
Delegates to phase-specific methods based on status transitions.
- PENDING → CREATED: Calls on_create_execution_end (success) + on_get_result_start
- PENDING → ERROR/TIMEOUT: Handled in on_after_execute (failure case)
Source code in src/stkai/rqc/_event_listeners.py
on_after_execute ¶
Delegates to phase-specific methods based on execution outcome.
- No execution_id: Create-execution failed → on_create_execution_end
- Has execution_id: Polling finished → on_get_result_end
Source code in src/stkai/rqc/_event_listeners.py
FileLoggingListener ¶
Bases: RqcEventListener
Listener that persists request and response to JSON files for debugging.
This listener writes files to the specified output directory:
- {tracking_id}-request.json: The request payload
- {tracking_id}-response-{status}.json: The response result or error details
Example
listener = FileLoggingListener(Path("./output/rqc")) rqc = RemoteQuickCommand(slug_name="my-rqc", listeners=[listener])
Source code in src/stkai/rqc/_event_listeners.py
Functions¶
__init__ ¶
Initialize the listener with an output directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
Path | str
|
Directory where JSON files will be saved (Path or str). Created automatically if it doesn't exist. |
required |
Source code in src/stkai/rqc/_event_listeners.py
on_status_change ¶
on_status_change(request: RqcRequest, old_status: RqcExecutionStatus, new_status: RqcExecutionStatus, context: dict[str, Any]) -> None
Writes request file when status transitions from PENDING (for debugging).
Source code in src/stkai/rqc/_event_listeners.py
on_after_execute ¶
Writes response to JSON file after execution completes.
Source code in src/stkai/rqc/_event_listeners.py
Errors¶
MaxRetriesExceededError ¶
Bases: Exception
Raised when all retry attempts are exhausted.
This exception wraps the last exception that occurred during retry attempts, providing access to the original error for debugging.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
Human-readable error message. |
|
last_exception |
The original exception from the last retry attempt. |
Example
try: ... for attempt in Retrying(max_retries=3): ... with attempt: ... raise ConnectionError("Server unavailable") ... except MaxRetriesExceededError as e: ... print(f"Failed after retries: {e}") ... print(f"Original error: {e.last_exception}")
Source code in src/stkai/_retry.py
RqcResultHandlerError ¶
Bases: RuntimeError
Raised when the result handler fails to process the result.
This exception wraps any error that occurs during result processing, providing access to the original cause and the handler that failed.
Attributes:
| Name | Type | Description |
|---|---|---|
cause |
The original exception that caused the handler to fail. |
|
result_handler |
The handler instance that raised the error. |
Source code in src/stkai/rqc/_handlers.py
ExecutionIdIsMissingError ¶
Bases: RuntimeError
Raised when the execution ID is missing or not provided.
This exception indicates that the StackSpot AI API returned an invalid response without an execution ID after a create-execution request.