Agent CLI

Command-line interface for single Agent chat and run operations

The PraisonAI TypeScript CLI provides commands for chatting with and running agents directly from the command line.

Diagram

User

CLI

Agent

Response

Quick Start

  1. Simple Usage
    bash
    # Chat with an agent
    praisonai-ts chat "Your message here"
    
    # Run an agent with a task
    praisonai-ts run "Your task" --agent my-agent.yaml
  2. With Configuration
    bash
    praisonai-ts chat "Hello" --model gpt-4o-mini --stream
    praisonai-ts run "Analyse this data" --agent my-agent.yaml --verbose

Commands Overview

bash
# Chat with an agent
praisonai-ts chat "Your message here"

# Run an agent with a task
praisonai-ts run "Your task" --agent my-agent.yaml

chat

Interactive chat with an agent.

Basic Usage

bash
praisonai-ts chat "Hello, how are you?"

With Model Selection

bash
praisonai-ts chat "Hello" --model gpt-4o-mini

With Streaming

bash
praisonai-ts chat "Write a poem" --stream

Options

OptionDescriptionDefault
--model, -mLLM model to usegpt-4o-mini
--stream, -sEnable streaming outputfalse
--sessionSession ID for conversation continuityAuto-generated
--verbose, -vEnable verbose outputfalse
--jsonOutput as JSONfalse

Examples

bash
# Simple chat
praisonai-ts chat "What is the capital of France?"

# With custom model
praisonai-ts chat "Explain quantum computing" --model gpt-4o

# With session persistence
praisonai-ts chat "My name is Alice" --session user-123
praisonai-ts chat "What's my name?" --session user-123

# JSON output
praisonai-ts chat "Hello" --json

# Streaming output
praisonai-ts chat "Write a story about a robot" --stream

JSON Output Format

json
{
  "success": true,
  "data": {
    "response": "Hello! How can I help you today?",
    "sessionId": "550e8400-e29b-41d4-a716-446655440000"
  },
  "meta": {
    "duration_ms": 1234,
    "model": "gpt-4o-mini"
  }
}

run

Run an agent with a specific task.

Basic Usage

bash
praisonai-ts run "Analyze this data" --agent my-agent.yaml

Options

OptionDescriptionDefault
--agent, -aAgent configuration file or name–
--tools, -tComma-separated list of tools–
--verbose, -vEnable verbose outputfalse
--jsonOutput as JSONfalse

Examples

bash
# Run a task with tools
praisonai-ts run "Search the web for AI news" --tools tavily

# Run with agent config
praisonai-ts run "Summarize the document" --agent researcher.yaml

# JSON output for scripting
praisonai-ts run "Generate 5 random names" --json

Environment Variables

Set these environment variables for API access:

bash
# Required - at least one provider key
export OPENAI_API_KEY=sk-...
export ANTHROPIC_API_KEY=sk-ant-...
export GOOGLE_API_KEY=...

# Optional - default model
export PRAISONAI_MODEL=gpt-4o-mini

# Optional - default database for persistence
export PRAISONAI_DB=sqlite:./data.db

Database Persistence

Use the --db flag to persist memory, sessions, and knowledge across CLI invocations.

Supported Databases

DatabaseURL Format
SQLitesqlite:./data.db
PostgreSQLpostgres://user:pass@host:5432/db
Redisredis://localhost:6379

Memory Persistence

bash
# Add memory that persists
praisonai-ts memory add "User prefers dark mode" --db sqlite:./data.db

# List persisted memories
praisonai-ts memory list --db sqlite:./data.db

# Search memories
praisonai-ts memory search "dark" --db sqlite:./data.db

Session Persistence

bash
# Create a persistent session
praisonai-ts session create my-session --db sqlite:./data.db

# List all sessions
praisonai-ts session list --db sqlite:./data.db

# Get session details
praisonai-ts session get my-session --db sqlite:./data.db

Knowledge Persistence

bash
# Add knowledge from text
praisonai-ts knowledge add "PraisonAI is an AI agent framework" --db sqlite:./data.db

# Add knowledge from file
praisonai-ts knowledge add ./document.txt --db sqlite:./data.db

# Search knowledge base
praisonai-ts knowledge search "agent framework" --db sqlite:./data.db

# List all knowledge entries
praisonai-ts knowledge list --db sqlite:./data.db

Environment Variable

Instead of passing --db on every command, set the environment variable:

bash
export PRAISONAI_DB=sqlite:./data.db

# Now all commands use persistent storage
praisonai-ts memory add "Hello world"
praisonai-ts memory list  # Shows persisted entry

Scripting Examples

Bash Script

bash
#!/bin/bash

# Run agent and capture output
RESULT=$(praisonai-ts chat "What is 2+2?" --json)
ANSWER=$(echo $RESULT | jq -r '.data.response')
echo "Answer: $ANSWER"

Pipeline Usage

bash
# Chain with other commands
praisonai-ts chat "Generate a topic" | \
  xargs -I {} praisonai-ts chat "Write about: {}"

Error Handling

Missing API Key

bash
$ praisonai-ts chat "Hello"
Error: OPENAI_API_KEY environment variable is not set

Invalid Model

bash
$ praisonai-ts chat "Hello" --model invalid-model
Error: Model 'invalid-model' is not available

Related