|
1 | | -import os, sys |
2 | | -from typing import Optional, Any, List |
3 | | -import importlib.resources |
4 | | -from pathlib import Path |
5 | | -import json |
| 1 | +import os |
6 | 2 | import sys |
7 | | -from typing import Optional, List, Dict, Union |
| 3 | +from typing import Optional, List |
| 4 | +from pathlib import Path |
| 5 | +from typing import Union |
8 | 6 |
|
9 | 7 | from . import get_agent_names |
10 | | -from .gen_utils import insert_code_after_tag, string_in_file, _framework_filename |
| 8 | +from .gen_utils import insert_code_after_tag, _framework_filename |
11 | 9 | from ..utils import open_json_file, get_framework, term_color |
12 | | -import os |
13 | 10 | import shutil |
14 | 11 | import fileinput |
15 | 12 | import astor |
|
19 | 16 | from agentstack import packaging |
20 | 17 | from agentstack.utils import get_package_path |
21 | 18 | from agentstack.generation.files import ConfigFile, EnvFile |
22 | | -from .gen_utils import insert_code_after_tag, string_in_file |
23 | | -from ..utils import open_json_file, get_framework, term_color |
24 | 19 |
|
25 | 20 |
|
26 | 21 | TOOL_INIT_FILENAME = "src/tools/__init__.py" |
@@ -69,7 +64,7 @@ def from_json(cls, path: Path) -> 'ToolConfig': |
69 | 64 | except ValidationError as e: |
70 | 65 | print(term_color(f"Error validating tool config JSON: \n{path}", 'red')) |
71 | 66 | for error in e.errors(): |
72 | | - print(f"{' '.join(error['loc'])}: {error['msg']}") |
| 67 | + print(f"{' '.join([str(loc) for loc in error['loc']])}: {error['msg']}") |
73 | 68 | sys.exit(1) |
74 | 69 |
|
75 | 70 | def get_import_statement(self) -> str: |
@@ -148,7 +143,7 @@ def remove_tool(tool_name: str, path: Optional[str] = None): |
148 | 143 | framework = get_framework() |
149 | 144 | agentstack_config = ConfigFile(path) |
150 | 145 |
|
151 | | - if not tool_name in agentstack_config.tools: |
| 146 | + if tool_name not in agentstack_config.tools: |
152 | 147 | print(term_color(f'Tool {tool_name} is not installed', 'red')) |
153 | 148 | sys.exit(1) |
154 | 149 |
|
@@ -195,7 +190,10 @@ def remove_tool_from_tools_init(tool_data: ToolConfig, path: str = ''): |
195 | 190 |
|
196 | 191 |
|
197 | 192 | def add_tool_to_agent_definition( |
198 | | - framework: str, tool_data: ToolConfig, path: str = '', agents: list[str] = [] |
| 193 | + framework: str, |
| 194 | + tool_data: ToolConfig, |
| 195 | + path: str = '', |
| 196 | + agents: Optional[list[str]] = [], |
199 | 197 | ): |
200 | 198 | """ |
201 | 199 | Add tools to specific agent definitions using AST transformation. |
@@ -285,7 +283,7 @@ def _process_tools_list( |
285 | 283 | tool_data: ToolConfig, |
286 | 284 | operation: str, |
287 | 285 | base_name: str = 'tools', |
288 | | -) -> List[ast.AST]: |
| 286 | +) -> List[ast.AST]: # type: ignore[return-type,arg-type] |
289 | 287 | """ |
290 | 288 | Process a tools list according to the specified operation. |
291 | 289 |
|
@@ -347,10 +345,9 @@ def _modify_agent_tools( |
347 | 345 | if kw.arg == 'tools': |
348 | 346 | if isinstance(kw.value, ast.List): |
349 | 347 | # Process the tools list |
350 | | - new_tools = _process_tools_list(kw.value.elts, tool_data, operation, base_name) |
351 | | - |
| 348 | + new_tools = _process_tools_list(kw.value.elts, tool_data, operation, base_name) # type: ignore |
352 | 349 | # Replace with new list |
353 | | - kw.value = ast.List(elts=new_tools, ctx=ast.Load()) |
| 350 | + kw.value = ast.List(elts=new_tools, ctx=ast.Load()) # type: ignore |
354 | 351 |
|
355 | 352 | return node |
356 | 353 |
|
|
0 commit comments