util
Checkpointer
Source code in src/ursa/util/__init__.py
7 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 | |
from_path(db_path, db_name='checkpointer.db')
classmethod
Make checkpointer sqlite db.
Args
- db_path: The path to the SQLite database file (e.g. ./checkpoint.db) to be created.
Source code in src/ursa/util/__init__.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 | |
diff_renderer
DiffRenderer
Renderable diff—console.print(DiffRenderer(...))
Source code in src/ursa/util/diff_renderer.py
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 | |
helperFunctions
run_tool_calls(ai_msg, tools)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ai_msg
|
AIMessage
|
The LLM's AIMessage containing tool calls. |
required |
tools
|
ToolRegistry | Iterable[Runnable | Callable[..., Any]]
|
Either a dict {name: tool} or an iterable of tools (must have |
required |
Returns:
| Name | Type | Description |
|---|---|---|
out |
list[BaseMessage]
|
list[BaseMessage] to feed back to the model |
Source code in src/ursa/util/helperFunctions.py
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 | |
logo_generator
generate_logo_sync(*, problem_text, workspace, out_dir, filename=None, model=DEFAULT_IMAGE_MODEL, size=None, background='opaque', quality='high', n=1, overwrite=False, style='sticker', allow_text=False, palette=None, mode='logo', aspect='square', style_intensity='overt', aperture=DEFAULT_APERTURE, console=None, image_model_provider='openai', image_provider_kwargs=None)
Generate images.
Key change (diversity): - We no longer rely on a single prompt with n>1 siblings for scenes. - If mode='scene' and style='random' and n>1, we pick n distinct scene styles (horror/fantasy/etc) and generate 1 image per style/prompt.
Return value
- Returns the "main" path (first generated image). Additional variants are saved alongside it.
Source code in src/ursa/util/logo_generator.py
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 | |
mcp
memory_logger
AgentMemory
Simple wrapper around a persistent Chroma vector-store for agent-conversation memory.
Parameters
path : str | Path | None
Where to keep the on-disk Chroma DB. If None, a folder called
agent_memory_db is created in the package’s base directory.
collection_name : str
Name of the Chroma collection.
embedding_model :
Notes
- Requires
langchain-chroma, andchromadb.
Source code in src/ursa/util/memory_logger.py
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 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 | |
add_memories(new_chunks, metadatas=None)
Append new text chunks to the existing store (must call build_index
first if the DB is empty).
Raises
RuntimeError If the vector store is not yet initialised.
Source code in src/ursa/util/memory_logger.py
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 | |
build_index(chunks, metadatas=None)
Create a fresh vector store from chunks. Existing data (if any)
are overwritten.
Parameters
chunks : Sequence[str]
Text snippets (already chunked) to embed.
metadatas : Sequence[dict] | None
Optional metadata dict for each chunk, same length as chunks.
Source code in src/ursa/util/memory_logger.py
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 | |
retrieve(query, k=4, with_scores=False, **search_kwargs)
Return the k most similar chunks for query.
Parameters
query : str
Natural-language question or statement.
k : int
How many results to return.
with_scores : bool
If True, also return similarity scores.
**search_kwargs
Extra kwargs forwarded to Chroma’s similarity_search* helpers.
Returns
list[Document] | list[tuple[Document, float]]
Source code in src/ursa/util/memory_logger.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 | |
delete_database(path=None)
Simple wrapper around a persistent Chroma vector-store for agent-conversation memory.
Parameters
path : str | Path | None
Where the on-disk Chroma DB is for deleting. If None, a folder called
agent_memory_db is created in the package’s base directory.
Source code in src/ursa/util/memory_logger.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
parse
extract_json(text)
Extract a JSON object or array from text that might contain markdown or other content.
The function attempts three strategies
- Extract JSON from a markdown code block labeled as JSON.
- Extract JSON from any markdown code block.
- Use bracket matching to extract a JSON substring starting with '{' or '['.
Returns:
| Type | Description |
|---|---|
list[dict]
|
A Python object parsed from the JSON string (dict or list). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no valid JSON is found. |
Source code in src/ursa/util/parse.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 | |
extract_main_text_only(html, *, max_chars=250000)
Returns plain text with navigation/ads/scripts removed. Prefers trafilatura -> jusText -> BS4 paragraphs.
Source code in src/ursa/util/parse.py
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 | |
read_text_file(path)
Reads in a file at a given path into a string
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
string filename, with path, to read in |
required |
Source code in src/ursa/util/parse.py
619 620 621 622 623 624 625 626 627 628 | |
resolve_pdf_from_osti_record(rec, *, headers=None, unpaywall_email=None, timeout=25)
Returns (pdf_url, landing_used, note) - pdf_url: direct downloadable PDF URL if found (or a strong candidate) - landing_used: landing page URL we parsed (if any) - note: brief trace of how we found it
Source code in src/ursa/util/parse.py
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 | |
plan_renderer
render_plan_steps_rich(plan_steps, highlight_index=None)
Pretty table for a list of plan steps (strings or dicts), with an optional highlighted row.
Source code in src/ursa/util/plan_renderer.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 | |
types
AsciiStr = Annotated[str, StringConstraints(strip_whitespace=True, strict=True, pattern='^[\\x20-\\x7E\\t\\n\\r\\f\\v]+$')]
module-attribute
Limit strings to "text" ASCII characters (letters, digits, symbols, whitespace)