Using the Weni by VTEX CLI
Learn how to use Weni by VTEX CLI
This guide will walk you through using the Weni by VTEX CLI to create, deploy, and manage AI-powered agents, enhancing your customer service capabilities. By the end of this guide, you will be able to install the CLI, configure your project, and deploy your first agent.
With the CLI, you can:
- Create, deploy, and manage multiple AI agents
- Add custom tools to the agents
- Update agent configuration and behavior
To use the Weni by VTEX CLI, you must have: a Weni by VTEX Platform account; an account at weni.ai; and at least one project in your account.
The content is organized as follows:
- Installing the CLI
- Getting started with your project
- Troubleshooting
- Contributing to Weni by VTEX CLI
Step 1 - Installing the CLI
There are two installation methods:
- A quick installation with
pip. - A manual installation with
Poetry, for development purposes.
Install via pip
To install the CLI using pip, open the terminal and run the following command:
_10pip install weni-cli
Install via Poetry
To install the CLI manually, follow these steps:
- Clone the repository by running the following command:
_10git clone https://github.com/weni-ai/weni-cli.git_10cd weni-cli
- Install dependencies and make the CLI executable by running the following command:
_10poetry shell_10poetry install
Step 2 - Verifying Installation
To verify that Weni by VTEX CLI is installed, type the following command in your terminal:
_10weni
If the installation was successful, your terminal should display something like this:
An error occurred while loading the image https://github.com/vtexdocs/dev-portal-content/main/docs/guides/Weni-by-VTEX/CLI/assets/weni-installation-verification.png
Troubleshooting
If you encounter any issues:
- Check our GitHub Issues
- Create a new issue with:
- Your operating system
- Python version (
python --version) - Error message
- Steps to reproduce
Getting started with your project
Step 1 - Log in to your Weni by VTEX account
- Open the terminal and run the following command:
_10weni login
This should open your browser on the login page for authentication. If that does not happen, you can open the URL shown in the terminal.
- Log in using your Weni by VTEX account and password.
Step 2 - List your projects
List your projects by running the following command:
_10weni project list
This will show all projects you have access to and, next to each of them, its universally unique identifier (UUID).
Step 3 - Select a project
Select the project you want to work on by running the following command:
_10weni project use your-project-uuid
Replace your-project-uuid with the UUID from the project list.
Step 4 - Verify the current project
To verify you're working on the correct project, you can run the following command:
_10weni project current
You will see the project's UUID in the terminal output.
Step 5 - Initialize a new agent
To create an agent, run the following command:
_10weni init
This command performs the following actions:
- Creates the necessary folder structure for your agent.
- Sets up a pre-built CEP (Complex Event Processing) tool.
- Creates an
agent_definition.yamlfile with the initial configuration. You can edit this file to customize your agent's behavior.
_21agents:_21 sample_agent:_21 name: "CEP Agent"_21 description: "Weni's CEP agent"_21 instructions:_21 - "You are an expert in providing addresses to the user based on a postal code provided by the user"_21 - "The user will send a ZIP code (postal code) and you must provide the address corresponding to this code."_21 guardrails:_21 - "Don't talk about politics, religion, or any other sensitive topic. Keep it neutral."_21 tools:_21 - get_address:_21 name: "Get Address"_21 source: _21 path: "tools/get_address"_21 entrypoint: "main.GetAddress"_21 description: "Function to get the address from the postal code"_21 parameters:_21 - cep:_21 description: "postal code"_21 type: "string"_21 required: true
Understanding the source configuration
In the YAML above, there are two fields nested within the source field:
-
path: This field specifies the directory containing your tool implementation.- The command automatically creates a
toolsdirectory and a folder calledget_addressnested within it. - In this path, you can find the files
main.py,requirements.txt, andtest_definition.yaml.
- The command automatically creates a
-
entrypoint: This field informs the system which class to use.- Using
main.GetAddressindicates that the system finds the file namedmain.py, uses theGetAddressclass inside the file and that the class must inherit from theToolsbase class.
- Using
Your project structure should look like this:
_10my-agent-project/_10├── agent_definition.yaml_10└── tools/_10 └── get_address/_10 ├── main.py # Contains GetAddress class_10 └── requirements.txt # Dependencies
Step 6 - Implement the tool manually (if weni init fails)
If the command doesn't work, you can implement this tool manually following the next steps:
- Create the tool directory
_10 mkdir -p tools/get_address_10 cd tools/get_address
- Create the file
tools/get_address/main.pyand insert the following:
_16 from weni import Tool_16 from weni.context import Context_16 from weni.responses import TextResponse_16 import requests_16_16_16 class GetAddress(Tool):_16 def execute(self, context: Context) -> TextResponse:_16 cep = context.parameters.get("cep", "")_16 address_response = self.get_address_by_cep(cep=cep)_16 return TextResponse(data=address_response)_16_16 def get_address_by_cep(self, cep):_16 url = f"https://viacep.com.br/ws/{cep}/json/"_16 response = requests.get(url)_16 return response.json()
- The class name
GetAddressmust match the class name in the entrypoint - The file name
main.pymust match the file name in the entrypoint - The class must inherit from
Tooland implement theexecutemethod
- Create the
requirements.txtfile
_10 requests==2.32.3
Step 7 - Add credentials and global files (optional)
If you have credentials and global files, place these files in tools/get_address during local runs:
_10# .env_10api_key=your-development-api-key
_10# .globals_10BASE_URL=https://api.example.com
Step 7 - Deploy the agent
Deploy your agent by running the following command:
_10weni project push agent_definition.yaml
Advanced Configuration
Custom Parameters
You can add more parameters to your tools:
_10parameters:_10 - format:_10 description: "Response format (json or text)"_10 type: "string"_10 required: false_10 default: "json"
Multiple Tools
Agents can have multiple tools:
_10tools:_10 - get_address:_10 # tool definition_10 - validate_cep:_10 # another tool definition
Contributing to Weni by VTEX CLI
This guide will help you get started with contributing to the project.
Development Setup
Prerequisites
- Python >= 3.12
- Poetry >= 1.8.5
- Git
Setting Up Development Environment
-
Fork the repository on GitHub
-
Clone your fork:
_10git clone https://github.com/YOUR_USERNAME/weni-cli.git_10cd weni-cli -
Install dependencies:
_10poetry install -
Create a new branch:
_10git checkout -b feature/your-feature-name
Development Guidelines
Code Style
- Follow PEP 8 guidelines
- Use meaningful variable and function names
- Add docstrings to functions and classes
- Keep functions focused and concise
Testing
-
Write tests for new features:
_10def test_your_feature():_10# Your test code here_10assert expected == actual -
Run tests:
_10poetry run pytest -
Check coverage:
_10poetry run pytest --cov
Documentation
- Update documentation for new features
- Add docstrings to new functions
- Update README.md if needed
- Add examples when relevant
Making Changes
Workflow
- Create a feature branch
- Make your changes
- Write or update tests
- Update documentation
- Run tests locally
- Commit your changes
- Push to your fork
- Create a Pull Request
Commit Messages
Follow conventional commits:
feat:New featuresfix:Bug fixesdocs:Documentation changestest:Adding or updating testschore:Maintenance tasks
Example:
_10git commit -m "feat: add support for custom headers in requests"
Pull Requests
PR Guidelines
- Create one PR per feature/fix
- Include tests
- Update documentation
- Reference issues if applicable
- Keep changes focused and minimal
PR Template
_14### Description_14Brief description of changes_14_14### Type of Change_14- [ ] Bug fix_14- [ ] New feature_14- [ ] Documentation update_14- [ ] Other (specify)_14_14### Testing_14Describe testing done_14_14### Documentation_14List documentation updates
Review Process
- Automated checks must pass
- Code review by maintainers
- Documentation review
- Changes requested if needed
- Approval and merge
Getting Help
- Create an issue for bugs
- Ask questions in discussions
- Join our community channels
Development Tools
Recommended VSCode Extensions
- Python
- YAML
- markdownlint
- GitLens
Useful Commands
_11# Format code_11poetry run black ._11_11# Run linter_11poetry run flake8_11_11# Run tests_11poetry run pytest_11_11# Build documentation_11poetry run mkdocs serve
Release Process
- Version bump
- Update CHANGELOG
- Create release PR
- Tag release
- Deploy to PyPI
Community
- Be respectful and inclusive
- Help others when possible
- Share knowledge
- Follow our Code of Conduct