跳到主要内容

viben agent chat

Non-interactive conversation with a specified Agent.

Overview

Adds a chat subcommand to viben agent for non-interactive Agent conversations. The Agent calls the corresponding underlying executor based on its configured type (e.g., claude-code, gemini), while automatically loading the Agent's memory, MCP configuration, and Skills.

Command Interface

viben agent chat [OPTIONS] -n <AGENT_ID>

OPTIONS:
-n, --name <AGENT_ID> Agent ID (required)
-p, --prompt <PROMPT> Prompt (optional, reads from stdin if not provided)
-C, --cwd <DIR> Working directory (default: current directory)

--input-format <FORMAT> Input format: text (default), stream-json
--output-format <FORMAT> Output format: text (default), stream-json
--verbose Verbose output

-s, --session <SESSION_ID> Specify session ID
--resume <SESSION_ID> Resume existing session
--new-session Force create new session

--model <MODEL> Override Agent's configured model
--no-memory Don't load Agent memory
--dangerously-skip-permissions Skip permission checks

--json JSON format output

Data Flow Architecture


Usage Examples

# ============================================================
# Basic Usage
# ============================================================

# Conversation with default agent
viben agent chat -p "Analyze this code"

# Specify agent
viben agent chat -n my-agent -p "Write a sorting function"

# Read prompt from stdin
echo "Explain this error" | viben agent chat -n my-agent

# Specify working directory
viben agent chat -n my-agent -p "Analyze project structure" -C /path/to/project

# ============================================================
# Session Management
# ============================================================

# Use specific session
viben agent chat -n my-agent -p "Continue previous work" -s main

# Resume existing session
viben agent chat -n my-agent -p "Continue" --resume abc123

# Force create new session
viben agent chat -n my-agent -p "Start new task" --new-session

# ============================================================
# Advanced Options
# ============================================================

# Override model
viben agent chat -n my-agent -p "Complex reasoning task" --model claude-3-opus

# Don't load memory (clean state)
viben agent chat -n my-agent -p "Independent task" --no-memory

# Skip permission checks
viben agent chat -n my-agent -p "Automation script" --dangerously-skip-permissions

# ============================================================
# Programmatic Calls (JSON Stream)
# ============================================================

# JSON stream input/output
echo '{"type":"user","message":{"role":"user","content":"Analyze code"}}' | \
viben agent chat -n my-agent --input-format stream-json --output-format stream-json

# JSON format output
viben agent chat -n my-agent -p "Quick task" --json

Agent Memory Injection

Agent chat automatically loads and injects the Agent's memory:

Use --no-memory to skip memory loading.


Configuration Merge Order

When agent chat executes, configuration is merged by priority:

Priority from low to high:

1. Agent Base Configuration
~/.viben/agents/<id>/config.yaml
- type, model, mcp, skills, etc.
────────────────────────────────────────────────────
2. Workspace Configuration (based on agent type)
<cwd>/.claude/settings.json (if type=claude-code)
<cwd>/.cursor/settings.json (if type=cursor)
────────────────────────────────────────────────────
3. Command Line Arguments
--model, --session, --no-memory, etc.

Session Storage

Conversation sessions are stored in the Agent directory:

~/.viben/agents/<agent-id>/.agent_sessions/
└── <session_id>/
├── config.yaml # Session configuration
│ session_id: abc123
│ created_at: 2024-01-16T10:30:00Z
│ last_active: 2024-01-16T14:15:00Z
│ cwd: /path/to/project
│ model: claude-3-sonnet

└── messages.rollout.jsonl # Message history (JSONL format)

Output Examples

viben agent chat -n my-agent -p "Hello" (Human):

Hello! I'm your coding assistant. How can I help you today?

I have access to your project context and remember our previous conversations.
What would you like to work on?

viben agent chat -n my-agent -p "Hello" --json:

{
"success": true,
"agent_id": "my-agent",
"session_id": "abc123",
"response": "Hello! I'm your coding assistant...",
"tokens": {
"input": 150,
"output": 42
},
"memory_loaded": true,
"duration_ms": 1234
}

Error: Agent not found:

Error: Agent not found: unknown-agent

Available agents:
main claude-code
my-agent claude-code
researcher gemini

Use `viben agent list` to see all agents.

Error: Agent type doesn't support chat:

Error: Chat not supported for agent type: custom

Supported types: claude-code, gemini, codex

Difference from executor chat

Featureviben executor chatviben agent chat
TargetDirectly call underlying executorCall configured Agent
MemoryNoneAutomatically loads Agent memory
ConfigurationCommand line args onlyAgent config + workspace + command line
SessionTemporaryPersisted to Agent directory
MCPManual configuration neededUses Agent's MCP configuration
SkillsNoneUses Agent's Skills
Use CaseOne-off calls, script integrationOngoing conversations, project development

Acceptance Criteria

Basic Functionality

  • viben agent chat -n <id> -p <prompt> executes conversation
  • Read prompt from stdin (when -p not provided)
  • Select correct executor based on Agent type
  • -C specifies working directory

Memory System

  • Automatically load MEMORY.md
  • Automatically load today + yesterday logs
  • --no-memory skips memory loading
  • Update daily log after conversation

Session Management

  • -s specifies session ID
  • --resume resumes existing session
  • --new-session forces new session creation
  • Session persisted to .agent_sessions/

Configuration Merge

  • Load Agent base configuration
  • Merge workspace configuration
  • Command line args override configuration
  • --model overrides model setting

Input/Output Formats

  • --input-format text (default)
  • --input-format stream-json
  • --output-format text (default)
  • --output-format stream-json
  • --json outputs JSON result

Error Handling

  • Show available agents when Agent not found
  • Error when Agent type doesn't support chat
  • Error when no prompt and stdin is empty

Permissions & Security

  • Permission checks required by default
  • --dangerously-skip-permissions skips checks
  • --verbose verbose output