Skip to content

Commit

Permalink
generate project from template
Browse files Browse the repository at this point in the history
  • Loading branch information
bboynton97 committed Nov 27, 2024
1 parent a9daf82 commit 65e5fcc
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 27 deletions.
1 change: 1 addition & 0 deletions 0.2-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ We'll move forward with the codegen method unless other information comes to lig
- dont place into a subdirectory
- `--template <template_name>`
- generate the project according to a template
- can also consume a url

### `agentstack tools`
- Stays the same
Expand Down
6 changes: 5 additions & 1 deletion agentstack/cli/agentstack_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def __init__(self,
version: str = "",
license: str = "",
year: int = datetime.now().year,
template: str = "default"
template: str = "none",
template_version: str = "0",
):
self.project_name = clean_input(project_name) if project_name else "myagent"
self.project_slug = clean_input(project_slug) if project_slug else self.project_name
Expand All @@ -26,6 +27,7 @@ def __init__(self,
self.year = year
self.agentstack_version = get_version()
self.template = template
self.template_version = template

log.debug(f"ProjectMetadata: {self.to_dict()}")

Expand All @@ -39,6 +41,8 @@ def to_dict(self):
'license': self.license,
'year': self.year,
'agentstack_version': self.agentstack_version,
'template': self.template,
'template_version': self.template_version,
}

def to_json(self):
Expand Down
24 changes: 15 additions & 9 deletions agentstack/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def init_project_builder(slug_name: Optional[str] = None, template: Optional[str
print(term_color("Project name must be snake case", 'red'))
return

if template is not None and not use_wizard:
if template is not None and use_wizard:
print(term_color("Template and wizard flags cannot be used together", 'red'))
return

Expand All @@ -39,7 +39,7 @@ def init_project_builder(slug_name: Optional[str] = None, template: Optional[str
print(term_color(f"Failed to fetch template data from {template}. Status code: {response.status_code}", 'red'))
sys.exit(1)
else:
with importlib.resources.path('agentstack.templates.proj_templates', template) as template_path:
with importlib.resources.path('agentstack.templates.proj_templates', f'{template}.json') as template_path:
if template_path is None:
print(term_color(f"No such template {template} found", 'red'))
sys.exit(1)
Expand All @@ -58,8 +58,10 @@ def init_project_builder(slug_name: Optional[str] = None, template: Optional[str
'agents': template_data['agents'],
'tasks': template_data['tasks']
}
for tool_data in template_data['tools']:
generation.add_tool(tool_data['name'], agents=tool_data['agents'], path=project_details['name'])

tools = template_data['tools']
# for tool_data in template_data['tools']:
# generation.add_tool(tool_data['name'], agents=tool_data['agents'], path=project_details['name'])


elif use_wizard:
Expand All @@ -68,7 +70,7 @@ def init_project_builder(slug_name: Optional[str] = None, template: Optional[str
welcome_message()
framework = ask_framework()
design = ask_design()
# tools = ask_tools()
tools = ask_tools()

else:
welcome_message()
Expand All @@ -87,15 +89,17 @@ def init_project_builder(slug_name: Optional[str] = None, template: Optional[str
'tasks': []
}

# tools = []
tools = []

log.debug(
f"project_details: {project_details}"
f"framework: {framework}"
f"design: {design}"
)
insert_template(project_details, framework, design)
insert_template(project_details, framework, design, template_data)
# add_tools(tools, project_details['name'])
for tool_data in tools:
generation.add_tool(tool_data['name'], agents=tool_data['agents'], path=project_details['name'])


def welcome_message():
Expand Down Expand Up @@ -298,14 +302,16 @@ def ask_project_details(slug_name: Optional[str] = None) -> dict:
return questions


def insert_template(project_details: dict, framework_name: str, design: dict):
def insert_template(project_details: dict, framework_name: str, design: dict, template_data: Optional[dict] = None):
framework = FrameworkData(framework_name.lower())
project_metadata = ProjectMetadata(project_name=project_details["name"],
description=project_details["description"],
author_name=project_details["author"],
version="0.0.1",
license="MIT",
year=datetime.now().year)
year=datetime.now().year,
template=template_data['name'],
template_version=template_data['template_version'] if template_data else None)

project_structure = ProjectStructure()
project_structure.agents = design["agents"]
Expand Down
2 changes: 1 addition & 1 deletion agentstack/generation/tool_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def modify_agent_tools(
base_name: Base module name for tools (default: 'tools')
"""
if agents is not None:
valid_agents = get_agent_names()
valid_agents = get_agent_names(path=path)
for agent in agents:
if agent not in valid_agents:
print(term_color(f"Agent '{agent}' not found in the project.", 'red'))
Expand Down
2 changes: 1 addition & 1 deletion agentstack/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
TELEMETRY_URL = 'https://api.agentstack.sh/telemetry'

def collect_machine_telemetry(command: str):
if get_telemetry_opt_out():
if command != "init" and get_telemetry_opt_out():
return

telemetry_data = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"framework": "{{ cookiecutter.framework }}",
"agentstack_version": "{{ cookiecutter.agentstack_version }}",
"template": "{{ cookiecutter.template }}"
"agentstack_version": "{{ cookiecutter.project_metadata.agentstack_version }}",
"template": "{{ cookiecutter.project_metadata.template }}",
"template_version": "{{ cookiecutter.project_metadata.template_version }}"
}
23 changes: 10 additions & 13 deletions agentstack/templates/proj_templates/research.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
{
"name": "research",
"description": "Starter project research agent",
"framework": "Framework",
"template_version": 1,
"framework": "crewai",
"agents": [{
"name": "researcher",
"prompt": {
"role": "Gather data using research tools.",
"goal": "Collect all relevant information asked for using the tools available to you. The data will be analyzed later, compile a result of all data that you believe to be relevant to the query.",
"backstory": "You are an expert researcher. You are given a query and are tasked with providing as much relevant data in a concise manner."
},
"llm": "openai/gpt-4o"
"role": "Gather data using research tools.",
"goal": "Collect all relevant information asked for using the tools available to you. The data will be analyzed later, compile a result of all data that you believe to be relevant to the query.",
"backstory": "You are an expert researcher. You are given a query and are tasked with providing as much relevant data in a concise manner.",
"model": "openai/gpt-4o"
},{
"name": "analyst",
"prompt": {
"role": "Analyze gathered data.",
"goal": "Analyze and consolidate the data gathered from research to adequately answer the query provided in the task.",
"backstory": "You are an expert analyst. You are given a collection of research results and should use your knowledge to make conclusions on the data without making any assumptions that are not specifically supported by the data."
},
"llm": "openai/gpt-4o"
"role": "Analyze gathered data.",
"goal": "Analyze and consolidate the data gathered from research to adequately answer the query provided in the task.",
"backstory": "You are an expert analyst. You are given a collection of research results and should use your knowledge to make conclusions on the data without making any assumptions that are not specifically supported by the data.",
"model": "openai/gpt-4o"
}],
"tasks": [{
"name": "research",
Expand Down

0 comments on commit 65e5fcc

Please sign in to comment.