ursa-ai 0.0.3__py3-none-any.whl → 0.2.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ursa-ai might be problematic. Click here for more details.

ursa/util/parse.py ADDED
@@ -0,0 +1,89 @@
1
+ import json
2
+ import re
3
+
4
+
5
+ def extract_json(text: str):
6
+ """
7
+ Extract a JSON object or array from text that might contain markdown or other content.
8
+
9
+ The function attempts three strategies:
10
+ 1. Extract JSON from a markdown code block labeled as JSON.
11
+ 2. Extract JSON from any markdown code block.
12
+ 3. Use bracket matching to extract a JSON substring starting with '{' or '['.
13
+
14
+ Returns:
15
+ A Python object parsed from the JSON string (dict or list).
16
+
17
+ Raises:
18
+ ValueError: If no valid JSON is found.
19
+ """
20
+ # Approach 1: Look for a markdown code block specifically labeled as JSON.
21
+ labeled_block = re.search(
22
+ r"```json\s*([\[{].*?[\]}])\s*```", text, re.DOTALL
23
+ )
24
+ if labeled_block:
25
+ json_str = labeled_block.group(1).strip()
26
+ try:
27
+ return json.loads(json_str)
28
+ except json.JSONDecodeError:
29
+ # Fall back to the next approach if parsing fails.
30
+ pass
31
+
32
+ # Approach 2: Look for any code block delimited by triple backticks.
33
+ generic_block = re.search(r"```(.*?)```", text, re.DOTALL)
34
+ if generic_block:
35
+ json_str = generic_block.group(1).strip()
36
+ if json_str.startswith("{") or json_str.startswith("["):
37
+ try:
38
+ return json.loads(json_str)
39
+ except json.JSONDecodeError:
40
+ pass
41
+
42
+ # Approach 3: Attempt to extract JSON using bracket matching.
43
+ # Find the first occurrence of either '{' or '['.
44
+ first_obj = text.find("{")
45
+ first_arr = text.find("[")
46
+ if first_obj == -1 and first_arr == -1:
47
+ raise ValueError("No JSON object or array found in the text.")
48
+
49
+ # Determine which bracket comes first.
50
+ if first_obj == -1:
51
+ start = first_arr
52
+ open_bracket = "["
53
+ close_bracket = "]"
54
+ elif first_arr == -1:
55
+ start = first_obj
56
+ open_bracket = "{"
57
+ close_bracket = "}"
58
+ else:
59
+ if first_obj < first_arr:
60
+ start = first_obj
61
+ open_bracket = "{"
62
+ close_bracket = "}"
63
+ else:
64
+ start = first_arr
65
+ open_bracket = "["
66
+ close_bracket = "]"
67
+
68
+ # Bracket matching: find the matching closing bracket.
69
+ depth = 0
70
+ end = None
71
+ for i in range(start, len(text)):
72
+ if text[i] == open_bracket:
73
+ depth += 1
74
+ elif text[i] == close_bracket:
75
+ depth -= 1
76
+ if depth == 0:
77
+ end = i
78
+ break
79
+
80
+ if end is None:
81
+ raise ValueError(
82
+ "Could not find matching closing bracket for JSON content."
83
+ )
84
+
85
+ json_str = text[start : end + 1]
86
+ try:
87
+ return json.loads(json_str)
88
+ except json.JSONDecodeError as e:
89
+ raise ValueError("Extracted content is not valid JSON.") from e
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.4
2
+ Name: ursa-ai
3
+ Version: 0.2.2
4
+ Summary: Agents for science at LANL
5
+ Author-email: Mike Grosskopf <mikegros@lanl.gov>, Rahul Somasundaram <rsomasundaram@lanl.gov>, Arthur Lui <alui@lanl.gov>
6
+ Project-URL: Homepage, https://github.com/lanl/ursa
7
+ Project-URL: Documentation, https://github.com/lanl/ursa/tree/main/docs
8
+ Project-URL: Repository, https://github.com/lanl/ursa
9
+ Project-URL: Issues, https://github.com/lanl/ursa/issues
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: License :: OSI Approved :: BSD License
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: arxiv<3.0,>=2.2.0
21
+ Requires-Dist: beautifulsoup4<5.0,>=4.13.4
22
+ Requires-Dist: coolname<3.0,>=2.2.0
23
+ Requires-Dist: langchain<0.4,>=0.3.22
24
+ Requires-Dist: langchain-community<0.4,>=0.3.20
25
+ Requires-Dist: langchain-litellm>=0.2.2
26
+ Requires-Dist: langchain-openai<0.4,>=0.3.12
27
+ Requires-Dist: langgraph>=0.5
28
+ Requires-Dist: pandas<3.0,>=2.2.3
29
+ Requires-Dist: pillow>=11.2.1
30
+ Requires-Dist: pymupdf<2.0,>=1.26.0
31
+ Requires-Dist: pypdf<6.0,>=5.4.0
32
+ Requires-Dist: rich<14.0,>=13.7.0
33
+ Requires-Dist: langchain-chroma>=0.2.4
34
+ Requires-Dist: chromadb>=1.0.15
35
+ Requires-Dist: mp-api>=0.45.8
36
+ Requires-Dist: langchain-google-genai>=2.1.9
37
+ Requires-Dist: langchain-anthropic>=0.3.18
38
+ Requires-Dist: langgraph-checkpoint-sqlite>=2.0.10
39
+ Requires-Dist: duckduckgo-search>=8.1.1
40
+ Requires-Dist: langchain-ollama>=0.3.6
41
+ Dynamic: license-file
42
+
43
+ # URSA - The Universal Research and Scientific Agent
44
+
45
+ <img src="./logos/logo.png" alt="URSA Logo" width="200" height="200">
46
+
47
+ [![PyPI Version][pypi-version]](https://pypi.org/project/ursa-ai/)
48
+ [![PyPI Downloads][total-downloads]](https://pepy.tech/projects/ursa-ai)
49
+
50
+ The flexible agentic workflow for accelerating scientific tasks.
51
+ Composes information flow between agents for planning, code writing and execution, and online research to solve complex problems.
52
+
53
+ ## Installation
54
+ You can install `ursa` via `pip` or `uv`.
55
+
56
+ **pip**
57
+ ```bash
58
+ pip install ursa-ai
59
+ ```
60
+
61
+ **uv**
62
+ ```bash
63
+ uv add ursa-ai
64
+ ```
65
+
66
+ ## How to use this code
67
+ Better documentation will be incoming, but for now there are examples in the examples folder that should give
68
+ a decent idea for how to set up some basic problems. They also should give some idea of how to pass results from
69
+ one agent to another. I will look to add things with multi-agent graphs, etc. in the future.
70
+
71
+ Documentation for each URSA agent:
72
+ - [Planning Agent](docs/planning_agent.md)
73
+ - [Execution Agent](docs/execution_agent.md)
74
+ - [ArXiv Agent](docs/arxiv_agent.md)
75
+ - [Web Search Agent](docs/web_search_agent.md)
76
+ - [Hypothesizer Agent](docs/hypothesizer_agent.md)
77
+
78
+ Documentation for combining agents:
79
+ - [ArXiv -> Execution for Materials](docs/combining_arxiv_and_execution.md)
80
+ - [ArXiv -> Execution for Neutron Star Properties](docs/combining_arxiv_and_execution_neutronStar.md)
81
+
82
+ # Sandboxing
83
+ The Execution Agent is allowed to run system commands and write/run code. Being able to execute arbitrary system commands or write
84
+ and execute code has the potential to cause problems like:
85
+ - Damage code or data on the computer
86
+ - Damage the computer
87
+ - Transmit your local data
88
+
89
+ The Web Search Agent scrapes data from urls, so has the potential to attempt to pull information from questionable sources.
90
+
91
+ Some suggestions for sandboxing the agent:
92
+ - Creating a specific environment such that limits URSA's access to only what you want. Examples:
93
+ - Creating/using a virtual machine that is sandboxed from the rest of your machine
94
+ - Creating a new account on your machine specifically for URSA
95
+ - Creating a network blacklist/whitelist to ensure that network commands and webscraping are contained to safe sources
96
+
97
+ You have a duty for ensuring that you use URSA responsibly.
98
+
99
+ ## Development Dependencies
100
+
101
+ * [`uv`](https://docs.astral.sh/uv/)
102
+ * `uv` is an extremely fast python package and project manager, written in Rust.
103
+ Follow installation instructions
104
+ [here](https://docs.astral.sh/uv/getting-started/installation/)
105
+
106
+ * [`ruff`](https://docs.astral.sh/ruff/)
107
+ * An extremely fast Python linter and code formatter, written in Rust.
108
+ * After installing `uv`, you can install just ruff `uv tool install ruff`
109
+
110
+ * [`just`](https://github.com/casey/just)
111
+ * A modern way to save and run project-specific commands
112
+ * After installing `uv`, you can install just with `uv tool install rust-just`
113
+
114
+ ## Development Team
115
+
116
+ URSA has been developed at Los Alamos National Laboratory as part of the ArtIMis project.
117
+
118
+ <img src="./logos/artimis.png" alt="ArtIMis Logo" width="200" height="200">
119
+
120
+ ### Notice of Copyright Assertion (O4958):
121
+ *This program is Open-Source under the BSD-3 License.
122
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:*
123
+ - *Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.*
124
+ - *Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.*
125
+ - *Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.*
126
+
127
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
128
+
129
+ [pypi-version]: https://img.shields.io/pypi/v/ursa-ai?style=flat-square&label=PyPI
130
+ [total-downloads]: https://img.shields.io/pepy/dt/ursa-ai?style=flat-square&label=downloads&color=blue
@@ -0,0 +1,26 @@
1
+ ursa/agents/__init__.py,sha256=J2GVc4GpQwNHvzxePgjtAHgz806ZGrSPJs3QyOPHFlA,616
2
+ ursa/agents/arxiv_agent.py,sha256=1w3Mu8iK3vhP1zWCtqnuMQ5CQ74H6oy6RPWJPBkLC_o,13151
3
+ ursa/agents/base.py,sha256=4wHwXPAcmH_Ml3SG-E4aJwcMVkNPAG9MBbKTWpCQVsc,1337
4
+ ursa/agents/code_review_agent.py,sha256=0qTTeTgYSM0n1Z7nPtDKP7790Ea9bm9Jg2E4w8jLDC8,11376
5
+ ursa/agents/execution_agent.py,sha256=NoEsT4Y9wpMU0rceQP9RUhmBFBjPfjy6zp0hgiQXnQA,16468
6
+ ursa/agents/hypothesizer_agent.py,sha256=FQwLKUKsoV-yw9dS8Tync1fy1Tw84VCx4zThX_SJH8I,23210
7
+ ursa/agents/mp_agent.py,sha256=qMosIZncfCqsNNNHsShc0paq2bH_gzrHZiaEf_a6j-8,9220
8
+ ursa/agents/planning_agent.py,sha256=CdXNgH4VDvdcrgtwtydvvZOeV5DPLDkX24I_iWYBAew,5192
9
+ ursa/agents/recall_agent.py,sha256=wtUf3tkcyUAdhQ8gNV_mLeXBoAhFV-RDZ20EMTweXSw,836
10
+ ursa/agents/websearch_agent.py,sha256=_JlTPSeA_UY2nwMaiiYBDWzvcgoys_RWBfNIUWMfbr8,7117
11
+ ursa/prompt_library/code_review_prompts.py,sha256=6hI158aIJ4LPxuwuGHSsqj3AIngpJVez05twPQSCFaw,2442
12
+ ursa/prompt_library/execution_prompts.py,sha256=hDmvSZzGcmza4DP1Z-yDVAJCTcvQ-sgz8bQxBAVqaeg,2153
13
+ ursa/prompt_library/hypothesizer_prompts.py,sha256=is1SpCbsUtsYsyWOFz3H6M4nCnfyOMPj2p0mOcaEucc,763
14
+ ursa/prompt_library/literature_prompts.py,sha256=xUteIC6Cf8CvKFNKy_YxViiJBK1ldYu2Y18BNOWOZ68,420
15
+ ursa/prompt_library/planning_prompts.py,sha256=SvvKbPU29yHnM4dLyNu12Z8OrBIjFWc_jUPAtsEtJOA,3536
16
+ ursa/prompt_library/websearch_prompts.py,sha256=Dyu26-o-QpUjo_m4Uj7mE_SXzLxPueT8P-yXI1s3RZU,8858
17
+ ursa/tools/run_command.py,sha256=sQRuHtRyJYWEyL9dpW_Ukc-xQ5vmKKJK1i_6z3uKEfA,690
18
+ ursa/tools/write_code.py,sha256=DtCsUMZegYm0mk-HMPG5Zo3Ba1gbGfnXHsv1NZTdDs8,1220
19
+ ursa/util/diff_renderer.py,sha256=efiXAd6Lz1-4QSNNX4_yYSK4xEInnmWUENXqg7emOPg,4014
20
+ ursa/util/memory_logger.py,sha256=Prnqs-ZJDiCVGzsKAxBK5NUUOGCrzE9mGPKjz7adRFY,5674
21
+ ursa/util/parse.py,sha256=M0cjyQWmjatxX4WbVmDRUiirTLyW-t_Aemlrlrsc5nA,2811
22
+ ursa_ai-0.2.2.dist-info/licenses/LICENSE,sha256=4Vr6_u2zTHIUvYjoOBg9ztDbfpV3hyCFv3mTCS87gYU,1482
23
+ ursa_ai-0.2.2.dist-info/METADATA,sha256=01crOx6RAtm-YcYSvGmXJGrafsgeGD5P-R4VI57Bmy0,6557
24
+ ursa_ai-0.2.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
25
+ ursa_ai-0.2.2.dist-info/top_level.txt,sha256=OjA1gRYSUAeiXGnpqPC8iOOGfcjFO1IlP848qMnYSdY,5
26
+ ursa_ai-0.2.2.dist-info/RECORD,,
@@ -0,0 +1,8 @@
1
+ This program is Open-Source under the BSD-3 License.
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
5
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
6
+ Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
7
+
8
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ursa/__init__.py DELETED
@@ -1,2 +0,0 @@
1
- def hello() -> str:
2
- return "Hello from ursa!"
ursa/py.typed DELETED
File without changes
@@ -1,7 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: ursa-ai
3
- Version: 0.0.3
4
- Summary: Add your description here
5
- Author-email: Mike Grosskopf <mikegros@lanl.gov>, Arthur Lui <alui@lanl.gov>
6
- Requires-Python: >=3.11
7
- Description-Content-Type: text/markdown
@@ -1,6 +0,0 @@
1
- ursa/__init__.py,sha256=axGrqZf_bAtq20gqwmzW5O2nu4qKHfvXIpH2y5ihh18,50
2
- ursa/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- ursa_ai-0.0.3.dist-info/METADATA,sha256=bfGgg-JCXWuu80P0nK3NtNiLJKikBVvqYzA8yIg1Okw,227
4
- ursa_ai-0.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
- ursa_ai-0.0.3.dist-info/top_level.txt,sha256=OjA1gRYSUAeiXGnpqPC8iOOGfcjFO1IlP848qMnYSdY,5
6
- ursa_ai-0.0.3.dist-info/RECORD,,