util
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
|
Union[ToolRegistry, Iterable[Union[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
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 |
|
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
5 6 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 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 |
|