Skip to content

Commit 03b24e6

Browse files
authored
fix: enhance cmd (#286)
* fix: enhance cmd * fix: enhance cmd
1 parent 993ac88 commit 03b24e6

File tree

7 files changed

+222
-31
lines changed

7 files changed

+222
-31
lines changed

docs/agents/overview.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ The Agent Starter Pack follows a "bring your own agent" approach. It provides se
88
| Agent Name | Description | Use Case |
99
|------------|-------------|----------|
1010
| `adk_base` | A base ReAct agent implemented using Google's [Agent Development Kit](https://github.com/google/adk-python) | General purpose conversational agent |
11-
| `adk_gemini_fullstack` | A production-ready fullstack research agent with Gemini | Complex research and information synthesis |
1211
| `agentic_rag` | A RAG agent for document retrieval and Q&A | Document search and question answering |
1312
| `langgraph_base_react` | A base ReAct agent using LangGraph | Graph based conversational agent |
1413
| `crewai_coding_crew` | A multi-agent system implemented with CrewAI | Collaborative coding assistance |

docs/cli/create.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ uvx agent-starter-pack create my-agent -a github.com/user/repo@main
3535
# ADK samples shortcut
3636
uvx agent-starter-pack create my-agent -a adk@gemini-fullstack
3737

38-
# Local templates
39-
uvx agent-starter-pack create my-agent -a local@./path/to/template
38+
# Use your existing project as source
39+
uvx agent-starter-pack create my-agent -a local@./path/to/project
4040
```
4141

4242
If omitted, you'll see an interactive list of available agents.
@@ -135,8 +135,8 @@ uvx agent-starter-pack create my-agent -a https://github.com/user/my-template
135135
# Use shorthand notation with branch
136136
uvx agent-starter-pack create my-agent -a github.com/user/template@develop
137137

138-
# Test local template
139-
uvx agent-starter-pack create my-agent -a local@./my-template
138+
# Use your existing project
139+
uvx agent-starter-pack create my-agent -a local@./my-project
140140
```
141141

142142
### Advanced Configuration

docs/cli/enhance.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ uvx agent-starter-pack enhance [TEMPLATE_PATH] [OPTIONS]
1818

1919
## Options
2020

21-
The `enhance` command supports all the same options as [`create`](./create.md), including:
21+
The `enhance` command supports all the same options as [`create`](./create.md), plus:
2222

23+
### `--base-template` TEMPLATE
24+
Override the base template for inheritance when enhancing your existing project. Available base templates include:
25+
- `adk_base` - Basic agent template (default)
26+
- `langgraph_base_react` - LangGraph-based ReAct agent
27+
- `agentic_rag` - RAG-enabled agent template
28+
29+
### Other Options
2330
- `--name, -n` - Project name (defaults to current directory name)
2431
- `--deployment-target, -d` - Deployment target (`agent_engine`, `cloud_run`)
2532
- `--include-data-ingestion, -i` - Include data ingestion pipeline
@@ -55,6 +62,16 @@ uvx agent-starter-pack enhance --include-data-ingestion --datastore alloydb
5562
uvx agent-starter-pack enhance --session-type alloydb
5663
```
5764

65+
### Base Template Inheritance
66+
67+
```bash
68+
# Enhance current project with LangGraph capabilities
69+
uvx agent-starter-pack enhance . --base-template langgraph_base_react
70+
71+
# Enhance with RAG-enabled base template
72+
uvx agent-starter-pack enhance . --base-template agentic_rag
73+
```
74+
5875
## Project Structure Validation
5976

6077
The enhance command validates your project structure and provides guidance:
@@ -87,6 +104,23 @@ It automatically:
87104
- Validates the project structure for compatibility
88105
- Applies the same file merging logic as the `create` command
89106

107+
### Base Template Inheritance
108+
109+
When enhancing your existing project (using `local@.` or `local@/path/to/project`), the enhance command will:
110+
111+
1. **Show current inheritance**: Display which base template your project inherits from
112+
2. **Provide guidance**: Show available alternative base templates and how to use them
113+
3. **Support CLI override**: Use `--base-template` to override the base template specified in `pyproject.toml`
114+
115+
The inheritance hierarchy works as follows:
116+
```
117+
Your Existing Project
118+
↓ (inherits from)
119+
Base Template (adk_base, langgraph_base_react, etc.)
120+
↓ (provides)
121+
Core Infrastructure & Capabilities
122+
```
123+
90124
## Use Cases
91125

92126
**Prototype to Production:**
@@ -111,6 +145,9 @@ uvx agent-starter-pack enhance --include-data-ingestion --datastore alloydb
111145
```bash
112146
# Upgrade from basic to advanced agent template
113147
uvx agent-starter-pack enhance adk@gemini-fullstack
148+
149+
# Or change base template inheritance
150+
uvx agent-starter-pack enhance . --base-template langgraph_base_react
114151
```
115152

116153
## Automatic Backup

docs/remote-templates/using-remote-templates.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ uvx agent-starter-pack create my-agent -a github.com/user/my-template@main
3232
# Use official ADK samples
3333
uvx agent-starter-pack create my-agent -a adk@gemini-fullstack
3434

35-
# Test local templates
36-
uvx agent-starter-pack create my-agent -a local@./path/to/template
35+
# Use your existing project
36+
uvx agent-starter-pack create my-agent -a local@./path/to/project
3737
```
3838

3939
The system automatically handles the rest - fetching the template, applying intelligent defaults, and generating your production-ready agent.
@@ -70,11 +70,11 @@ uvx agent-starter-pack create my-agent -a adk@data-science
7070
uvx agent-starter-pack create my-agent -a adk@chat-agent
7171
```
7272

73-
### Local Templates
73+
### Your Existing Projects
7474
```bash
75-
# Test templates on your local machine
76-
uvx agent-starter-pack create my-test-agent -a local@./path/to/your/template
77-
uvx agent-starter-pack create my-test-agent -a local@/absolute/path/to/template
75+
# Use your existing project as source
76+
uvx agent-starter-pack create my-test-agent -a local@./path/to/your/project
77+
uvx agent-starter-pack create my-test-agent -a local@/absolute/path/to/project
7878
```
7979

8080
## Advanced Usage

src/cli/commands/create.py

Lines changed: 78 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,62 @@ def shared_template_options(f: Callable) -> Callable:
104104
return f
105105

106106

107+
def get_available_base_templates() -> list[str]:
108+
"""Get list of available base templates for inheritance.
109+
110+
Returns:
111+
List of base template names.
112+
"""
113+
agents = get_available_agents()
114+
return sorted([agent_info["name"] for agent_info in agents.values()])
115+
116+
117+
def validate_base_template(base_template: str) -> bool:
118+
"""Validate that a base template exists.
119+
120+
Args:
121+
base_template: Name of the base template to validate
122+
123+
Returns:
124+
True if the base template exists, False otherwise
125+
"""
126+
available_templates = get_available_base_templates()
127+
return base_template in available_templates
128+
129+
130+
def get_standard_ignore_patterns() -> Callable[[str, list[str]], list[str]]:
131+
"""Get standard ignore patterns for copying directories.
132+
133+
Returns:
134+
A callable that can be used with shutil.copytree's ignore parameter.
135+
"""
136+
exclude_dirs = {
137+
".git",
138+
".venv",
139+
"venv",
140+
"__pycache__",
141+
".pytest_cache",
142+
"node_modules",
143+
".next",
144+
"dist",
145+
"build",
146+
".DS_Store",
147+
".vscode",
148+
".idea",
149+
"*.egg-info",
150+
".mypy_cache",
151+
".coverage",
152+
"htmlcov",
153+
".tox",
154+
".cache",
155+
}
156+
157+
def ignore_patterns(dir: str, files: list[str]) -> list[str]:
158+
return [f for f in files if f in exclude_dirs or f.startswith(".backup_")]
159+
160+
return ignore_patterns
161+
162+
107163
def normalize_project_name(project_name: str) -> str:
108164
"""Normalize project name for better compatibility with cloud resources and tools."""
109165

@@ -176,6 +232,7 @@ def create(
176232
region: str,
177233
skip_checks: bool,
178234
in_folder: bool,
235+
base_template: str | None = None,
179236
skip_welcome: bool = False,
180237
) -> None:
181238
"""Create GCP-based AI agent projects from templates."""
@@ -210,14 +267,14 @@ def create(
210267

211268
# Create backup of entire directory before in-folder templating
212269
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
213-
backup_dir = (
214-
project_path.parent / f".backup_{project_path.name}_{timestamp}"
215-
)
270+
backup_dir = project_path / f".backup_{project_path.name}_{timestamp}"
216271

217-
console.print("📦 [blue]Creating backup before enhancement...[/blue]")
272+
console.print("📦 [blue]Creating backup before modification...[/blue]")
218273

219274
try:
220-
shutil.copytree(project_path, backup_dir)
275+
shutil.copytree(
276+
project_path, backup_dir, ignore=get_standard_ignore_patterns()
277+
)
221278
console.print(f"Backup created: [cyan]{backup_dir.name}[/cyan]")
222279
except Exception as e:
223280
console.print(
@@ -257,7 +314,11 @@ def create(
257314
temp_dir = tempfile.mkdtemp(prefix="asp_local_template_")
258315
temp_dir_to_clean = temp_dir
259316
template_source_path = pathlib.Path(temp_dir) / local_path.name
260-
shutil.copytree(local_path, template_source_path)
317+
shutil.copytree(
318+
local_path,
319+
template_source_path,
320+
ignore=get_standard_ignore_patterns(),
321+
)
261322

262323
selected_agent = f"local_{template_source_path.name}"
263324
console.print(f"Using local template: {local_path}")
@@ -334,15 +395,25 @@ def create(
334395

335396
# Load template configuration based on whether it's remote or local
336397
if template_source_path:
398+
# Prepare CLI overrides for remote template config
399+
cli_overrides = {}
400+
if base_template:
401+
cli_overrides["base_template"] = base_template
402+
337403
# Load remote template config
338-
source_config = load_remote_template_config(template_source_path)
404+
source_config = load_remote_template_config(
405+
template_source_path, cli_overrides
406+
)
339407

340408
# Remote templates now work even without pyproject.toml thanks to defaults
341409
if debug and source_config:
342410
logging.debug(f"Final remote template config: {source_config}")
343411

344412
# Load base template config for inheritance
345413
base_template_name = get_base_template_name(source_config)
414+
if debug:
415+
logging.debug(f"Using base template: {base_template_name}")
416+
346417
base_template_path = (
347418
pathlib.Path(__file__).parent.parent.parent.parent
348419
/ "agents"

0 commit comments

Comments
 (0)