# CLI Reference

> Command-line interface for FlyMy.AI agents: create, run, list, and inspect agents from your terminal.

The `fma` command-line tool lets you manage agents, tools, and runs directly from your terminal.

## Installation

```bash
pip install fma
```

## Configuration

The CLI stores its configuration in `~/.config/fma/config.yaml`.

| Env variable | Description | Default |
|---|---|---|
| `FLYMYAI_API_KEY` | API key (used when no key is saved locally) | -- |
| `FLYMYAI_DSN` | Base URL override | `https://backend.flymy.ai` |

---

## Authentication

### Save your API key

```bash
fma api-key set fly-abc123...
```

The key is written to `~/.config/fma/config.yaml` and used for all subsequent commands.

### Show current key

```bash
fma api-key show
```

```
API key: fly-abc***23
```

The key is masked for security. You can also skip local storage entirely and export the key as an environment variable:

```bash
export FLYMYAI_API_KEY="fly-abc123..."
```

---

## Agents

### Create an agent

```bash
fma agents create --name "Web Researcher" \
  --goal "Search the web for {{ topic }} and return a summary with sources." \
  --tools 1,2
```

| Flag | Required | Description |
|---|---|---|
| `--name` | Yes | Human-readable name |
| `--goal` | Yes | Instructions (supports Handlebars templating) |
| `--tools` | No | Comma-separated tool IDs to attach |

### List agents

```bash
fma agents list
```

### Get agent details

```bash
fma agents get a1b2c3d4-...
```

Add `--json-output` for raw JSON:

```bash
fma agents get a1b2c3d4-... --json-output
```

### Update an agent

Only the flags you pass are changed; everything else stays the same.

```bash
fma agents update a1b2c3d4-... \
  --name "Updated Name" \
  --goal "New instructions." \
  --tools 1,2,3
```

### Delete an agent

```bash
fma agents delete a1b2c3d4-...
```

### Run an agent

```bash
fma agents run a1b2c3d4-...
```

By default, the command fires the run and exits immediately, printing the run ID.

| Flag | Description |
|---|---|
| `--stream` | Stream execution events in real-time with colored output |
| `--wait` | Poll until the run finishes, then print the result |
| `--timeout 300` | Maximum wait time in seconds (default: 300) |

**Fire-and-forget (default):**

```bash
$ fma agents run a1b2c3d4-...
Run #42 started.
```

**Stream events:**

```bash
$ fma agents run a1b2c3d4 --stream
Run #42 started

  [functions]  Functions for agent
  [tool]       Called tool tavily--search
  [tool]       Called tool system-utils--save_result

Status: completed
Result:
{
  "summary": "...",
  "sources": [...]
}
```

**Wait for result:**

```bash
$ fma agents run a1b2c3d4 --wait --timeout 120
Waiting for run #42... completed

{
  "summary": "...",
  "sources": [...]
}
```

---

## Runs

### List recent runs

```bash
fma runs list
fma runs list --limit 50
```

### Get run details

```bash
fma runs get 42
fma runs get 42 --json-output
```

### Cancel a run

```bash
fma runs cancel 42
```

### Wait for a run to finish

Polls the server until the run reaches a terminal state.

```bash
fma runs wait 42 --timeout 300 --poll 2.0
```

| Flag | Default | Description |
|---|---|---|
| `--timeout` | `300` | Maximum wait time in seconds |
| `--poll` | `2.0` | Polling interval in seconds |

### View run logs

```bash
fma runs logs 42
```

---

## Tools

### Browse the catalog

List all tools available on the FlyMy.AI platform:

```bash
fma tools available
```

Filter by category:

```bash
fma tools available --filter development
```

### List your configured tools

```bash
fma tools list
```

### Add a tool from the catalog

```bash
fma tools add tavily
```

### Configure a tool

Walk through the configuration steps interactively:

```bash
fma tools configure 7
```

Or provide configuration as JSON in one shot:

```bash
fma tools configure 7 --response '{"TAVILY_API_KEY": "tvly-..."}'
```

### Call a tool directly

Invoke a specific action on a configured tool without running an agent:

```bash
fma tools call 7 --action search --args '{"query": "FlyMyAI agents"}'
```

### Remove a tool

```bash
fma tools remove 7
```

---

## Complete workflow

A start-to-finish example: authenticate, add a tool, create an agent, and run it with streaming output.

```bash
# 1. Save your API key
fma api-key set fly-abc123...

# 2. Browse available tools and add one
fma tools available
fma tools add tavily

# 3. Configure the tool (note the ID from the previous step)
fma tools configure 1 --response '{"TAVILY_API_KEY": "tvly-..."}'

# 4. Create an agent with the tool attached
fma agents create \
  --name "Research Assistant" \
  --goal "Research {{ topic }} thoroughly. Return a summary with key findings and sources." \
  --tools 1

# 5. Run the agent and stream the output
fma agents run a1b2c3d4-... --stream
```

Expected output:

```
Run #1 started

  [functions]  Functions for agent
  [tool]       Called tool tavily--search
  [tool]       Called tool system-utils--save_result

Status: completed
Result:
{
  "summary": "...",
  "sources": [...]
}
```

To check on the run later or view its logs:

```bash
fma runs get 1
fma runs logs 1
```
