-
Notifications
You must be signed in to change notification settings - Fork 155
Description
Feature Summary
Enable automatic generation of dedicated CLI tools for each agent project created with better-agents. When creating an agent (e.g., "customer-support-agent"), the framework should provide an option to generate a corresponding CLI (e.g., customer-support) that:
- Exposes all agent tools as individual CLI commands
- Includes universal/fundamental commands common to all better-agents projects
- Provides a production-ready interface for agent interaction outside of development environments
Problem/Use Case
Current State:
Agents built with better-agents are excellent for development and testing but lack a streamlined way to be deployed as production-ready CLI tools. Developers must manually create CLIs or API wrappers to expose agent functionality to end users or integrate with existing workflows.
Real-World Scenarios:
-
DevOps Agent: An agent with tools for
deploy,rollback,check-health,view-logsshould be usable asdevops-agent deploy --env productionrather than through code or API calls -
Data Analysis Agent: Tools like
analyze_dataset,generate_report,visualizebecome CLI commands:data-agent analyze --file data.csv --output report.pdf -
CI/CD Integration: Agents with code review capabilities should be callable as
code-reviewer review --pr 123 --repo org/repoin GitHub Actions or GitLab CI -
System Administration: An agent with
backup,restore,monitortools becomes a first-class system utility -
Multi-Agent Orchestration: Different agents (research, writer, editor) with individual CLIs can be chained in bash scripts or workflows
Proposed Solution
Core Implementation
During project initialization:
better-agents init my-customer-agent --with-cli
# Or add to existing project
better-agents add cli --name customer-supportGenerated CLI structure:
my-customer-agent/
├── app/ # Agent code
│ └── agent.py
├── cli/ # Generated CLI
│ ├── __init__.py
│ ├── commands/
│ │ ├── agent_tools.py # Auto-generated from agent tools
│ │ └── universal.py # Common better-agents commands
│ ├── main.py # CLI entry point
│ └── config.py # CLI configuration
├── pyproject.toml # Includes CLI entry point
└── README.md
Agent Tools → CLI Commands Mapping
Automatic Tool Detection:
The framework uses AST parsing to extract tool definitions and type hints from agent code, automatically generating Click/Typer commands that map to agent tools.
CLI Usage:
# Install CLI
cd my-customer-agent
pip install -e . # or uv pip install -e .
# Use agent-specific commands
customer-support search-knowledge-base "how to reset password" --limit 5
customer-support create-ticket "Login issue" "User cannot access account" --priority high
# Interactive mode
customer-support chat --interactive
customer-support chat --input "Help me troubleshoot email delivery"Universal/Fundamental Commands
Common to ALL better-agents project CLIs:
Project Management:
<agent-cli> info # Show agent configuration, tools, version
<agent-cli> test # Run agent test scenarios
<agent-cli> validate # Validate agent configuration and prompts
<agent-cli> lint # Check agent code qualityDevelopment:
<agent-cli> dev # Start development server with hot-reload
<agent-cli> shell # Interactive Python shell with agent loaded
<agent-cli> debug --trace # Run with detailed execution tracingPrompts:
<agent-cli> prompts list # List all prompts
<agent-cli> prompts push <name> # Push prompt to LangWatch
<agent-cli> prompts pull <name> # Pull latest prompt version
<agent-cli> prompts diff <name> # Compare local vs remoteScenarios:
<agent-cli> scenarios run # Run all scenario tests
<agent-cli> scenarios run <name> # Run specific scenario
<agent-cli> scenarios record # Record new scenario from interactionEvaluations:
<agent-cli> eval list # List evaluation notebooks
<agent-cli> eval run <notebook> # Execute evaluation notebookDeployment:
<agent-cli> build # Build for production
<agent-cli> export --format api # Export as REST API spec
<agent-cli> export --format docker # Generate Dockerfile
<agent-cli> export --format lambda # Package for AWS LambdaObservability:
<agent-cli> logs --tail # Stream agent execution logs
<agent-cli> metrics # Show performance metrics
<agent-cli> trace <execution-id> # View detailed traceCLI Configuration
# cli/config.yaml (auto-generated)
cli:
name: customer-support
version: 0.1.0
agent:
path: app/agent.py
class: CustomerSupportAgent
commands:
tool_mapping:
enabled: true
prefix: "" # Optional prefix for tool commands
universal:
enabled: true
groups:
- project
- prompts
- scenarios
- evaluations
custom:
- name: deploy
script: scripts/deploy.sh
description: Deploy agent to production
output:
format: json # json | text | yaml
color: true
verbose: falseCLI Frameworks Support
Support multiple CLI framework backends:
better-agents init my-agent --with-cli --cli-framework click
better-agents init my-agent --with-cli --cli-framework typer
better-agents init my-agent --with-cli --cli-framework argparseFramework Characteristics:
- Click: Rich features, widely adopted, excellent documentation
- Typer: Modern, type-hints based, great for Python 3.7+
- Argparse: Stdlib, no dependencies, simple deployments
Implementation Roadmap
Phase 1: MVP (v0.1.0)
- Basic CLI scaffolding with
--with-cliflag - Auto-generate commands from agent
@tooldecorators - Universal commands:
info,test,dev - Click framework support
- Simple JSON/text output formats
Phase 2: Enhanced Features (v0.2.0)
- Typer and argparse framework support
- Full universal commands suite (prompts, scenarios, evaluations)
- Interactive chat mode
- Configuration file support (cli/config.yaml)
- Custom command registration
Phase 3: Production Ready (v0.3.0)
- Export to Docker/Lambda/API
- Authentication and authorization
- Rate limiting and error handling
- Telemetry and observability
- Multi-agent CLI orchestration
Phase 4: Advanced (v0.4.0+)
- Auto-completion (bash/zsh/fish)
- Plugin system for custom commands
- CLI marketplace/registry
- Cross-platform binaries (PyInstaller/cx_Freeze)
Benefits
- Production Deployment: Agents become first-class CLI tools usable in any environment
- CI/CD Integration: Easy integration into automated workflows
- Developer Experience: Consistent interface across all better-agents projects
- Discoverability:
--helpautomatically documents all agent capabilities - Automation: Enable bash scripting and workflow orchestration
- Testing: CLI commands are testable with standard testing frameworks
- Standardization: Universal commands ensure consistent patterns
Alternative Solutions
- Manual CLI Creation: Users create CLIs themselves - inconsistent patterns, more work
- API-Only Approach: Expose agents only via HTTP APIs - requires additional infrastructure
- Jupyter Notebooks: Use notebooks for interaction - not suitable for automation
- Generic Agent CLI: One CLI for all agents - loses agent-specific customization
Technical Considerations
- Use AST parsing to extract tool definitions and type hints
- Support for Pydantic models as CLI arguments with automatic validation
- Error handling with user-friendly messages
- Logging integration with better-agents observability
- Environment variable support for API keys and configuration
Related Work
This feature builds on proven patterns from:
- AWS CLI:
aws s3 cpmaps to S3 service operations - Kubectl:
kubectl get podsmaps to Kubernetes API operations - GitHub CLI:
gh pr createmaps to GitHub API operations - Stripe CLI:
stripe customers createmaps to Stripe API operations