API Reference¶
IntentKit - A Python library for building hierarchical intent classification and execution systems.
This library provides: - Tree-based intent architecture with classifier and intent nodes - IntentGraph for multi-intent routing and splitting - Context-aware execution with dependency tracking - Multiple AI service backends (OpenAI, Anthropic, Google AI, Ollama) - Interactive visualization of execution paths
ClassifierNode
¶
Bases: TreeNode
Intermediate node that uses a classifier to select child nodes.
Source code in intent_kit/classifiers/node.py
12 13 14 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 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 |
|
node_type
property
¶
Get the type of this node.
HandlerNode
¶
Bases: TreeNode
Leaf node representing an executable handler with argument extraction and validation.
Source code in intent_kit/handlers/node.py
13 14 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 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 |
|
node_type
property
¶
Get the type of this node.
IntentContext
¶
Thread-safe context object for sharing state between workflow steps.
Features: - Field-level locking for concurrent access - Complete audit trail of all operations - Error tracking with detailed information - Session-based isolation - Type-safe field access
Source code in intent_kit/context/__init__.py
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 |
|
__init__(session_id=None, debug=False)
¶
Initialize a new IntentContext.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session_id
|
Optional[str]
|
Unique identifier for this context session |
None
|
debug
|
bool
|
Enable debug logging |
False
|
Source code in intent_kit/context/__init__.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
__repr__()
¶
Detailed string representation of the context.
Source code in intent_kit/context/__init__.py
352 353 354 |
|
__str__()
¶
String representation of the context.
Source code in intent_kit/context/__init__.py
343 344 345 346 347 348 349 350 |
|
add_error(node_name, user_input, error_message, error_type, params=None)
¶
Add an error to the context error log.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_name
|
str
|
Name of the node where the error occurred |
required |
user_input
|
str
|
The user input that caused the error |
required |
error_message
|
str
|
The error message |
required |
error_type
|
str
|
The type of error |
required |
params
|
Optional[Dict[str, Any]]
|
Optional parameters that were being processed |
None
|
Source code in intent_kit/context/__init__.py
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 |
|
clear(modified_by=None)
¶
Clear all fields from context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
modified_by
|
Optional[str]
|
Identifier for who/what cleared the context |
None
|
Source code in intent_kit/context/__init__.py
240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
clear_errors()
¶
Clear all errors from the context.
Source code in intent_kit/context/__init__.py
330 331 332 333 334 335 336 |
|
delete(key, modified_by=None)
¶
Delete a field from context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The field key to delete |
required |
modified_by
|
Optional[str]
|
Identifier for who/what deleted this field |
None
|
Returns:
Type | Description |
---|---|
bool
|
True if field was deleted, False if it didn't exist |
Source code in intent_kit/context/__init__.py
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
|
error_count()
¶
Get the total number of errors in the context.
Source code in intent_kit/context/__init__.py
338 339 340 341 |
|
get(key, default=None)
¶
Get a value from context with field-level locking.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The field key to retrieve |
required |
default
|
Any
|
Default value if key doesn't exist |
None
|
Returns:
Type | Description |
---|---|
Any
|
The field value or default |
Source code in intent_kit/context/__init__.py
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 |
|
get_errors(node_name=None, limit=None)
¶
Get errors from the context error log.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_name
|
Optional[str]
|
Filter errors by node name (optional) |
None
|
limit
|
Optional[int]
|
Maximum number of errors to return (optional) |
None
|
Returns:
Type | Description |
---|---|
List[ContextErrorEntry]
|
List of error entries |
Source code in intent_kit/context/__init__.py
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 |
|
get_field_metadata(key)
¶
Get metadata for a specific field.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The field key |
required |
Returns:
Type | Description |
---|---|
Optional[Dict[str, Any]]
|
Dictionary with field metadata or None if field doesn't exist |
Source code in intent_kit/context/__init__.py
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
|
get_history(key=None, limit=None)
¶
Get the history of context operations.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
Optional[str]
|
Filter history to specific key (optional) |
None
|
limit
|
Optional[int]
|
Maximum number of entries to return (optional) |
None
|
Returns:
Type | Description |
---|---|
List[ContextHistoryEntry]
|
List of history entries |
Source code in intent_kit/context/__init__.py
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 |
|
has(key)
¶
Check if a field exists in context.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The field key to check |
required |
Returns:
Type | Description |
---|---|
bool
|
True if field exists, False otherwise |
Source code in intent_kit/context/__init__.py
169 170 171 172 173 174 175 176 177 178 179 180 |
|
keys()
¶
Get all field keys in the context.
Returns:
Type | Description |
---|---|
Set[str]
|
Set of all field keys |
Source code in intent_kit/context/__init__.py
182 183 184 185 186 187 188 189 190 |
|
set(key, value, modified_by=None)
¶
Set a value in context with field-level locking and history tracking.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key
|
str
|
The field key to set |
required |
value
|
Any
|
The value to store |
required |
modified_by
|
Optional[str]
|
Identifier for who/what modified this field |
None
|
Source code in intent_kit/context/__init__.py
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 |
|
IntentGraph
¶
The root-level dispatcher for user input.
The graph contains root nodes that can handle different types of intents. Input splitting happens in isolation and routes to appropriate root nodes. Trees emerge naturally from the parent-child relationships between nodes.
Source code in intent_kit/graph/intent_graph.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 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 |
|
__init__(root_nodes=None, splitter=None, visualize=False, llm_config=None, debug_context=False, context_trace=False)
¶
Initialize the IntentGraph with root nodes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root_nodes
|
Optional[List[TreeNode]]
|
List of root nodes that can handle intents |
None
|
splitter
|
Optional[SplitterFunction]
|
Function to use for splitting intents (default: pass-through splitter) |
None
|
visualize
|
bool
|
If True, render the final output to an interactive graph HTML file |
False
|
llm_config
|
Optional[dict]
|
LLM configuration for chunk classification (optional) |
None
|
debug_context
|
bool
|
If True, enable context debugging and state tracking |
False
|
context_trace
|
bool
|
If True, enable detailed context tracing with timestamps |
False
|
Source code in intent_kit/graph/intent_graph.py
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 |
|
add_root_node(root_node, validate=True)
¶
Add a root node to the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root_node
|
TreeNode
|
The root node to add |
required |
validate
|
bool
|
Whether to validate the graph after adding the node |
True
|
Source code in intent_kit/graph/intent_graph.py
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 |
|
list_root_nodes()
¶
List all root node names.
Returns:
Type | Description |
---|---|
List[str]
|
List of root node names |
Source code in intent_kit/graph/intent_graph.py
131 132 133 134 135 136 137 138 |
|
remove_root_node(root_node)
¶
Remove a root node from the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root_node
|
TreeNode
|
The root node to remove |
required |
Source code in intent_kit/graph/intent_graph.py
118 119 120 121 122 123 124 125 126 127 128 129 |
|
route(user_input, context=None, debug=False, debug_context=None, context_trace=None, **splitter_kwargs)
¶
Route user input through the graph with optional context support.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_input
|
str
|
The input string to process |
required |
context
|
Optional[IntentContext]
|
Optional context object for state sharing |
None
|
debug
|
bool
|
Whether to print debug information |
False
|
debug_context
|
Optional[bool]
|
Override graph-level debug_context setting |
None
|
context_trace
|
Optional[bool]
|
Override graph-level context_trace setting |
None
|
**splitter_kwargs
|
Additional arguments to pass to the splitter |
{}
|
Returns:
Type | Description |
---|---|
ExecutionResult
|
ExecutionResult containing aggregated results and errors from all matched taxonomies |
Source code in intent_kit/graph/intent_graph.py
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 |
|
validate_graph(validate_routing=True, validate_types=True)
¶
Validate the graph structure and routing constraints.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
validate_routing
|
bool
|
Whether to validate splitter-to-classifier routing |
True
|
validate_types
|
bool
|
Whether to validate node types |
True
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dictionary containing validation results and statistics |
Raises:
Type | Description |
---|---|
GraphValidationError
|
If validation fails |
Source code in intent_kit/graph/intent_graph.py
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 |
|
validate_splitter_routing()
¶
Validate that all splitter nodes only route to classifier nodes.
Raises:
Type | Description |
---|---|
GraphValidationError
|
If any splitter node routes to a non-classifier node |
Source code in intent_kit/graph/intent_graph.py
177 178 179 180 181 182 183 184 185 186 187 188 |
|
IntentGraphBuilder
¶
Builder class for creating IntentGraph instances with a fluent interface.
Source code in intent_kit/builder.py
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 |
|
build()
¶
Build and return the IntentGraph instance.
Returns:
Type | Description |
---|---|
IntentGraph
|
Configured IntentGraph instance |
Raises:
Type | Description |
---|---|
ValueError
|
If no root node has been set |
Source code in intent_kit/builder.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
context_trace(enabled=True)
¶
Enable detailed context tracing for the intent graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enabled
|
bool
|
Whether to enable context tracing |
True
|
Returns:
Type | Description |
---|---|
IntentGraphBuilder
|
Self for method chaining |
Source code in intent_kit/builder.py
94 95 96 97 98 99 100 101 102 103 104 |
|
debug_context(enabled=True)
¶
Enable context debugging for the intent graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enabled
|
bool
|
Whether to enable context debugging |
True
|
Returns:
Type | Description |
---|---|
IntentGraphBuilder
|
Self for method chaining |
Source code in intent_kit/builder.py
82 83 84 85 86 87 88 89 90 91 92 |
|
root(node)
¶
Set the root node for the intent graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node
|
TreeNode
|
The root TreeNode to use for the graph |
required |
Returns:
Type | Description |
---|---|
IntentGraphBuilder
|
Self for method chaining |
Source code in intent_kit/builder.py
33 34 35 36 37 38 39 40 41 42 43 |
|
splitter(splitter_func)
¶
Set a custom splitter function for the intent graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
splitter_func
|
Function to use for splitting intents |
required |
Returns:
Type | Description |
---|---|
IntentGraphBuilder
|
Self for method chaining |
Source code in intent_kit/builder.py
45 46 47 48 49 50 51 52 53 54 55 |
|
LLMFactory
¶
Factory for creating LLM clients.
Source code in intent_kit/services/llm_factory.py
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 |
|
create_client(llm_config)
staticmethod
¶
Create an LLM client based on the configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
llm_config
|
Dict[str, Any]
|
Dictionary with keys: - provider: "openai", "anthropic", "google", "openrouter", "ollama" - api_key: API key for the provider (not required for ollama) - model: Model name (optional, uses defaults) - max_tokens: Maximum tokens (optional) - temperature: Temperature (optional) - base_url: Base URL for ollama (optional, defaults to localhost:11434) |
required |
Returns:
Type | Description |
---|---|
LLM client instance |
Raises:
Type | Description |
---|---|
ValueError
|
If provider is not supported or config is invalid |
Source code in intent_kit/services/llm_factory.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
generate_with_config(llm_config, prompt)
staticmethod
¶
Generate text using the specified LLM configuration.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
llm_config
|
Dict[str, Any]
|
LLM configuration dictionary |
required |
prompt
|
str
|
Text prompt to send to the LLM |
required |
Returns:
Type | Description |
---|---|
str
|
Generated text response |
Source code in intent_kit/services/llm_factory.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
NodeType
¶
Bases: Enum
Enumeration of valid node types in the intent tree.
Source code in intent_kit/node/enums.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
SplitterNode
¶
Bases: TreeNode
Node that splits user input into multiple intent chunks.
Source code in intent_kit/splitters/node.py
8 9 10 11 12 13 14 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 116 117 118 119 120 121 122 123 124 125 126 127 128 |
|
node_type
property
¶
Get the type of this node.
TreeNode
¶
Bases: Node
, ABC
Base class for all nodes in the intent tree.
Source code in intent_kit/node/base.py
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 |
|
node_type
property
¶
Get the type of this node. Override in subclasses.
execute(user_input, context=None)
abstractmethod
¶
Execute the node with the given user input and optional context.
Source code in intent_kit/node/base.py
68 69 70 71 72 73 |
|
create_intent_graph(root_node)
¶
Create an IntentGraph with the given root node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
root_node
|
TreeNode
|
The root TreeNode for the graph |
required |
Returns:
Type | Description |
---|---|
IntentGraph
|
Configured IntentGraph instance |
Source code in intent_kit/builder.py
374 375 376 377 378 379 380 381 382 383 |
|
create_llm_arg_extractor(llm_config, extraction_prompt, param_schema)
¶
Create an LLM-powered argument extractor function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
llm_config
|
Dict[str, Any]
|
LLM configuration dictionary |
required |
extraction_prompt
|
str
|
Prompt template for argument extraction |
required |
param_schema
|
Dict[str, Any]
|
Parameter schema defining expected parameters |
required |
Returns:
Type | Description |
---|---|
Callable[[str, Optional[Dict[str, Any]]], Dict[str, Any]]
|
Argument extractor function that can be used with HandlerNode |
Source code in intent_kit/classifiers/llm_classifier.py
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 |
|
create_llm_classifier(llm_config, classification_prompt, node_descriptions)
¶
Create an LLM-powered classifier function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
llm_config
|
Dict[str, Any]
|
LLM configuration dictionary |
required |
classification_prompt
|
str
|
Prompt template for classification |
required |
node_descriptions
|
List[str]
|
List of descriptions for each child node |
required |
Returns:
Type | Description |
---|---|
Callable[[str, List[TreeNode], Optional[Dict[str, Any]]], Optional[TreeNode]]
|
Classifier function that can be used with ClassifierNode |
Source code in intent_kit/classifiers/llm_classifier.py
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 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 |
|
get_context_dependencies(graph)
¶
Analyze the full dependency map for all nodes in a graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
Any
|
IntentGraph instance to analyze |
required |
Returns:
Type | Description |
---|---|
Dict[str, ContextDependencies]
|
Dictionary mapping node names to their context dependencies |
Source code in intent_kit/context/debug.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|
handler(*, name, description, handler_func, param_schema, llm_config=None, extraction_prompt=None, context_inputs=None, context_outputs=None, input_validator=None, output_validator=None, remediation_strategies=None)
¶
Create a handler node with automatic argument extraction.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the handler node |
required |
description
|
str
|
Description of what this handler does |
required |
handler_func
|
Callable[..., Any]
|
Function to execute when this handler is triggered |
required |
param_schema
|
Dict[str, Type]
|
Dictionary mapping parameter names to their types |
required |
llm_config
|
Optional[Dict[str, Any]]
|
Optional LLM configuration for LLM-based argument extraction. If not provided, uses a simple rule-based extractor. |
None
|
extraction_prompt
|
Optional[str]
|
Optional custom prompt for LLM argument extraction |
None
|
context_inputs
|
Optional[Set[str]]
|
Optional set of context keys this handler reads from |
None
|
context_outputs
|
Optional[Set[str]]
|
Optional set of context keys this handler writes to |
None
|
input_validator
|
Optional[Callable[[Dict[str, Any]], bool]]
|
Optional function to validate extracted parameters |
None
|
output_validator
|
Optional[Callable[[Any], bool]]
|
Optional function to validate handler output |
None
|
Returns:
Type | Description |
---|---|
TreeNode
|
Configured HandlerNode |
Example
greet_handler = handler( ... name="greet", ... description="Greet the user", ... handler_func=lambda name: f"Hello {name}!", ... param_schema={"name": str}, ... llm_config=LLM_CONFIG ... )
Source code in intent_kit/builder.py
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 |
|
keyword_classifier(user_input, children, context=None)
¶
A simple classifier that selects the first child whose name appears in the user input.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
user_input
|
str
|
The input string to process |
required |
children
|
list[TreeNode]
|
List of possible child nodes |
required |
context
|
Optional[Dict[str, Any]]
|
Optional context dictionary (unused in this classifier) |
None
|
Returns:
Type | Description |
---|---|
Optional[TreeNode]
|
The first matching child node, or None if no match is found |
Source code in intent_kit/classifiers/keyword.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
llm_classifier(*, name, children, llm_config, classification_prompt=None, description='', remediation_strategies=None)
¶
Create an LLM-powered classifier node with auto-wired children descriptions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the classifier node |
required |
children
|
List[TreeNode]
|
List of child nodes to classify between |
required |
llm_config
|
Dict[str, Any]
|
LLM configuration for classification |
required |
classification_prompt
|
Optional[str]
|
Optional custom classification prompt |
None
|
description
|
str
|
Optional description of the classifier |
''
|
Returns:
Type | Description |
---|---|
TreeNode
|
Configured ClassifierNode with auto-wired children descriptions |
Example
classifier = llm_classifier( ... name="root", ... children=[greet_handler, calc_handler, weather_handler], ... llm_config=LLM_CONFIG ... )
Source code in intent_kit/builder.py
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 |
|
llm_splitter_node(*, name, children, llm_config, description='')
¶
Create an LLM-powered splitter node for multi-intent handling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the splitter node |
required |
children
|
List[TreeNode]
|
List of child nodes to route to |
required |
llm_config
|
Dict[str, Any]
|
LLM configuration for splitting |
required |
description
|
str
|
Optional description of the splitter |
''
|
Returns:
Type | Description |
---|---|
TreeNode
|
Configured SplitterNode with LLM-powered splitting |
Example
splitter = llm_splitter_node( ... name="multi_intent_splitter", ... children=[classifier_node], ... llm_config=LLM_CONFIG ... )
Source code in intent_kit/builder.py
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 |
|
rule_splitter_node(*, name, children, description='')
¶
Create a rule-based splitter node for multi-intent handling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the splitter node |
required |
children
|
List[TreeNode]
|
List of child nodes to route to |
required |
description
|
str
|
Optional description of the splitter |
''
|
Returns:
Type | Description |
---|---|
TreeNode
|
Configured SplitterNode with rule-based splitting |
Example
splitter = rule_splitter_node( ... name="rule_based_splitter", ... children=[classifier_node], ... )
Source code in intent_kit/builder.py
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 |
|
trace_context_execution(graph, user_input, context, output_format='console')
¶
Generate a detailed execution trace with context state changes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
graph
|
Any
|
IntentGraph instance |
required |
user_input
|
str
|
The user input that was processed |
required |
context
|
IntentContext
|
Context object with execution history |
required |
output_format
|
str
|
Output format ("console", "json") |
'console'
|
Returns:
Type | Description |
---|---|
str
|
Formatted execution trace |
Source code in intent_kit/context/debug.py
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 |
|
validate_context_flow(graph, context)
¶
Validate the context flow for a graph and context.
Source code in intent_kit/context/debug.py
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 |
|