File size: 3,892 Bytes
07c2476
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# CLI Commands

The AI Imaging Agent provides a command-line interface for starting the application and managing the software catalog.

## Available Commands

### ai_agent chat



Launch the chat-based user interface.



```bash

ai_agent chat
```



**What it does**:



1. Performs startup catalog synchronization

2. Loads the FAISS index

3. Initializes the retrieval and agent pipelines

4. Launches the Gradio web interface on `http://127.0.0.1:7860`

5. Starts background catalog refresh (if configured)



**Options**: None (all configuration via `.env` and `config.yaml`)



**Example**:



```bash

$ ai_agent chat

[startup-sync] 150 → dataset/catalog.jsonl

[startup-refresh] catalog unchanged; keeping existing FAISS index

Running on local URL:  http://127.0.0.1:7860



To create a public link, set `share=True` in `launch()`.

```

**Background Refresh**:

If `SYNC_EVERY_HOURS` is set in `.env`, the catalog will auto-refresh in the background:

```dotenv

SYNC_EVERY_HOURS=24  # Check every 24 hours

```

### ai_agent sync



Manually synchronize the software catalog and rebuild the index.



```bash

ai_agent sync
```



**What it does**:



1. Loads the software catalog from `SOFTWARE_CATALOG` path

2. Embeds all tool descriptions using BGE-M3

3. Builds FAISS vector index

4. Saves artifacts to `artifacts/rag_index/`



**When to use**:



- After editing `catalog.jsonl`

- After adding new tools

- To force index rebuild

- For testing catalog changes



**Example**:



```bash

$ ai_agent sync

[sync] 150 → dataset/catalog.jsonl

[sync] Embedding 150 tools... (5.2s)

[sync] Building FAISS index...

[sync] Saved to artifacts/rag_index/

[sync] Sync complete.

```

## Command Aliases

Both commands are available with either `ai_agent` or `ai-agent`:

```bash

ai_agent chat   # Works

ai-agent chat   # Also works



ai_agent sync   # Works

ai-agent sync   # Also works

```

## Common Usage Patterns

### Development Workflow

```bash

# Edit catalog

vim dataset/catalog.jsonl



# Sync catalog

ai_agent sync



# Test changes

ai_agent chat

```

<!-- ### Production Deployment

```bash

# In your deployment script:

ai_agent sync                    # Ensure index is built

nohup ai_agent chat &           # Run in background

```

Or use environment variable control:

```bash

export SYNC_EVERY_HOURS=0       # Disable auto-refresh in production

ai_agent chat

``` -->



### Testing & Development



```bash

# Enable debug logging

export LOGLEVEL_CONSOLE=DEBUG

export LOG_PROMPTS=1

ai_agent chat

```

## Environment Variables

All configuration is via environment variables (see [Environment Variables Reference](environment.md)).

## Exit Codes

- **0**: Success
- **1**: General error (see logs)

## Troubleshooting

### Command Not Found

If you see `command not found: ai_agent`:

```bash

# Ensure package is installed

pip install -e .



# Check installation

pip list | grep ai-agent



# Try with python -m

python -m ai_agent.cli chat

```

### Port Already in Use

If port 7860 is occupied:

```bash

# Find and kill process

lsof -ti:7860 | xargs kill -9



# Or change port in code (ui/app.py)

```

### Catalog Load Error

If catalog fails to load:

```bash

# Verify catalog exists

ls -lh dataset/catalog.jsonl



# Verify JSONL syntax

python -c "import json; [json.loads(l) for l in open('dataset/catalog.jsonl')]"



# Check environment variable

echo $SOFTWARE_CATALOG

```

### Index Build Error

If FAISS index building fails:

```bash

# Check artifacts directory

ls -lh artifacts/rag_index/



# Rebuild manually

rm -rf artifacts/rag_index/

ai_agent sync

```

## Next Steps

- Configure [Environment Variables](environment.md)
- Review the [Changelog](changelog.md)
- Return to [Getting Started](../getting-started/quickstart.md)