> ## Documentation Index
> Fetch the complete documentation index at: https://docs.maikers.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CLI Tool

> Command-line interface for Maikers SDK operations

## Overview

The Maikers CLI provides a command-line interface for interacting with the Maikers API. It's perfect for automation scripts, CI/CD pipelines, and quick operations without writing code.

<CardGroup cols={2}>
  <Card title="Authentication" icon="key">
    Manage API keys and authentication
  </Card>

  <Card title="Agent Management" icon="robot">
    Create, update, and manage AI agents
  </Card>

  <Card title="Agent Interaction" icon="comments">
    Query and interact with your agents
  </Card>

  <Card title="Automation" icon="gear">
    Perfect for scripts and automation workflows
  </Card>
</CardGroup>

## Installation & Setup

### Build the CLI

First, clone the repository and build the CLI:

```bash theme={null}
# Clone the repository
git clone https://github.com/maikershq/maikers-mainframe-sdk.git
cd maikers-mainframe-sdk

# Install dependencies
pnpm install

# Build the CLI
pnpm build
```

### Verify Installation

```bash theme={null}
# Check if CLI is working
node dist/cli.js --help
```

You should see the help output with available commands.

## Authentication Commands

### Login

Authenticate with your Maikers API key:

```bash theme={null}
node dist/cli.js auth login YOUR_API_KEY
```

<Note>
  Replace `YOUR_API_KEY` with your actual API key from the Maikers dashboard.
</Note>

### Check Status

Verify your authentication status:

```bash theme={null}
node dist/cli.js auth status
```

**Example Output:**

```
✅ Authenticated
API Key: mk_****...****
Status: Active
```

### Logout

Clear your stored authentication:

```bash theme={null}
node dist/cli.js auth logout
```

## Agent Management Commands

### Create Agent

Create a new AI agent with specified configuration:

```bash theme={null}
node dist/cli.js agent create \
  --id "my-trading-bot" \
  --name "Trading Assistant" \
  --description "AI agent for market analysis and trading" \
  --risk-level low \
  --job-types trading,analysis \
  --skills sniper,analyst \
  --persona-id helpful-assistant
```

**Parameters:**

* `--id`: Unique identifier for the agent
* `--name`: Display name for the agent
* `--description`: Description of the agent's purpose
* `--risk-level`: Risk tolerance (low, medium, high)
* `--job-types`: Comma-separated list of job types
* `--skills`: Comma-separated list of skills
* `--persona-id`: Persona identifier for the agent

**Example Output:**

```
✅ Agent created successfully
ID: my-trading-bot
Name: Trading Assistant
Skills: sniper, analyst
Status: Active
```

### List Agents

List all your agents:

```bash theme={null}
node dist/cli.js agent list
```

**Example Output:**

```
📋 Your Agents:

1. my-trading-bot
   Name: Trading Assistant
   Skills: sniper, analyst
   Status: Active
   Created: 2024-01-15T10:30:00Z

2. content-creator
   Name: Content Generator
   Skills: writer, entertainer
   Status: Active
   Created: 2024-01-14T15:45:00Z
```

### Get Agent Details

Get detailed information about a specific agent:

```bash theme={null}
node dist/cli.js agent get my-trading-bot
```

### Update Agent Settings

Update an existing agent's configuration:

```bash theme={null}
node dist/cli.js agent update-settings my-trading-bot \
  --persona "professional trader" \
  --risks low,medium
```

### Delete Agent

Remove an agent:

```bash theme={null}
node dist/cli.js agent delete my-trading-bot
```

<Warning>
  This action is irreversible. Make sure you want to permanently delete the
  agent.
</Warning>

## Agent Interaction Commands

### Query Agent

Send a message to an agent and get a response:

```bash theme={null}
node dist/cli.js agent query my-trading-bot \
  --message "What are the current market trends for Bitcoin?"
```

**Example Output:**

```
🤖 Agent Response:

Based on current market analysis, Bitcoin is showing:

1. **Bullish Momentum**: Price has broken above key resistance at $45,000
2. **Volume Increase**: Trading volume up 25% in the last 24 hours
3. **Technical Indicators**: RSI at 65, indicating strong but not overbought
4. **Market Sentiment**: Fear & Greed Index at 72 (Greed)

Recommendation: Consider taking profits at $48,000 resistance level.

---
Response Time: 2.3s
Credits Used: 3
```

### Interactive Chat

Start an interactive chat session with an agent:

```bash theme={null}
node dist/cli.js agent chat my-trading-bot
```

This opens an interactive session where you can have a conversation:

```
🤖 Starting chat with Trading Assistant
Type 'exit' to quit, 'help' for commands

You: What's the best strategy for DeFi yield farming?

Agent: For DeFi yield farming, I recommend a diversified approach:

1. **Start Conservative**: Begin with established protocols like Aave or Compound
2. **Risk Management**: Never put more than 20% in high-risk farms
3. **Impermanent Loss**: Understand IL before providing liquidity
4. **Gas Optimization**: Use Layer 2 solutions when possible

Would you like me to analyze specific protocols?

You: Yes, analyze Uniswap V3 vs Curve

Agent: Here's a comparison of Uniswap V3 vs Curve for yield farming:

[Detailed analysis continues...]

You: exit

Chat session ended. Total credits used: 8
```

## Automation & Scripting

### Batch Operations

Create multiple agents from a configuration file:

```bash theme={null}
# Create agents.json configuration file
cat > agents.json << EOF
[
  {
    "id": "trader-1",
    "name": "BTC Trader",
    "skills": ["sniper", "analyst"],
    "jobTypes": ["trading"]
  },
  {
    "id": "researcher-1",
    "name": "Market Researcher",
    "skills": ["hunter", "analyst"],
    "jobTypes": ["research"]
  }
]
EOF

# Create agents from file
node dist/cli.js agent create-batch --file agents.json
```

