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.
Quick Start
- 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 - 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
# Chat with an agent
praisonai-ts chat "Your message here"
# Run an agent with a task
praisonai-ts run "Your task" --agent my-agent.yamlchat
Interactive chat with an agent.
Basic Usage
praisonai-ts chat "Hello, how are you?"With Model Selection
praisonai-ts chat "Hello" --model gpt-4o-miniWith Streaming
praisonai-ts chat "Write a poem" --streamOptions
| Option | Description | Default |
|---|---|---|
--model, -m | LLM model to use | gpt-4o-mini |
--stream, -s | Enable streaming output | false |
--session | Session ID for conversation continuity | Auto-generated |
--verbose, -v | Enable verbose output | false |
--json | Output as JSON | false |
Examples
# 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" --streamJSON Output Format
{
"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
praisonai-ts run "Analyze this data" --agent my-agent.yamlOptions
| Option | Description | Default |
|---|---|---|
--agent, -a | Agent configuration file or name | – |
--tools, -t | Comma-separated list of tools | – |
--verbose, -v | Enable verbose output | false |
--json | Output as JSON | false |
Examples
# 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" --jsonEnvironment 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 PRAISONAI_MODEL=gpt-4o-mini
# Optional - default database for persistence
export PRAISONAI_DB=sqlite:./data.dbDatabase Persistence
Use the --db flag to persist memory, sessions, and knowledge across CLI invocations.
Supported Databases
| Database | URL Format |
|---|---|
| SQLite | sqlite:./data.db |
| PostgreSQL | postgres://user:pass@host:5432/db |
| Redis | redis://localhost:6379 |
Memory Persistence
# 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.dbSession Persistence
# 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.dbKnowledge Persistence
# 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.dbEnvironment Variable
Instead of passing --db on every command, set the environment variable:
export PRAISONAI_DB=sqlite:./data.db
# Now all commands use persistent storage
praisonai-ts memory add "Hello world"
praisonai-ts memory list # Shows persisted entryScripting Examples
Bash Script
#!/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
# Chain with other commands
praisonai-ts chat "Generate a topic" | \
xargs -I {} praisonai-ts chat "Write about: {}"Error Handling
Missing API Key
$ praisonai-ts chat "Hello"
Error: OPENAI_API_KEY environment variable is not setInvalid Model
$ praisonai-ts chat "Hello" --model invalid-model
Error: Model 'invalid-model' is not available