Skip to content

Commit efc7b7f

Browse files
authored
Merge pull request #102 from tcdent/ruff-line-length
Allow line length of 110
2 parents 9ccdfaa + 8be143b commit efc7b7f

File tree

12 files changed

+55
-175
lines changed

12 files changed

+55
-175
lines changed

agentstack/cli/agentstack_data.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ def __init__(
2020
template_version: str = "0",
2121
):
2222
self.project_name = clean_input(project_name) if project_name else "myagent"
23-
self.project_slug = (
24-
clean_input(project_slug) if project_slug else self.project_name
25-
)
23+
self.project_slug = clean_input(project_slug) if project_slug else self.project_name
2624
self.description = description
2725
self.author_name = author_name
2826
self.version = version

agentstack/cli/cli.py

Lines changed: 15 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -115,16 +115,10 @@ def init_project_builder(
115115

116116
tools = []
117117

118-
log.debug(
119-
f"project_details: {project_details}"
120-
f"framework: {framework}"
121-
f"design: {design}"
122-
)
118+
log.debug(f"project_details: {project_details}" f"framework: {framework}" f"design: {design}")
123119
insert_template(project_details, framework, design, template_data)
124120
for tool_data in tools:
125-
generation.add_tool(
126-
tool_data['name'], agents=tool_data['agents'], path=project_details['name']
127-
)
121+
generation.add_tool(tool_data['name'], agents=tool_data['agents'], path=project_details['name'])
128122

129123
try:
130124
packaging.install(f'{AGENTSTACK_PACKAGE}[{framework}]', path=slug_name)
@@ -164,9 +158,7 @@ def configure_default_model(path: Optional[str] = None):
164158
)
165159

166160
if model == other_msg: # If the user selects "Other", prompt for a model name
167-
print(
168-
f'A list of available models is available at: "https://docs.litellm.ai/docs/providers"'
169-
)
161+
print(f'A list of available models is available at: "https://docs.litellm.ai/docs/providers"')
170162
model = inquirer.text(message="Enter the model name")
171163

172164
with ConfigFile(path) as agentstack_config:
@@ -194,9 +186,7 @@ def ask_framework() -> str:
194186
# choices=["CrewAI", "Autogen", "LiteLLM"],
195187
# )
196188

197-
print(
198-
"Congrats! Your project is ready to go! Quickly add features now or skip to do it later.\n\n"
199-
)
189+
print("Congrats! Your project is ready to go! Quickly add features now or skip to do it later.\n\n")
200190

201191
return framework
202192