### Scheduled Queries

Use with cron for scheduled operations:

```bash theme={null}
# Add to crontab for hourly market analysis
# 0 * * * * /path/to/node /path/to/dist/cli.js agent query trader-1 --message "Analyze current market conditions" >> /var/log/maikers.log
```

### Pipeline Integration

Use in CI/CD pipelines:

```bash theme={null}
#!/bin/bash
# deploy-trading-bot.sh

# Authenticate
node dist/cli.js auth login $MAIKERS_API_KEY

# Create trading bot
node dist/cli.js agent create \
  --id "production-trader-$(date +%s)" \
  --name "Production Trading Bot" \
  --description "Automated trading bot for production" \
  --risk-level medium \
  --skills sniper,analyst,strategist

# Test the bot
RESPONSE=$(node dist/cli.js agent query production-trader-$(date +%s) \
  --message "Perform system check and report status")

if [[ $RESPONSE == *"✅"* ]]; then
  echo "Trading bot deployed successfully"
  exit 0
else
  echo "Trading bot deployment failed"
  exit 1
fi
```

## Advanced Usage

### JSON Output

Get machine-readable JSON output:

```bash theme={null}
node dist/cli.js agent query my-trading-bot \
  --message "Analyze Bitcoin" \
  --format json
```

**Output:**

```json theme={null}
{
  "agentId": "my-trading-bot",
  "response": "Bitcoin analysis shows bullish momentum...",
  "creditsUsed": 3,
  "timestamp": "2024-01-15T10:30:00Z",
  "responseTime": 2300
}
```

### Verbose Mode

Get detailed operation logs:

```bash theme={null}
node dist/cli.js agent create \
  --id "debug-agent" \
  --name "Debug Agent" \
  --verbose
```

### Configuration File

Use a configuration file for default settings:

```bash theme={null}
# Create ~/.maikers/config.json
mkdir -p ~/.maikers
cat > ~/.maikers/config.json << EOF
{
  "apiKey": "your-api-key",
  "baseUrl": "https://api.maikers.com",
  "defaultRiskLevel": "medium",
  "defaultPersona": "helpful-assistant"
}
EOF

# CLI will automatically use these defaults
node dist/cli.js agent create --id "auto-config-agent"
```

## Error Handling

### Common Errors

<AccordionGroup>
  <Accordion title="🔐 Authentication Failed">
    **Error:** `❌ Authentication failed. Invalid API key.`

    **Solutions:**

    * Verify your API key is correct
    * Check if the key has expired
    * Ensure you're using the right environment (dev/prod)

    ```bash theme={null}
    # Re-authenticate
    node dist/cli.js auth logout
    node dist/cli.js auth login NEW_API_KEY
    ```
  </Accordion>

  <Accordion title="Agent Not Found">
    **Error:** `❌ Agent 'my-agent' not found.`

    **Solutions:**

    * Check the agent ID spelling
    * List all agents to verify it exists
    * Ensure the agent wasn't deleted

    ```bash theme={null}
    # List all agents
    node dist/cli.js agent list
    ```
  </Accordion>

  <Accordion title="Rate Limit Exceeded">
    **Error:** `❌ Rate limit exceeded. Please try again later.`

    **Solutions:**

    * Wait before retrying
    * Implement delays in scripts
    * Consider upgrading your plan

    ```bash theme={null}
    # Add delay in scripts
    sleep 5
    node dist/cli.js agent query my-agent --message "..."
    ```
  </Accordion>

  <Accordion title="🌐 Network Errors">
    **Error:** `❌ Network error: Connection timeout.`

    **Solutions:**

    * Check internet connection
    * Verify API endpoint is accessible
    * Try again with longer timeout

    ```bash theme={null}
    # Increase timeout
    node dist/cli.js agent query my-agent \
      --message "..." \
      --timeout 60000
    ```
  </Accordion>
</AccordionGroup>

## Help & Documentation

### Get Help

```bash theme={null}
# General help
node dist/cli.js --help

# Command-specific help
node dist/cli.js agent --help
node dist/cli.js agent create --help
node dist/cli.js auth --help
```

### Version Information

```bash theme={null}
node dist/cli.js --version
```

## Best Practices

<CardGroup cols={2}>
  <Card title="Security" icon="shield">
    **Protect Your API Key**

    * Never commit API keys to version control
    * Use environment variables in scripts
    * Rotate keys regularly
    * Use different keys for different environments
  </Card>

  <Card title="Automation" icon="robot">
    **Script Optimization**

    * Add error handling to scripts
    * Implement retry logic with backoff
    * Log operations for debugging
    * Use JSON output for parsing
  </Card>

  <Card title="Performance" icon="zap">
    **Efficient Usage**

    * Batch operations when possible
    * Respect rate limits
    * Cache responses when appropriate
    * Monitor credit usage
  </Card>

  <Card title="Monitoring" icon="chart-bar">
    **Operation Tracking**

    * Log all operations
    * Monitor agent performance
    * Track credit consumption
    * Set up alerts for failures
  </Card>
</CardGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="SDK Library" icon="code" href="/sdk/overview">
    Use the SDK as a library in your applications
  </Card>

  <Card title="Examples" icon="lightbulb" href="/sdk/examples">
    Explore practical examples and use cases
  </Card>

  <Card title="API Reference" icon="book" href="/sdk/api-reference">
    Complete API documentation
  </Card>

  <Card title="GitHub" icon="github" href="https://github.com/maikershq/maikers-mainframe-sdk">
    View source code and contribute
  </Card>
</CardGroup>
