Skip to main content

Agent CLI

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

Commands Overview

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

# Run an agent with a task
praisonai-ts agent run --instructions "You are helpful" --task "Explain AI"

agent chat

Interactive chat with an agent.

Basic Usage

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

With Custom Instructions

praisonai-ts agent chat "What is AI?" --instructions "You are a tech expert"

With Model Selection

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

Options

OptionDescriptionDefault
--instructions, -iAgent instructions/system prompt”You are a helpful assistant”
--model, -mLLM model to usegpt-4o-mini
--name, -nAgent nameAuto-generated
--verbose, -vEnable verbose outputtrue
--jsonOutput as JSONfalse
--sessionSession ID for persistenceAuto-generated

Examples

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

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

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

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

JSON Output Format

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

agent run

Run an agent with a specific task.

Basic Usage

praisonai-ts agent run --instructions "You are a writer" --task "Write a haiku about coding"

Options

OptionDescriptionDefault
--instructions, -iAgent instructions (required)-
--task, -tTask to execute (required)-
--model, -mLLM model to usegpt-4o-mini
--name, -nAgent nameAuto-generated
--verbose, -vEnable verbose outputtrue
--jsonOutput as JSONfalse

Examples

# Run a research task
praisonai-ts agent run \
  --instructions "You are a research assistant" \
  --task "Summarize the latest AI news"

# Run with specific model
praisonai-ts agent run \
  --instructions "You are a code reviewer" \
  --task "Review this code for bugs" \
  --model gpt-4o

# JSON output for scripting
praisonai-ts agent run \
  --instructions "You are helpful" \
  --task "Generate 5 random names" \
  --json

Environment Variables

Set these environment variables for API access:
# 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 OPENAI_MODEL_NAME=gpt-4o-mini
export PRAISONAI_MODEL=gpt-4o-mini

# Optional - behavior
export PRAISON_VERBOSE=true
export PRAISON_PRETTY=true

Using with Tools

Currently, tool usage via CLI requires a configuration file:
# Create agents.yaml with tool definitions
praisonai-ts agent run --config agents.yaml --task "Check weather in Paris"

Scripting Examples

Bash Script

#!/bin/bash

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

Pipeline Usage

# Pipe input to agent
echo "Summarize this text" | praisonai-ts agent chat --stdin

# Chain agents
praisonai-ts agent chat "Generate a topic" | \
  praisonai-ts agent chat --instructions "Write about this topic"

Error Handling

Missing API Key

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

Invalid Model

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

See Also