Skip to content

Commit 7c1ecfa

Browse files
authored
Merge pull request #77 from tcdent/issue-2
Add selection process for default agent model and save selection to agentstack.json
2 parents c2725af + 6c1635b commit 7c1ecfa

File tree

6 files changed

+43
-7
lines changed

6 files changed

+43
-7
lines changed

agentstack/cli/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .cli import init_project_builder, list_tools
1+
from .cli import init_project_builder, list_tools, configure_default_model

agentstack/cli/cli.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@
1616
from .agentstack_data import FrameworkData, ProjectMetadata, ProjectStructure, CookiecutterData
1717
from agentstack.logger import log
1818
from agentstack.utils import get_package_path
19+
from agentstack.generation.files import ConfigFile
1920
from agentstack.generation.tool_generation import get_all_tools
2021
from .. import generation
2122
from ..utils import open_json_file, term_color, is_snake_case
2223

24+
PREFERRED_MODELS = [
25+
'openai/gpt-4o',
26+
'anthropic/claude-3-5-sonnet',
27+
'openai/o1-preview',
28+
'openai/gpt-4-turbo',
29+
'anthropic/claude-3-opus',
30+
]
2331

2432
def init_project_builder(slug_name: Optional[str] = None, template: Optional[str] = None, use_wizard: bool = False):
2533
if slug_name and not is_snake_case(slug_name):
@@ -114,6 +122,27 @@ def welcome_message():
114122
print(border)
115123

116124

125+
def configure_default_model(path: Optional[str] = None):
126+
"""Set the default model"""
127+
agentstack_config = ConfigFile(path)
128+
if agentstack_config.default_model:
129+
return # Default model already set
130+
131+
print("Project does not have a default model configured.")
132+
other_msg = f"Other (enter a model name)"
133+
model = inquirer.list_input(
134+
message="Which model would you like to use?",
135+
choices=PREFERRED_MODELS + [other_msg],
136+
)
137+
138+
if model == other_msg: # If the user selects "Other", prompt for a model name
139+
print(f'A list of available models is available at: "https://docs.litellm.ai/docs/providers"')
140+
model = inquirer.text(message="Enter the model name")
141+
142+
with ConfigFile(path) as agentstack_config:
143+
agentstack_config.default_model = model
144+
145+
117146
def ask_framework() -> str:
118147
framework = "CrewAI"
119148
# framework = inquirer.list_input(

agentstack/generation/agent_generation.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from .gen_utils import insert_code_after_tag, get_crew_components, CrewComponent
44
from agentstack.utils import verify_agentstack_project, get_framework
5+
from agentstack.generation.files import ConfigFile
56
import os
67
from ruamel.yaml import YAML
78
from ruamel.yaml.scalarstring import FoldedScalarString
@@ -14,14 +15,15 @@ def generate_agent(
1415
backstory: Optional[str],
1516
llm: Optional[str]
1617
):
18+
agentstack_config = ConfigFile() # TODO path
1719
if not role:
1820
role = 'Add your role here'
1921
if not goal:
2022
goal = 'Add your goal here'
2123
if not backstory:
2224
backstory = 'Add your backstory here'
2325
if not llm:
24-
llm = 'openai/gpt-4o'
26+
llm = agentstack_config.default_model
2527

2628
verify_agentstack_project()
2729

@@ -37,9 +39,6 @@ def generate_agent(
3739
print(f"Added agent \"{name}\" to your AgentStack project successfully!")
3840

3941

40-
41-
42-
4342
def generate_crew_agent(
4443
name,
4544
role: Optional[str] = 'Add your role here',

agentstack/generation/files.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ class ConfigFile(BaseModel):
3131
A list of tools that are currently installed in the project.
3232
telemetry_opt_out: Optional[bool]
3333
Whether the user has opted out of telemetry.
34+
default_model: Optional[str]
35+
The default model to use when generating agent configurations.
3436
"""
3537
framework: Optional[str] = DEFAULT_FRAMEWORK
3638
tools: list[str] = []
3739
telemetry_opt_out: Optional[bool] = None
40+
default_model: Optional[str] = None
3841

3942
def __init__(self, path: Union[str, Path, None] = None):
4043
path = Path(path) if path else Path.cwd()

agentstack/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import sys
44

5-
from agentstack.cli import init_project_builder, list_tools
5+
from agentstack.cli import init_project_builder, list_tools, configure_default_model
66
from agentstack.telemetry import track_cli_command
77
from agentstack.utils import get_version, get_framework
88
import agentstack.generation as generation
@@ -102,6 +102,8 @@ def main():
102102
os.system('python src/main.py')
103103
elif args.command in ['generate', 'g']:
104104
if args.generate_command in ['agent', 'a']:
105+
if not args.llm:
106+
configure_default_model()
105107
generation.generate_agent(args.name, args.role, args.goal, args.backstory, args.llm)
106108
elif args.generate_command in ['task', 't']:
107109
generation.generate_task(args.name, args.description, args.expected_output, args.agent)

tests/test_generation_files.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def test_read_config(self):
1414
assert config.framework == "crewai"
1515
assert config.tools == ["tool1", "tool2"]
1616
assert config.telemetry_opt_out is None
17+
assert config.default_model is None
1718

1819
def test_write_config(self):
1920
try:
@@ -25,6 +26,7 @@ def test_write_config(self):
2526
config.framework = "crewai"
2627
config.tools = ["tool1", "tool2"]
2728
config.telemetry_opt_out = True
29+
config.default_model = "openai/gpt-4o"
2830

2931
tmp_data = open(BASE_PATH/"tmp/agentstack.json").read()
3032
assert tmp_data == """{
@@ -33,7 +35,8 @@ def test_write_config(self):
3335
"tool1",
3436
"tool2"
3537
],
36-
"telemetry_opt_out": true
38+
"telemetry_opt_out": true,
39+
"default_model": "openai/gpt-4o"
3740
}"""
3841
except Exception as e:
3942
raise e

0 commit comments

Comments
 (0)