Skip to content

Commit 157b97b

Browse files
committed
fix examples
1 parent 603344a commit 157b97b

15 files changed

Lines changed: 68 additions & 69 deletions

.pre-commit-config.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ repos:
55
hooks:
66
# Run the linter.
77
- id: ruff-check
8-
args: [ --fix, --select, "I,F401" ]
8+
args: [ --fix, --extend-fixable, "F401", --ignore, "D100,W505" ]
99
# Run the formatter.
1010
- id: ruff-format
11+
12+
# "src/**/__init__.py" = ["F401"]

examples/combine_agents_examples/agent_graph.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,6 @@
5454
"""
5555

5656

57-
class State(TypedDict):
58-
messages: Annotated[list, add_messages]
59-
current_progress: str
60-
code_files: list[str]
61-
workspace: str
62-
arxiv_results: list[str]
63-
64-
6557
model = ChatLiteLLM(
6658
model="openai/o3",
6759
max_tokens=50000,
@@ -167,7 +159,7 @@ def runner(self, state: State) -> State:
167159
)
168160
os.makedirs(new_state["workspace"], exist_ok=True)
169161

170-
if type(new_state["messages"][0]) == SystemMessage:
162+
if isinstance(new_state["messages"][0], SystemMessage):
171163
new_state["messages"][0] = SystemMessage(content=self.runner_prompt)
172164
else:
173165
new_state["messages"] = [
@@ -190,7 +182,7 @@ def summarize(self, state: ExecutionState) -> ExecutionState:
190182
memories = []
191183
# Handle looping through the messages
192184
for x in state["messages"]:
193-
if not type(x) == AIMessage:
185+
if not isinstance(x, AIMessage):
194186
memories.append(x.content)
195187
elif not x.tool_calls:
196188
memories.append(x.content)

examples/single_agent_examples/arxiv_agent/high_entropy_alloy_papers.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import sys
21
import time
32

4-
sys.path.append("../../.")
5-
63
from langchain_community.callbacks.openai_info import OpenAICallbackHandler
74
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
85

@@ -34,7 +31,7 @@ def main():
3431

3532
t0 = time.time()
3633

37-
result = agent.run(
34+
agent.run(
3835
arxiv_search_query="High Entropy Alloys",
3936
context="Find High entropy alloys suitable for application under extreme conditions. For candidates that you identify, provide the starting structure, crystal structure, lattice parameters, and space group.",
4037
)

examples/single_agent_examples/arxiv_agent/neutron_star_radius.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from pathlib import Path
2+
13
from langchain_litellm import ChatLiteLLM
24

35
from ursa.agents import ArxivAgent
@@ -6,14 +8,15 @@
68
def main():
79
llm = ChatLiteLLM(model="openai/o3", max_completion_tokens=20000)
810

11+
Path("workspace").mkdir(exist_ok=True)
912
agent = ArxivAgent(
1013
llm=llm,
1114
summarize=True,
1215
process_images=True,
1316
max_results=3,
14-
database_path="arxiv_papers_neutron_star",
15-
summaries_path="arxiv_summaries_neutron_star",
16-
vectorstore_path="arxiv_vectorstores_neutron_star",
17+
database_path="workspace/arxiv_papers_neutron_star",
18+
summaries_path="workspace/arxiv_summaries_neutron_star",
19+
vectorstore_path="workspace/arxiv_vectorstores_neutron_star",
1720
download_papers=True,
1821
)
1922

justfile

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
ruff := "uvx ruff@0.12.10"
2+
lint-options := "--extend-fixable=F401 --ignore='D100,W505'"
3+
14
help:
25
just -l -u
36

47
test:
58
uv run examples/single_agent_examples/execution_agent/bayesian_optimization.py
69

710
test-vowels:
8-
uv run examples/single_agent_examples/research_agent/ten_vowel_city.py
11+
uv run examples/single_agent_examples/websearch_agent/ten_vowel_city.py
912

1013
# Test neutron star example with latest dependencies
1114
neutron-latest:
@@ -19,5 +22,14 @@ clean-workspaces:
1922
rm -rf workspace
2023
rm -rf workspace_*/
2124

22-
pre-commit:
25+
lint:
2326
uv run pre-commit run --all-files
27+
28+
lint-diff:
29+
{{ ruff }} check {{ lint-options }} --diff
30+
31+
lint-stats:
32+
{{ ruff }} check {{ lint-options }} --statistics
33+
34+
lint-watch:
35+
{{ ruff }} check {{ lint-options }} --watch

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,14 @@ line-length = 80
6666

6767
[tool.ruff.lint]
6868
ignore = ["D100"]
69-
extend-select = ["I", "W505"] # "D"
70-
extend-unsafe-fixes = ["F401"]
69+
extend-select = ["I", "W505"] # D (docs)
70+
extend-unfixable = ["F401"]
7171
pydocstyle.convention = "numpy"
7272
pycodestyle.max-doc-length = 80
7373

74+
[tool.ruff.lint.per-file-ignores]
75+
"__init__.py" = ["F401"]
76+
7477
# Ignore test file documentation linting.
7578
[tool.ruff.lint.extend-per-file-ignores]
7679
"tests/**/*.py" = ["D"]

src/ursa/agents/__init__.py

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,9 @@
1-
from ursa.agents.arxiv_agent import ArxivAgent, PaperMetadata, PaperState
2-
from ursa.agents.base import BaseAgent, BaseChatModel
3-
from ursa.agents.code_review_agent import CodeReviewAgent, CodeReviewState
4-
from ursa.agents.execution_agent import ExecutionAgent, ExecutionState
5-
from ursa.agents.hypothesizer_agent import HypothesizerAgent, HypothesizerState
6-
from ursa.agents.mp_agent import MaterialsProjectAgent
7-
from ursa.agents.planning_agent import PlanningAgent, PlanningState
8-
from ursa.agents.recall_agent import RecallAgent
9-
from ursa.agents.websearch_agent import WebSearchAgent, WebSearchState
10-
11-
__all__ = [
12-
"ArxivAgent",
13-
"PaperMetadata",
14-
"PaperState",
15-
"BaseAgent",
16-
"BaseChatModel",
17-
"CodeReviewAgent",
18-
"CodeReviewState",
19-
"ExecutionAgent",
20-
"ExecutionState",
21-
"HypothesizerAgent",
22-
"HypothesizerState",
23-
"MaterialsProjectAgent",
24-
"PlanningAgent",
25-
"PlanningState",
26-
"RecallAgent",
27-
"WebSearchAgent",
28-
"WebSearchState",
29-
]
1+
from .arxiv_agent import ArxivAgent, PaperMetadata, PaperState
2+
from .base import BaseAgent, BaseChatModel
3+
from .code_review_agent import CodeReviewAgent, CodeReviewState
4+
from .execution_agent import ExecutionAgent, ExecutionState
5+
from .hypothesizer_agent import HypothesizerAgent, HypothesizerState
6+
from .mp_agent import MaterialsProjectAgent
7+
from .planning_agent import PlanningAgent, PlanningState
8+
from .recall_agent import RecallAgent
9+
from .websearch_agent import WebSearchAgent, WebSearchState

src/ursa/agents/arxiv_agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
try:
2525
from openai import OpenAI
26-
except:
26+
except Exception:
2727
pass
2828

2929
# embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
@@ -162,7 +162,7 @@ def _fetch_papers(self, query: str) -> List[PaperMetadata]:
162162
full_id = entry.id.split("/abs/")[-1]
163163
arxiv_id = full_id.split("/")[-1]
164164
title = entry.title.strip()
165-
authors = ", ".join(author.name for author in entry.authors)
165+
# authors = ", ".join(author.name for author in entry.authors)
166166
pdf_url = f"https://arxiv.org/pdf/{full_id}.pdf"
167167
pdf_filename = os.path.join(
168168
self.database_path, f"{arxiv_id}.pdf"
@@ -313,7 +313,7 @@ def process_paper(i, paper):
313313

314314
if "papers" not in state or len(state["papers"]) == 0:
315315
print(
316-
f"No papers retrieved - bad query or network connection to ArXiv?"
316+
"No papers retrieved - bad query or network connection to ArXiv?"
317317
)
318318
return {**state, "summaries": None}
319319

src/ursa/agents/code_review_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def main():
349349
}
350350
result = (
351351
code_review_agent.action.invoke(initial_state),
352-
{"configurable": {"thread_id": self.thread_id}},
352+
{"configurable": {"thread_id": 42}},
353353
)
354354
for x in result["messages"]:
355355
print(x.content)

src/ursa/agents/execution_agent.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def query_executor(self, state: ExecutionState) -> ExecutionState:
107107
# note that we've done the symlink now, so don't need to do it later
108108
new_state["symlinkdir"]["is_linked"] = True
109109

110-
if type(new_state["messages"][0]) == SystemMessage:
110+
if isinstance(new_state["messages"][0], SystemMessage):
111111
new_state["messages"][0] = SystemMessage(
112112
content=self.executor_prompt
113113
)
@@ -139,7 +139,7 @@ def summarize(self, state: ExecutionState) -> ExecutionState:
139139
memories = []
140140
# Handle looping through the messages
141141
for x in state["messages"]:
142-
if not type(x) == AIMessage:
142+
if not isinstance(x, AIMessage):
143143
memories.append(x.content)
144144
elif not x.tool_calls:
145145
memories.append(x.content)
@@ -426,7 +426,7 @@ def edit_code(
426426

427427
if old_code_clean not in content:
428428
console.print(
429-
f"[yellow] ⚠️ 'old_code' not found in file'; no changes made.[/]"
429+
"[yellow] ⚠️ 'old_code' not found in file'; no changes made.[/]"
430430
)
431431
return f"No changes made to {filename}: 'old_code' not found in file."
432432

@@ -483,7 +483,7 @@ def command_safe(state: ExecutionState) -> Literal["safe", "unsafe"]:
483483
index = -1
484484
message = state["messages"][index]
485485
# Loop through all the consecutive tool messages in reverse order
486-
while type(message) == ToolMessage:
486+
while isinstance(message, ToolMessage):
487487
if "[UNSAFE]" in message.content:
488488
return "unsafe"
489489

0 commit comments

Comments
 (0)