earlyai-agent
AI-powered automatic unit test generation for Python, by Early.
earlyai-agent is the Python analysis engine used by the Early CLI to generate green (passing) unit tests. It analyzes your source code, identifies public functions and methods, and generates pytest tests using AI.
Note:
earlyai-agentis a dependency of the Early CLI and is not intended to be used standalone. Install and operate it through the Early CLI.
Installation
1. Install the Early CLI
npm install -g @earlyai/cli
See the CLI Installation Guide for details.
2. Install earlyai-agent
pip install earlyai-agent
Requirements: Python 3.11+
3. Get an API Key
You need an EarlyAI API key to use the agent. Contact support@startearly.ai or visit www.startearly.ai to get one.
Usage
All commands are run through the Early CLI. See the full CLI documentation for all options.
Generate tests for a project
early generate-project \
--api-key <your-api-key> \
--token <your-github-token> \
--target-directory src/ \
--ref-name <branch-name> \
--test-framework pytest
See the Repo CLI Guide for more details.
Generate tests on a pull request
early generate-pr \
--api-key <your-api-key> \
--token <your-github-token> \
--pr-number 123 \
--ref-name feature/my-branch \
--test-framework pytest
See the PR CLI Guide for more details.
Run locally
For quick local evaluation, see Running Early CLI Locally.
Configuration
All options can be set via CLI flags or environment variables:
| Flag | Env Variable | Default | Description |
|---|---|---|---|
--api-key |
API_KEY |
-- | EarlyAI API key (required) |
--token |
TOKEN |
-- | GitHub token for commits/PRs (required) |
--target-directory |
TARGET_DIRECTORY |
. |
File or directory to generate tests for |
--test-framework |
TEST_FRAMEWORK |
pytest |
Test framework (pytest) |
--test-structure |
TEST_STRUCTURE |
siblingFolder |
Where to place tests (siblingFolder, rootFolder) |
--max-concurrency |
MAX_CONCURRENCY |
3 |
Number of concurrent workers |
--max-testables |
MAX_TESTABLES |
unlimited | Max methods to generate tests for |
For the full configuration reference, see CLI Configuration.
Test file placement
siblingFolder(default): Tests are placed in a folder next to the source filesrc/services/user.py src/services/user.early.test/test_get_user.pyrootFolder: Tests are placed in a roottests/directory mirroring the source structure
CI/CD Integration
GitHub Actions (PR)
Add to .github/workflows/early-pr-test-generation.yml:
name: Early PR Test Generation
permissions:
contents: write
pull-requests: write
packages: read
on:
pull_request:
types: [opened, reopened, synchronize]
branches: [main]
jobs:
early-test-generation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: |
pip install earlyai-agent
npm install -g @earlyai/cli
- name: Generate tests
continue-on-error: true
env:
API_KEY: ${{ secrets.EARLY_AGENT_API_KEY }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REF_NAME: ${{ github.head_ref }}
BASE_REF: ${{ github.base_ref }}
TEST_FRAMEWORK: pytest
run: early generate-pr
For other CI/CD systems (Jenkins, CircleCI, Bitbucket Pipelines), see the Agent Onboarding Guide.
How It Works
- Scan -- Discovers Python source files in the target directory
- Extract -- Analyzes each file to identify public functions and methods
- Generate -- Uses AI to generate unit tests for each function
- Validate -- Runs generated tests with pytest, keeping only green (passing) tests
Troubleshooting
Support
- Documentation: docs.startearly.ai
- Email: support@startearly.ai
- Website: www.startearly.ai
License
Commercial
Metadata
Release files for earlyai-agent 0.4.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| earlyai_agent-0.4.3.tar.gz | 72.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| earlyai_agent-0.4.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 169.0 kB
Release files / earlyai_agent-0.4.3.tar.gz
| Download URL | earlyai_agent-0.4.3.tar.gz |
|---|---|
| Size | 72.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4aca660f4f7d3669ad0610b5bd6e79ef7bd29f1478f5803c62adb382e118f7ca
|
|
BLAKE2b-256 checksum How to use checksums |
d0c479440da5077f76dc64b277b657c80b8b01de0ee88ed31ac11c3f10ff9ace
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / earlyai_agent-0.4.3-py3-none-any.whl
| Download URL | earlyai_agent-0.4.3-py3-none-any.whl |
|---|---|
| Size | 96.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1aa806ebbec0d5934374005a099064dac973f53a80d59035cae192792357b1b6
|
|
BLAKE2b-256 checksum How to use checksums |
b5911c1c60dfb5b529f1e5b164afeb6fd37468b4bbd8f5a9d97ca4d137279d4c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|