API Reference
OpenSymbolicAI Core Runtime.
CheckpointStatus
Bases: str, Enum
Status of an execution checkpoint.
Source code in src/opensymbolicai/checkpoint.py
CheckpointStore
Bases: Protocol
Protocol for checkpoint storage backends.
Implement this protocol to store checkpoints in your preferred backend (PostgreSQL, Redis, MongoDB, filesystem, etc.).
Example
class RedisCheckpointStore: def init(self, redis_client): self.redis = redis_client
def save(self, checkpoint: ExecutionCheckpoint) -> None:
self.redis.set(
f"checkpoint:{checkpoint.checkpoint_id}",
checkpoint.model_dump_json()
)
def load(self, checkpoint_id: str) -> ExecutionCheckpoint | None:
data = self.redis.get(f"checkpoint:{checkpoint_id}")
if data:
return ExecutionCheckpoint.model_validate_json(data)
return None
def delete(self, checkpoint_id: str) -> None:
self.redis.delete(f"checkpoint:{checkpoint_id}")
def list_by_status(self, status: CheckpointStatus) -> list[str]:
# Implementation depends on your indexing strategy
...
Source code in src/opensymbolicai/checkpoint.py
delete(checkpoint_id)
list_by_status(status)
load(checkpoint_id)
DecompositionInfo
Bases: BaseModel
Metadata describing a decomposition method, passed to PromptProvider selectors.
Source code in src/opensymbolicai/models.py
DesignExecute
Bases: PlanExecute
Agent that generates and executes Python plans with control flow.
DesignExecute extends PlanExecute to allow for, while, if/elif/else, try/except, and raise in LLM-generated plans while maintaining safety (loop limits, blocked dangerous ops) and full traceability (every primitive call is recorded).
Plans may include:
- Assignment statements: result = add(1, 2)
- For loops: for item in items:
- While loops: while condition:
- Conditionals: if/elif/else
- Try/except blocks: try: ... except ValueError: ...
- Raise statements: raise ValueError("message")
- break/continue (configurable)
Plans may NOT include: - Function/class definitions - Import statements - With blocks - exec/eval/open or other dangerous builtins - Private/dunder attribute access
Tracing works by wrapping all primitives with instrumentation wrappers that record each call (name, args, result, timing) into a flat trace.
Example::
class DataProcessor(DesignExecute):
@primitive(read_only=True)
def process(self, item: str) -> str:
return item.upper()
@primitive(read_only=True)
def summarize(self, items: list[str]) -> str:
return ", ".join(items)
Source code in src/opensymbolicai/blueprints/design_execute.py
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 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 | |
blueprint_type
property
The blueprint type: 'PlanExecute', 'DesignExecute', or 'GoalSeeking'.
design_config
property
Get the DesignExecute-specific config.
build_plan_prompt(task, feedback=None)
Build prompt that allows control flow.
Fully overrides the parent prompt to replace the rules section with DesignExecute-specific rules permitting loops and conditionals.
Source code in src/opensymbolicai/blueprints/design_execute.py
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 | |
execute(plan)
Execute a plan with control flow support and full tracing.
Unlike PlanExecute which executes statement-by-statement, this instruments all primitives with tracing wrappers and executes the entire plan as a single block. Loop guards are injected via AST transformation to prevent infinite loops.
Source code in src/opensymbolicai/blueprints/design_execute.py
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 | |
execute_stepwise(task, plan_context=None, serializer=None, checkpoint_id=None)
Not supported for DesignExecute.
Stepwise checkpoint execution is incompatible with block-based
control flow execution. Use execute() or run() instead.
Source code in src/opensymbolicai/blueprints/design_execute.py
validate_plan(plan)
Validate plan allowing control flow but blocking dangerous ops.
Compared to PlanExecute, this allows For, While, If, AugAssign, and Expr (bare function calls) at the top level.
Source code in src/opensymbolicai/blueprints/design_execute.py
DesignExecuteConfig
Bases: PlanExecuteConfig
Configuration for DesignExecute agents with control flow support.
Source code in src/opensymbolicai/models.py
EventType
Bases: str, Enum
Types of trace events emitted during agent execution.
Source code in src/opensymbolicai/observability/events.py
ExecutionCheckpoint
Bases: BaseModel
Serializable execution state for pause/resume across distributed workers.
Source code in src/opensymbolicai/checkpoint.py
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 | |
is_resumable
property
Check if this checkpoint can be resumed.
is_terminal
property
Check if this checkpoint is in a terminal state.
progress_fraction
property
Get execution progress as a fraction (0.0 to 1.0).
touch(worker_id=None)
Update the updated_at timestamp and optionally worker_id.
ExecutionError
Bases: Exception
Base exception for all primitive execution errors.
This is the root of the exception hierarchy. All custom exceptions should inherit from this class. When raised in a primitive, execution will stop and the error details will be captured in the execution trace.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
Human-readable error message. |
|
code |
Optional error code for programmatic handling. |
|
details |
Optional dictionary with additional context. |
|
halt_execution |
Whether this exception should stop plan execution. |
Source code in src/opensymbolicai/exceptions.py
__init__(message, *, code=None, details=None, halt_execution=True)
Initialize the exception.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error message. |
required |
code
|
str | None
|
Optional error code for programmatic handling (e.g., "INVALID_INPUT"). |
None
|
details
|
dict[str, Any] | None
|
Optional dictionary with additional context about the error. |
None
|
halt_execution
|
bool
|
Whether this exception should stop plan execution. Defaults to True. |
True
|
Source code in src/opensymbolicai/exceptions.py
__repr__()
Return detailed representation of the exception.
Source code in src/opensymbolicai/exceptions.py
__str__()
to_dict()
Convert exception to a dictionary for serialization.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing all exception attributes. |
Source code in src/opensymbolicai/exceptions.py
ExecutionMetrics
Bases: BaseModel
Metrics from a complete orchestration run.
Source code in src/opensymbolicai/models.py
total_time_seconds
property
Total time for planning and execution.
ExecutionResult
Bases: BaseModel
Result from executing a plan.
Source code in src/opensymbolicai/models.py
ExecutionStep
Bases: BaseModel
A single step in plan execution.
Source code in src/opensymbolicai/models.py
ExecutionTrace
Bases: BaseModel
Complete trace of plan execution.
Source code in src/opensymbolicai/models.py
all_succeeded
property
Check if all steps succeeded.
failed_steps
property
Get all failed steps.
last_step
property
Get the last executed step.
primitives_called
property
Get list of all primitives called.
step_count
property
Number of steps executed.
successful_steps
property
Get all successful steps.
FileCheckpointStore
File-based checkpoint store for simple persistence.
Source code in src/opensymbolicai/checkpoint.py
__init__(directory)
Initialize with a directory path for storing checkpoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
str
|
Path to directory where checkpoint JSON files are stored. |
required |
Source code in src/opensymbolicai/checkpoint.py
delete(checkpoint_id)
list_all()
list_by_status(status)
List checkpoint IDs with the given status.
Source code in src/opensymbolicai/checkpoint.py
load(checkpoint_id)
Load a checkpoint from a JSON file.
Source code in src/opensymbolicai/checkpoint.py
save(checkpoint)
Save a checkpoint to a JSON file.
FileTransport
Appends events as newline-delimited JSON to a file.
Each event is written as a single JSON line (JSONL format).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
File path to write to. Parent directories are created if needed. |
required |
Source code in src/opensymbolicai/observability/transports/file.py
close()
send(events)
Append events as JSONL to the file.
GoalContext
Bases: BaseModel
Accumulated structured knowledge across iterations.
This is the introspection boundary. Subclass to add domain-specific insight fields that update_context() populates from raw execution results. The planner and evaluator only see these fields — never raw results.
Source code in src/opensymbolicai/models.py
iteration_count
property
Number of completed iterations.
last_evaluation
property
Get the evaluation from the last iteration.
GoalEvaluation
Bases: BaseModel
Result of evaluating progress toward a goal.
Subclass to add domain-specific fields (findings, confidence, etc.)
Source code in src/opensymbolicai/models.py
goal_achieved
instance-attribute
Whether the goal has been achieved.
GoalSeeking
Bases: DesignExecute
Agent that iteratively pursues a goal through plan-execute-evaluate cycles.
GoalSeeking extends DesignExecute with an iterative loop that: 1. Plans the next step toward a goal 2. Executes the plan 3. Introspects results into structured context (the introspection boundary) 4. Evaluates progress toward the goal 5. Repeats until the goal is achieved or termination conditions are met
Evaluation uses a two-tier approach: - Tier 1 (static): An @evaluator-decorated method on the agent - Tier 2 (dynamic): LLM-generated evaluator code from the goal
Subclasses should: 1. Define @primitive methods for available operations 2. Optionally define an @evaluator method for static evaluation 3. Override update_context() to extract insights from execution results 4. Override create_context() to return a custom GoalContext subclass
Source code in src/opensymbolicai/blueprints/goal_seeking.py
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 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 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 | |
blueprint_type
property
The blueprint type: 'PlanExecute', 'DesignExecute', or 'GoalSeeking'.
__init__(llm, name='', description='', config=None)
Initialize the GoalSeeking agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm
|
LLM | LLMConfig
|
LLM instance or config for plan generation. |
required |
name
|
str
|
Agent name for prompts. |
''
|
description
|
str
|
Agent description for prompts. |
''
|
config
|
GoalSeekingConfig | None
|
GoalSeeking-specific configuration. |
None
|
Source code in src/opensymbolicai/blueprints/goal_seeking.py
build_evaluator_prompt(goal)
Build the prompt for evaluator code generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
goal
|
str
|
The goal to generate evaluator code for. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Prompt for the LLM to generate evaluator code. |
Source code in src/opensymbolicai/blueprints/goal_seeking.py
build_goal_prompt(goal, context, feedback=None)
Build the prompt for planning the next iteration.
Includes the original goal, available primitives, decomposition examples, and structured insights from context (NOT raw execution results).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
goal
|
str
|
The goal being pursued. |
required |
context
|
GoalContext
|
Accumulated context with structured insights. |
required |
feedback
|
str | None
|
Error feedback from a failed plan attempt (for retry). |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Complete prompt for plan generation. |
Source code in src/opensymbolicai/blueprints/goal_seeking.py
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 | |
create_context(goal)
Factory hook to create the initial context.
Override to return a custom context subclass.
on_goal_achieved(result)
Hook called when goal is achieved.
Override for notifications, cleanup, or celebration.
on_iteration_complete(iteration, context)
Hook called after each iteration completes.
Override for logging, metrics, or triggering side effects.
on_iteration_start(iteration_number, context)
Hook called at the start of each iteration.
Override for logging, metrics, or custom setup.
plan_evaluator(goal)
Generate evaluator code from the goal using the LLM.
Called once before the loop starts. The generated code must assign
result = GoalEvaluation(goal_achieved=...).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
goal
|
str
|
The goal to generate evaluator code for. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Python code string for evaluation. |
Source code in src/opensymbolicai/blueprints/goal_seeking.py
plan_iteration(goal, context, feedback=None)
Generate a plan for the next iteration.
Uses build_goal_prompt() directly (not self.plan()) to avoid double-wrapping the prompt through build_plan_prompt().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
goal
|
str
|
The goal being pursued. |
required |
context
|
GoalContext
|
Accumulated context from previous iterations. |
required |
feedback
|
str | None
|
Error feedback from a failed plan attempt (for retry). |
None
|
Returns:
| Type | Description |
|---|---|
PlanResult
|
PlanResult with the generated plan. |
Source code in src/opensymbolicai/blueprints/goal_seeking.py
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 | |
run_evaluator(evaluator_code, goal, context)
Execute generated evaluator code in a sandboxed namespace.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evaluator_code
|
str
|
The Python evaluator code to execute. |
required |
goal
|
str
|
The goal being pursued. |
required |
context
|
GoalContext
|
Accumulated context. |
required |
Returns:
| Type | Description |
|---|---|
EvaluatorResult
|
EvaluatorResult with the evaluation and any traced primitive steps. |
Source code in src/opensymbolicai/blueprints/goal_seeking.py
seek(goal)
Pursue a goal through iterative plan-execute-evaluate cycles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
goal
|
str
|
The goal to achieve (natural language). |
required |
Returns:
| Type | Description |
|---|---|
GoalSeekingResult
|
GoalSeekingResult with final answer and iteration history. |
Source code in src/opensymbolicai/blueprints/goal_seeking.py
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 | |
should_continue(context, evaluation)
Determine if the loop should continue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
GoalContext
|
The current goal context. |
required |
evaluation
|
GoalEvaluation
|
The latest evaluation result. |
required |
Returns:
| Type | Description |
|---|---|
tuple[bool, GoalStatus]
|
Tuple of (should_continue, status_if_stopping). |
Source code in src/opensymbolicai/blueprints/goal_seeking.py
update_context(context, execution_result)
THE INTROSPECTION BOUNDARY. Called after each execution.
This is where raw ExecutionResult is introspected into structured insights on the context. The planner and evaluator only see what this method writes into context — never the raw result.
Override to extract domain-specific insights from the execution result.
Source code in src/opensymbolicai/blueprints/goal_seeking.py
GoalSeekingConfig
Bases: DesignExecuteConfig
Configuration for GoalSeeking agents.
Source code in src/opensymbolicai/models.py
GoalSeekingResult
Bases: BaseModel
Result from a complete goal-seeking run.
Subclass to add domain-specific result fields.
Source code in src/opensymbolicai/models.py
iteration_count
property
Number of iterations performed.
succeeded
property
Whether the goal was achieved.
GoalStatus
HttpTransport
Batched HTTP transport using stdlib urllib.
Events are queued in memory and flushed by a background thread
either when the batch size is reached or on close().
On HTTP failure the batch is dropped with a warning to stderr. No retries — keep it simple.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
Collector endpoint (e.g. |
required |
batch_size
|
int
|
Flush after this many events are queued. |
50
|
flush_interval_seconds
|
float
|
Periodic flush interval. |
5.0
|
headers
|
dict[str, str] | None
|
Extra HTTP headers sent with every request
(e.g. |
None
|
Source code in src/opensymbolicai/observability/transports/http.py
15 16 17 18 19 20 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 | |
close()
flush()
InMemoryCheckpointStore
In-memory checkpoint store for testing and development.
Source code in src/opensymbolicai/checkpoint.py
clear()
delete(checkpoint_id)
list_all()
list_by_status(status)
List checkpoint IDs with the given status.
load(checkpoint_id)
save(checkpoint)
Save a checkpoint to memory.
InMemoryTransport
Stores trace events in memory.
Useful for testing and for inspecting events in the same process.
Source code in src/opensymbolicai/observability/transports/memory.py
close()
Iteration
Bases: BaseModel
A single iteration of the goal-seeking loop.
Source code in src/opensymbolicai/models.py
MethodType
MutationHookContext
Bases: BaseModel
Context passed to mutation hooks when a non-read-only primitive is called.
Source code in src/opensymbolicai/models.py
ObservabilityConfig
Bases: BaseModel
Controls what gets captured and where it goes.
When enabled is False (the default), no tracing overhead is incurred.
Source code in src/opensymbolicai/observability/config.py
OperationError
Bases: ExecutionError
Exception raised when an operation fails during execution.
Use this for runtime errors that occur during the actual operation, not input validation.
Example
raise OperationError( "File write failed", code="WRITE_FAILED", details={"path": "/tmp/output.txt", "reason": "disk full"} )
Source code in src/opensymbolicai/exceptions.py
__init__(message, *, code='OPERATION_ERROR', details=None, operation=None)
Initialize operation error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error message. |
required |
code
|
str | None
|
Error code, defaults to "OPERATION_ERROR". |
'OPERATION_ERROR'
|
details
|
dict[str, Any] | None
|
Additional context about the error. |
None
|
operation
|
str | None
|
Optional name of the operation that failed. |
None
|
Source code in src/opensymbolicai/exceptions.py
OrchestrationResult
Bases: BaseModel
Result from a complete plan-and-execute run.
Source code in src/opensymbolicai/models.py
ParameterInfo
Bases: BaseModel
Metadata for a single parameter of a primitive or decomposition method.
Source code in src/opensymbolicai/models.py
PendingMutation
Bases: BaseModel
Information about a mutation awaiting approval.
Source code in src/opensymbolicai/checkpoint.py
PlanAnalysis
Bases: BaseModel
Analysis of a plan's structure.
Source code in src/opensymbolicai/models.py
has_mutations
property
Check if any calls are not read-only.
method_names
property
Get list of all method names called.
PlanContext
Bases: BaseModel
Context about how the plan was generated.
Source code in src/opensymbolicai/checkpoint.py
all_llm_interactions
property
Get all LLM interactions from all attempts.
attempt_count
property
Number of plan generation attempts.
had_retries
property
Whether the plan required retries.
PlanExecute
Bases: Planner
Agent that generates and executes Python plans using LLMs.
PlanExecute orchestrators use an LLM to generate Python code that calls primitive methods, then execute that code step-by-step with full tracing.
Subclasses should: 1. Define primitive methods using the @primitive decorator 2. Optionally define decomposition examples using @decomposition
Example
class Calculator(PlanExecute): @primitive(read_only=True) def add(self, a: float, b: float) -> float: return a + b
@decomposition(intent="What is 2 + 3?")
def _example_add(self) -> float:
result = self.add(2, 3)
return result
Source code in src/opensymbolicai/blueprints/plan_execute.py
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 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 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 | |
blueprint_type
property
The blueprint type: 'PlanExecute', 'DesignExecute', or 'GoalSeeking'.
history
property
Get the conversation history (multi-turn mode only).
persisted_variables
property
Get the persisted variables from previous turns (multi-turn mode only).
__init__(llm, name='', description='', config=None)
Initialize the PlanExecute agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm
|
LLM | LLMConfig
|
LLM instance or config for plan generation. |
required |
name
|
str
|
Agent name for prompts. |
''
|
description
|
str
|
Agent description for prompts. |
''
|
config
|
PlanExecuteConfig | None
|
Extended configuration options. |
None
|
Source code in src/opensymbolicai/blueprints/plan_execute.py
analyze_plan(plan)
Analyze a plan to extract primitive calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plan
|
str
|
The Python statements to analyze. |
required |
Returns:
| Type | Description |
|---|---|
PlanAnalysis
|
PlanAnalysis containing all primitive calls found. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the plan has invalid syntax. |
Source code in src/opensymbolicai/blueprints/plan_execute.py
build_plan_prompt(task, feedback=None)
Build the prompt for the LLM to generate a plan.
Override this method in subclasses to customize the prompt sent to the LLM.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
str
|
The task description to plan for. |
required |
feedback
|
str | None
|
Optional error feedback from a previous failed plan attempt. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The complete prompt string to send to the LLM. |
Source code in src/opensymbolicai/blueprints/plan_execute.py
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 | |
compute_signature_hash()
Compute a hash of all primitive signatures and decomposition examples.
A changed hash means the agent's interface has changed and any downstream artifacts (e.g. fine-tuned adapters) need regeneration.
Returns:
| Type | Description |
|---|---|
str
|
A 16-character hex digest. |
Source code in src/opensymbolicai/blueprints/plan_execute.py
execute(plan)
Execute a plan step-by-step with full tracing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plan
|
str
|
The Python statements to execute. |
required |
Returns:
| Type | Description |
|---|---|
ExecutionResult
|
ExecutionResult containing the final value and execution trace. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the plan contains disallowed operations. |
Source code in src/opensymbolicai/blueprints/plan_execute.py
1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 | |
execute_stepwise(task, plan_context=None, serializer=None, checkpoint_id=None)
Execute a plan step-by-step, yielding checkpoints for persistence.
This method enables distributed execution by yielding a checkpoint after each step. The checkpoint can be persisted to a database and resumed on any worker.
When require_mutation_approval is True (default), execution pauses
before mutations and yields a checkpoint with status awaiting_approval.
Call resume_from_checkpoint() with approve_mutation=True to continue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
str
|
The task description to accomplish. |
required |
plan_context
|
PlanContext | None
|
Optional pre-computed plan context (from a previous planning phase). If None, will generate a new plan. |
None
|
serializer
|
SerializerRegistry | None
|
Custom serializer registry. Defaults to the global registry. |
None
|
checkpoint_id
|
str | None
|
Optional ID for the checkpoint. Auto-generated if None. |
None
|
Yields:
| Type | Description |
|---|---|
ExecutionCheckpoint
|
ExecutionCheckpoint after each step, allowing for persistence and |
ExecutionCheckpoint
|
distributed resume. |
Example
Simple usage - collect all checkpoints
for checkpoint in agent.execute_stepwise("do something"): store.save(checkpoint) if checkpoint.status == CheckpointStatus.AWAITING_APPROVAL: # Handle approval externally break
Resume after approval
checkpoint = store.load(checkpoint_id) for checkpoint in agent.resume_from_checkpoint(checkpoint, approve_mutation=True): store.save(checkpoint)
Source code in src/opensymbolicai/blueprints/plan_execute.py
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 | |
on_code_extracted(raw_response, extracted_code)
Hook called after code is extracted from the LLM response.
Override this method in subclasses to observe and/or modify the extracted code before it is used for planning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_response
|
str
|
The original raw text response from the LLM. |
required |
extracted_code
|
str
|
The code extracted by _extract_code_block. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The final code to use (can be modified from extracted_code). |
Source code in src/opensymbolicai/blueprints/plan_execute.py
plan(task, feedback=None)
Generate a plan (Python statements) for a task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
str
|
The task description to plan for. |
required |
feedback
|
str | None
|
Optional error feedback from a previous failed plan attempt. |
None
|
Returns:
| Type | Description |
|---|---|
PlanResult
|
PlanResult containing the generated plan and metrics. |
Source code in src/opensymbolicai/blueprints/plan_execute.py
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 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 | |
resume_from_checkpoint(checkpoint, approve_mutation=False, serializer=None)
Resume execution from a persisted checkpoint.
This method reconstructs execution state from a checkpoint and continues execution from where it left off.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint
|
ExecutionCheckpoint
|
The checkpoint to resume from. |
required |
approve_mutation
|
bool
|
If True and checkpoint is awaiting approval, execute the pending mutation and continue. |
False
|
serializer
|
SerializerRegistry | None
|
Custom serializer registry. Must match the one used when creating the checkpoint. |
None
|
Yields:
| Type | Description |
|---|---|
ExecutionCheckpoint
|
ExecutionCheckpoint after each step. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If checkpoint is in a terminal state or approval is required but not provided. |
Example
Load and resume
checkpoint = store.load(checkpoint_id) if checkpoint.status == CheckpointStatus.AWAITING_APPROVAL: # Get user approval somehow if user_approved: for cp in agent.resume_from_checkpoint(checkpoint, approve_mutation=True): store.save(cp)
Source code in src/opensymbolicai/blueprints/plan_execute.py
1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 | |
run(task)
Run the complete plan-and-execute cycle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
str
|
The task description to accomplish. |
required |
Returns:
| Type | Description |
|---|---|
OrchestrationResult
|
OrchestrationResult containing the outcome and metrics. |
Source code in src/opensymbolicai/blueprints/plan_execute.py
run_with_checkpoints(task, store, serializer=None, auto_approve=False)
Run execution with automatic checkpoint persistence.
Convenience method that handles checkpoint saving automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
str
|
The task to execute. |
required |
store
|
CheckpointStore
|
Checkpoint store for persistence. |
required |
serializer
|
SerializerRegistry | None
|
Custom serializer registry. |
None
|
auto_approve
|
bool
|
If True, automatically approve all mutations. |
False
|
Returns:
| Type | Description |
|---|---|
ExecutionCheckpoint
|
The final checkpoint (completed or failed). |
Source code in src/opensymbolicai/blueprints/plan_execute.py
validate_plan(plan)
Validate that a plan only uses allowed operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plan
|
str
|
The Python statements to validate. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the plan contains disallowed operations. |
Source code in src/opensymbolicai/blueprints/plan_execute.py
PlanExecuteConfig
Bases: BaseModel
Extended configuration for PlanExecute agents.
Source code in src/opensymbolicai/models.py
PlanResult
Bases: BaseModel
Result from the planning phase.
Source code in src/opensymbolicai/models.py
Planner
Bases: ABC
Abstract base class for agents that plan and execute tasks.
The Planner defines the interface for agents that: 1. Generate plans from natural language tasks 2. Execute those plans step-by-step 3. Return structured results with execution traces
Subclasses must implement: - plan(): Generate a plan for a given task - execute(): Execute a plan and return results - run(): Complete plan-and-execute cycle
Source code in src/opensymbolicai/blueprints/planner.py
execute(plan)
abstractmethod
Execute a plan step-by-step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plan
|
str
|
The Python statements to execute. |
required |
Returns:
| Type | Description |
|---|---|
ExecutionResult
|
ExecutionResult containing the final value and execution trace. |
Source code in src/opensymbolicai/blueprints/planner.py
plan(task)
abstractmethod
Generate a plan (Python statements) for a task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
str
|
The task description to plan for. |
required |
Returns:
| Type | Description |
|---|---|
PlanResult
|
PlanResult containing the generated plan and metrics. |
Source code in src/opensymbolicai/blueprints/planner.py
run(task)
abstractmethod
Run the complete plan-and-execute cycle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
str
|
The task description to accomplish. |
required |
Returns:
| Type | Description |
|---|---|
OrchestrationResult
|
OrchestrationResult containing the outcome and metrics. |
Source code in src/opensymbolicai/blueprints/planner.py
PreconditionError
Bases: ExecutionError
Exception raised when a precondition for an operation is not met.
Use this when the operation cannot proceed due to missing prerequisites or invalid state (e.g., division by zero, empty collection).
Example
if divisor == 0: raise PreconditionError( "Cannot divide by zero", code="DIVISION_BY_ZERO", details={"dividend": dividend, "divisor": divisor} )
Source code in src/opensymbolicai/exceptions.py
__init__(message, *, code='PRECONDITION_FAILED', details=None)
Initialize precondition error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error message. |
required |
code
|
str | None
|
Error code, defaults to "PRECONDITION_FAILED". |
'PRECONDITION_FAILED'
|
details
|
dict[str, Any] | None
|
Additional context about the error. |
None
|
Source code in src/opensymbolicai/exceptions.py
PrimitiveCall
Bases: BaseModel
Information about a primitive method call in a plan.
Source code in src/opensymbolicai/models.py
PrimitiveInfo
Bases: BaseModel
Metadata describing a primitive method, passed to PromptProvider selectors.
Source code in src/opensymbolicai/models.py
PromptProvider
Bases: BaseModel
Controls which primitives and decompositions are included in the prompt.
Subclass and override :meth:select_primitives and/or
:meth:select_decompositions to filter what the LLM sees. The
inheriting class only needs to choose method names — prompt
construction is handled by the framework.
Each selector receives rich metadata so you can filter by any attribute (name, docstring, read_only, parameter types, etc.).
Example::
class ReadOnlyOnly(PromptProvider):
def select_primitives(self, available: list[PrimitiveInfo]) -> list[str]:
return [p.name for p in available if p.read_only]
Source code in src/opensymbolicai/models.py
select_decompositions(available)
Return the decomposition names to include in the prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
available
|
list[DecompositionInfo]
|
Metadata for all decomposition methods on the agent. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The subset of names to expose to the LLM. Default: all. |
Source code in src/opensymbolicai/models.py
select_primitives(available)
Return the primitive names to include in the prompt.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
available
|
list[PrimitiveInfo]
|
Metadata for all primitive methods on the agent. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The subset of names to expose to the LLM. Default: all. |
Source code in src/opensymbolicai/models.py
PromptSections
Bases: BaseModel
The three demarcated sections of an OpenSymbolicAI prompt.
Source code in src/opensymbolicai/prompt_utils.py
context
instance-attribute
Dynamic per-call content: task, history, feedback.
definitions
instance-attribute
Static per-agent content: primitive signatures, type defs, examples.
instructions
instance-attribute
Static per-blueprint content: rules and output format.
preamble
instance-attribute
Text before the DEFINITIONS marker (agent identity/description).
ResourceError
Bases: ExecutionError
Exception raised when a required resource is unavailable.
Use this for missing files, network failures, or unavailable external services.
Example
raise ResourceError( "Database connection failed", code="DB_UNAVAILABLE", details={"host": "localhost", "port": 5432} )
Source code in src/opensymbolicai/exceptions.py
__init__(message, *, code='RESOURCE_ERROR', details=None, resource=None)
Initialize resource error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error message. |
required |
code
|
str | None
|
Error code, defaults to "RESOURCE_ERROR". |
'RESOURCE_ERROR'
|
details
|
dict[str, Any] | None
|
Additional context about the error. |
None
|
resource
|
str | None
|
Optional identifier for the unavailable resource. |
None
|
Source code in src/opensymbolicai/exceptions.py
RetryableError
Bases: ExecutionError
Exception raised for errors that may succeed on retry.
Use this for transient failures like network timeouts or rate limits. By default, this does NOT halt execution to allow potential recovery.
Example
raise RetryableError( "API rate limit exceeded", code="RATE_LIMIT", details={"retry_after_seconds": 60} )
Source code in src/opensymbolicai/exceptions.py
__init__(message, *, code='RETRYABLE_ERROR', details=None, retry_after=None)
Initialize retryable error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error message. |
required |
code
|
str | None
|
Error code, defaults to "RETRYABLE_ERROR". |
'RETRYABLE_ERROR'
|
details
|
dict[str, Any] | None
|
Additional context about the error. |
None
|
retry_after
|
float | None
|
Optional seconds to wait before retrying. |
None
|
Source code in src/opensymbolicai/exceptions.py
SerializedValue
Bases: BaseModel
A serialized value with type information for deserialization.
Source code in src/opensymbolicai/checkpoint.py
SerializerRegistry
Registry for custom type serializers.
Allows registering serializers/deserializers for types that aren't natively JSON-serializable.
Example
registry = SerializerRegistry()
Register a custom class
registry.register( MyClass, serializer=lambda obj: {"field": obj.field}, deserializer=lambda data: MyClass(field=data["field"]) )
Or use decorators
@registry.register_serializer(MyClass) def serialize_myclass(obj: MyClass) -> dict: return {"field": obj.field}
@registry.register_deserializer("mymodule.MyClass") def deserialize_myclass(data: dict) -> MyClass: return MyClass(field=data["field"])
Source code in src/opensymbolicai/checkpoint.py
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 | |
can_deserialize(type_name)
Check if a type can be deserialized.
Source code in src/opensymbolicai/checkpoint.py
deserialize(serialized)
Deserialize a SerializedValue back to its original value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
serialized
|
SerializedValue
|
The SerializedValue to deserialize. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The deserialized value. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no deserializer is registered for the type. |
Source code in src/opensymbolicai/checkpoint.py
deserialize_namespace(serialized)
Deserialize a namespace back to regular values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
serialized
|
dict[str, SerializedValue]
|
Dict of serialized values. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict mapping variable names to deserialized values. |
Source code in src/opensymbolicai/checkpoint.py
register(type_, serializer, deserializer)
Register a serializer/deserializer pair for a type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_
|
type
|
The Python type to register. |
required |
serializer
|
Serializer
|
Function that converts instance to JSON-compatible data. |
required |
deserializer
|
Deserializer
|
Function that converts JSON data back to instance. |
required |
Source code in src/opensymbolicai/checkpoint.py
register_deserializer(type_name)
Decorator to register a deserializer for a type name.
Example
@registry.register_deserializer("mymodule.MyClass") def deserialize(data: dict) -> MyClass: return MyClass(field=data["field"])
Source code in src/opensymbolicai/checkpoint.py
register_serializer(type_)
Decorator to register a serializer for a type.
Example
@registry.register_serializer(MyClass) def serialize(obj: MyClass) -> dict: return {"field": obj.field}
Source code in src/opensymbolicai/checkpoint.py
serialize(value)
Serialize a value to a SerializedValue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
The value to serialize. |
required |
Returns:
| Type | Description |
|---|---|
SerializedValue
|
SerializedValue with type info and serialized data. |
Source code in src/opensymbolicai/checkpoint.py
serialize_namespace(namespace, exclude=None)
Serialize an entire namespace dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
namespace
|
dict[str, Any]
|
The namespace to serialize. |
required |
exclude
|
set[str] | None
|
Keys to exclude from serialization. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, SerializedValue]
|
Dict mapping variable names to SerializedValues. |
Source code in src/opensymbolicai/checkpoint.py
TokenUsage
Bases: BaseModel
Token usage statistics from LLM generation.
Source code in src/opensymbolicai/models.py
total_tokens
property
Total tokens used.
TraceEvent
Bases: BaseModel
A single trace event emitted during agent execution.
Events are grouped by trace_id (one per run/seek call) and form a tree via span_id / parent_span_id.
Source code in src/opensymbolicai/observability/events.py
TraceTransport
Bases: Protocol
Protocol for sending trace events to a backend.
Implementations must provide send() and close().
Source code in src/opensymbolicai/observability/transports/protocol.py
close()
send(events)
Send a batch of trace events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
events
|
list[TraceEvent]
|
List of events to send. |
required |
ValidationError
Bases: ExecutionError
Exception raised when input validation fails.
Use this for invalid arguments, out-of-range values, or constraint violations in primitive inputs.
Example
if number <= 0: raise ValidationError( "Logarithm requires positive input", code="INVALID_INPUT", details={"received": number, "expected": "positive number"} )
Source code in src/opensymbolicai/exceptions.py
__init__(message, *, code='VALIDATION_ERROR', details=None, field=None)
Initialize validation error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Human-readable error message. |
required |
code
|
str | None
|
Error code, defaults to "VALIDATION_ERROR". |
'VALIDATION_ERROR'
|
details
|
dict[str, Any] | None
|
Additional context about the error. |
None
|
field
|
str | None
|
Optional name of the field that failed validation. |
None
|
Source code in src/opensymbolicai/exceptions.py
decomposition(intent, expanded_intent='')
Mark a method as a decomposition example.
Decompositions demonstrate how to break down high-level intents into sequences of primitive operations. They serve as examples for the LLM to learn the patterns of composition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intent
|
str
|
A high-level description of what this decomposition achieves. This is the natural language query that this example answers. |
required |
expanded_intent
|
str
|
An optional step-by-step breakdown of the approach. Provides additional context about the reasoning or methodology. |
''
|
Returns:
| Type | Description |
|---|---|
Callable[[F], F]
|
A decorator that marks the function as a decomposition example. |
Example
@decomposition( intent="What is sine of 90 degrees?", expanded_intent="First convert 90 degrees to radians, then calculate sine", ) def _example_sine_90(self) -> float: angle_rad: float = self.convert_degrees_to_radians(angle_in_degrees=90) sin_90: float = self.sine(angle_in_radians=angle_rad) return sin_90
Source code in src/opensymbolicai/core.py
evaluator(func)
Mark a method as the goal evaluator.
The evaluator determines whether the goal has been achieved after each iteration in a GoalSeeking agent. Exactly one method per agent should be decorated with @evaluator.
The decorated method receives (goal, context) and must return a GoalEvaluation. The evaluator checks structured insights on the context — never raw ExecutionResult. By the time the evaluator runs, update_context() has already introspected the raw result into context fields.
Returns:
| Type | Description |
|---|---|
F
|
The decorated function marked as an evaluator. |
Example
@evaluator def check_goal(self, goal: str, context: GoalContext) -> GoalEvaluation: has_enough = len(context.findings) >= 5 return GoalEvaluation(goal_achieved=has_enough)
Source code in src/opensymbolicai/core.py
extract_context(full_prompt)
Extract only the CONTEXT section from a full prompt.
This is the dynamic per-call content, independent of the static DEFINITIONS and INSTRUCTIONS sections.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
full_prompt
|
str
|
A prompt containing CONTEXT markers. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The text between |
str
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the prompt is missing CONTEXT markers. |
Source code in src/opensymbolicai/prompt_utils.py
primitive(read_only=False, deterministic=True)
Mark a method as a primitive operation.
Primitives are atomic operations that the agent can directly execute. They serve as the building blocks for more complex behaviors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
read_only
|
bool
|
If True, indicates this primitive does not modify state. |
False
|
deterministic
|
bool
|
If True (default), the primitive always returns the same output for the same inputs (pure function). Set to False for primitives that call LLMs, external APIs, or have side effects. Used by downstream tooling to decide whether to call the real implementation or mock-replay from captured traces during semantic validation. |
True
|
Returns:
| Type | Description |
|---|---|
Callable[[F], F]
|
A decorator that marks the function as a primitive. |
Example
@primitive(read_only=True) def add_numbers(self, a: float, b: float) -> float: return a + b
@primitive(deterministic=False) def resolve_name(self, name: str) -> str: return self._llm.generate(f"Resolve: {name}").text
Source code in src/opensymbolicai/core.py
split_prompt(full_prompt)
Split a full 3-section prompt into its component parts.
Sections with missing markers return empty strings. If no markers are present at all, the entire prompt is returned as the preamble.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
full_prompt
|
str
|
A prompt, optionally containing DEFINITIONS, CONTEXT,
and INSTRUCTIONS sections delimited by
|
required |
Returns:
| Type | Description |
|---|---|
PromptSections
|
A PromptSections instance with the four extracted parts. |