@@ -231,9 +221,7 @@ def ask_design() -> dict:
231221
while agent_incomplete:
232222
agent = inquirer.prompt(
233223
[
234-
inquirer.Text(
235-
"name", message="What's the name of this agent? (snake_case)"
236-
),
224+
inquirer.Text("name", message="What's the name of this agent? (snake_case)"),
237225
inquirer.Text("role", message="What role does this agent have?"),
238226
inquirer.Text("goal", message="What is the goal of the agent?"),
239227
inquirer.Text("backstory", message="Give your agent a backstory"),
@@ -254,11 +242,7 @@ def ask_design() -> dict:
254242
print(term_color("Error: Agent name is required - Try again", 'red'))
255243
agent_incomplete = True
256244
elif not is_snake_case(agent['name']):
257-
print(
258-
term_color(
259-
"Error: Agent name must be snake case - Try again", 'red'
260-
)
261-
)
245+
print(term_color("Error: Agent name must be snake case - Try again", 'red'))
262246
else:
263247
agent_incomplete = False
264248

@@ -286,12 +270,8 @@ def ask_design() -> dict:
286270
while task_incomplete:
287271
task = inquirer.prompt(
288272
[
289-
inquirer.Text(
290-
"name", message="What's the name of this task? (snake_case)"
291-
),
292-
inquirer.Text(
293-
"description", message="Describe the task in more detail"
294-
),
273+
inquirer.Text("name", message="What's the name of this task? (snake_case)"),
274+
inquirer.Text("description", message="Describe the task in more detail"),
295275
inquirer.Text(
296276
"expected_output",
297277
message="What do you expect the result to look like? (ex: A 5 bullet point summary of the email)",
@@ -307,9 +287,7 @@ def ask_design() -> dict:
307287
if not task['name'] or task['name'] == '':
308288
print(term_color("Error: Task name is required - Try again", 'red'))
309289
elif not is_snake_case(task['name']):
310-
print(
311-
term_color("Error: Task name must be snake case - Try again", 'red')
312-
)
290+
print(term_color("Error: Task name must be snake case - Try again", 'red'))
313291
else:
314292
task_incomplete = False
315293

@@ -348,14 +326,8 @@ def ask_tools() -> list:
348326
choices=list(tools_data.keys()) + ["~~ Stop adding tools ~~"],
349327
)
350328

351-
tools_in_cat = [
352-
f"{t['name']} - {t['url']}"
353-
for t in tools_data[tool_type]
354-
if t not in tools_to_add
355-
]
356-
tool_selection = inquirer.list_input(
357-
message="Select your tool", choices=tools_in_cat
358-
)
329+
tools_in_cat = [f"{t['name']} - {t['url']}" for t in tools_data[tool_type] if t not in tools_to_add]
330+
tool_selection = inquirer.list_input(message="Select your tool", choices=tools_in_cat)
359331

360332
tools_to_add.append(tool_selection.split(' - ')[0])
361333

@@ -369,22 +341,16 @@ def ask_tools() -> list:
369341

370342

371343
def ask_project_details(slug_name: Optional[str] = None) -> dict:
372-
name = inquirer.text(
373-
message="What's the name of your project (snake_case)", default=slug_name or ''
374-
)
344+
name = inquirer.text(message="What's the name of your project (snake_case)", default=slug_name or '')
375345

376346
if not is_snake_case(name):
377347
print(term_color("Project name must be snake case", 'red'))
378348
return ask_project_details(slug_name)
379349

380350
questions = inquirer.prompt(
381351
[
382-
inquirer.Text(
383-
"version", message="What's the initial version", default="0.1.0"
384-
),
385-
inquirer.Text(
386-
"description", message="Enter a description for your project"
387-
),
352+
inquirer.Text("version", message="What's the initial version", default="0.1.0"),
353+
inquirer.Text("description", message="Enter a description for your project"),
388354
inquirer.Text("author", message="Who's the author (your name)?"),
389355
]
390356
)
@@ -452,9 +418,7 @@ def insert_template(
452418
# subprocess.check_output(["git", "init"])
453419
# subprocess.check_output(["git", "add", "."])
454420
except:
455-
print(
456-
"Failed to initialize git repository. Maybe you're already in one? Do this with: git init"
457-
)
421+
print("Failed to initialize git repository. Maybe you're already in one? Do this with: git init")
458422

459423
# TODO: check if poetry is installed and if so, run poetry install in the new directory
460424
# os.system("poetry install")

agentstack/generation/agent_generation.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ def generate_crew_agent(
6868
# Handle None values
6969
role_str = FoldedScalarString(role) if role else FoldedScalarString('')
7070
goals_str = FoldedScalarString(goal) if goal else FoldedScalarString('')
71-
backstory_str = (
72-
FoldedScalarString(backstory) if backstory else FoldedScalarString('')
73-
)
71+
backstory_str = FoldedScalarString(backstory) if backstory else FoldedScalarString('')
7472
model_str = llm if llm else ''
7573

7674
# Add new agent details

agentstack/generation/files.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ class EnvFile:
8787

8888
variables: dict[str, str]
8989

90-
def __init__(
91-
self, path: Union[str, Path, None] = None, filename: str = ENV_FILEMANE
92-
):
90+
def __init__(self, path: Union[str, Path, None] = None, filename: str = ENV_FILEMANE):
9391
self._path = Path(path) if path else Path.cwd()
9492
self._filename = filename
9593
self.read()
@@ -117,9 +115,7 @@ def parse_line(line):
117115

118116
if os.path.exists(self._path / self._filename):
119117
with open(self._path / self._filename, 'r') as f:
120-
self.variables = dict(
121-
[parse_line(line) for line in f.readlines() if '=' in line]
122-
)
118+
self.variables = dict([parse_line(line) for line in f.readlines() if '=' in line])
123119
else:
124120
self.variables = {}
125121
self._new_variables = {}

agentstack/generation/gen_utils.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ def insert_code_after_tag(file_path, tag, code_to_insert, next_line=False):
1717
if tag in line:
1818
# Insert the code block after the tag
1919
indented_code = [
20-
(line[: len(line) - len(line.lstrip())] + code_line + '\n')
21-
for code_line in code_to_insert
20+
(line[: len(line) - len(line.lstrip())] + code_line + '\n') for code_line in code_to_insert
2221
]
2322
lines[index + 1 : index + 1] = indented_code
2423
break
@@ -40,8 +39,7 @@ def insert_after_tasks(file_path, code_to_insert):
4039
last_task_start = None
4140
for node in ast.walk(module):
4241
if isinstance(node, ast.FunctionDef) and any(
43-
isinstance(deco, ast.Name) and deco.id == 'task'
44-
for deco in node.decorator_list
42+
isinstance(deco, ast.Name) and deco.id == 'task' for deco in node.decorator_list
4543
):
4644
last_task_end = node.end_lineno
4745
last_task_start = node.lineno
@@ -140,10 +138,6 @@ def get_crew_components(
140138

141139
# If specific types were requested, only return those
142140
if component_type:
143-
return {
144-
k: v
145-
for k, v in components.items()
146-
if CrewComponent(k[:-1]) in component_type
147-
}
141+
return {k: v for k, v in components.items() if CrewComponent(k[:-1]) in component_type}
148142

149143
return components

agentstack/generation/task_generation.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,8 @@ def generate_crew_task(
6060
data = {}
6161

6262
# Handle None values
63-
description_str = (
64-
FoldedScalarString(description) if description else FoldedScalarString('')
65-
)
66-
expected_output_str = (
67-
FoldedScalarString(expected_output)
68-
if expected_output
69-
else FoldedScalarString('')
70-
)
63+
description_str = FoldedScalarString(description) if description else FoldedScalarString('')
64+
expected_output_str = FoldedScalarString(expected_output) if expected_output else FoldedScalarString('')
7165
agent_str = FoldedScalarString(agent) if agent else FoldedScalarString('')
7266

7367
# Add new agent details

agentstack/generation/tool_generation.py

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ def get_all_tools() -> list[ToolConfig]:
9696
return [ToolConfig.from_json(path) for path in get_all_tool_paths()]
9797

9898

99-
def add_tool(
100-
tool_name: str, path: Optional[str] = None, agents: Optional[List[str]] = []
101-
):
99+
def add_tool(tool_name: str, path: Optional[str] = None, agents: Optional[List[str]] = []):
102100
if path:
103101
path = path.endswith('/') and path or path + '/'
104102
else:
@@ -116,9 +114,7 @@ def add_tool(
116114

117115
if tool_data.packages:
118116
packaging.install(' '.join(tool_data.packages))
119-
shutil.copy(
120-
tool_file_path, f'{path}src/tools/{tool_name}_tool.py'
121-
) # Move tool from package to project
117+
shutil.copy(tool_file_path, f'{path}src/tools/{tool_name}_tool.py') # Move tool from package to project
122118
add_tool_to_tools_init(tool_data, path) # Export tool from tools dir
123119
add_tool_to_agent_definition(
124120
framework=framework, tool_data=tool_data, path=path, agents=agents
@@ -138,11 +134,7 @@ def add_tool(
138134
with agentstack_config as config:
139135
config.tools.append(tool_name)
140136

141-
print(
142-
term_color(
143-
f'🔨 Tool {tool_name} added to agentstack project successfully', 'green'
144-
)
145-
)
137+
print(term_color(f'🔨 Tool {tool_name} added to agentstack project successfully', 'green'))
146138
if tool_data.cta:
147139
print(term_color(f'🪩 {tool_data.cta}', 'blue'))
148140

@@ -224,9 +216,7 @@ def add_tool_to_agent_definition(
224216
)
225217

226218

227-
def remove_tool_from_agent_definition(
228-
framework: str, tool_data: ToolConfig, path: str = ''
229-
):
219+
def remove_tool_from_agent_definition(framework: str, tool_data: ToolConfig, path: str = ''):
230220
modify_agent_tools(
231221
framework=framework,
232222
tool_data=tool_data,
@@ -239,24 +229,18 @@ def remove_tool_from_agent_definition(
239229

240230
def _create_tool_attribute(tool_name: str, base_name: str = 'tools') -> ast.Attribute:
241231
"""Create an AST node for a tool attribute"""
242-
return ast.Attribute(
243-
value=ast.Name(id=base_name, ctx=ast.Load()), attr=tool_name, ctx=ast.Load()
244-
)
232+
return ast.Attribute(value=ast.Name(id=base_name, ctx=ast.Load()), attr=tool_name, ctx=ast.Load())
245233

246234

247235
def _create_starred_tool(tool_name: str, base_name: str = 'tools') -> ast.Starred:
248236
"""Create an AST node for a starred tool expression"""
249237
return ast.Starred(
250-
value=ast.Attribute(
251-
value=ast.Name(id=base_name, ctx=ast.Load()), attr=tool_name, ctx=ast.Load()
252-
),
238+
value=ast.Attribute(value=ast.Name(id=base_name, ctx=ast.Load()), attr=tool_name, ctx=ast.Load()),
253239
ctx=ast.Load(),
254240
)
255241

256242

257-
def _create_tool_attributes(
258-
tool_names: List[str], base_name: str = 'tools'
259-
) -> List[ast.Attribute]:
243+
def _create_tool_attributes(tool_names: List[str], base_name: str = 'tools') -> List[ast.Attribute]:
260244
"""Create AST nodes for multiple tool attributes"""
261245
return [_create_tool_attribute(name, base_name) for name in tool_names]
262246

@@ -266,16 +250,12 @@ def _create_tool_nodes(
266250
) -> List[Union[ast.Attribute, ast.Starred]]:
267251
"""Create AST nodes for multiple tool attributes"""
268252
return [
269-
_create_starred_tool(name, base_name)
270-
if is_bundled
271-
else _create_tool_attribute(name, base_name)
253+
_create_starred_tool(name, base_name) if is_bundled else _create_tool_attribute(name, base_name)
272254
for name in tool_names
273255
]
274256

275257

276-
def _is_tool_node_match(
277-
node: ast.AST, tool_name: str, base_name: str = 'tools'
278-
) -> bool:
258+
def _is_tool_node_match(node: ast.AST, tool_name: str, base_name: str = 'tools') -> bool:
279259
"""
280260
Check if an AST node matches a tool reference, regardless of whether it's starred
281261
@@ -318,19 +298,15 @@ def _process_tools_list(
318298
if operation == 'add':
319299
new_tools = current_tools.copy()
320300
# Add new tools with bundling if specified
321-
new_tools.extend(
322-
_create_tool_nodes(tool_data.tools, tool_data.tools_bundled, base_name)
323-
)
301+
new_tools.extend(_create_tool_nodes(tool_data.tools, tool_data.tools_bundled, base_name))
324302
return new_tools
325303

326304
elif operation == 'remove':
327305
# Filter out tools that match any in the removal list
328306
return [
329307
tool
330308
for tool in current_tools
331-
if not any(
332-
_is_tool_node_match(tool, name, base_name) for name in tool_data.tools
333-
)
309+
if not any(_is_tool_node_match(tool, name, base_name) for name in tool_data.tools)
334310
]
335311

336312
raise ValueError(f"Unsupported operation: {operation}")
@@ -359,9 +335,7 @@ def _modify_agent_tools(
359335
return node
360336

361337
# Check if this is an agent-decorated function
362-
if not any(
363-
isinstance(d, ast.Name) and d.id == 'agent' for d in node.decorator_list
364-
):
338+
if not any(isinstance(d, ast.Name) and d.id == 'agent' for d in node.decorator_list):
365339
return node
366340

367341
# Find the Return statement and modify tools
@@ -373,9 +347,7 @@ def _modify_agent_tools(
373347
if kw.arg == 'tools':
374348
if isinstance(kw.value, ast.List):
375349
# Process the tools list
376-
new_tools = _process_tools_list(
377-
kw.value.elts, tool_data, operation, base_name
378-
)
350+
new_tools = _process_tools_list(kw.value.elts, tool_data, operation, base_name)
379351

380352
# Replace with new list
381353
kw.value = ast.List(elts=new_tools, ctx=ast.Load())

0 commit comments

Comments
 (0)