lint-coding-agent / README.md
anonajay's picture
Upload folder using huggingface_hub
52958db verified
|
Raw History Blame Contribute Delete
9.78 kB
<div>
<img src="https://capsule-render.vercel.app/api?type=waving&color=gradient&height=200&section=header&text=Lint%20Coding%20Agent&fontSize=70&animation=fadeIn&fontAlignY=35" width="100%" />
<p align="center">
<img src="https://img.shields.io/badge/System_Status-Online-31c854?style=for-the-badge&logo=statuspage&logoColor=white" />
<img src="https://img.shields.io/badge/Maintained%3F-yes-2ea44f?style=for-the-badge" />
<img src="https://img.shields.io/badge/PRs-welcome-orange?style=for-the-badge&logo=github" />
</p>
<div>
### ⚑ Autonomous Software Engineering Sandbox ###
*Training agents to navigate codebases, one level at a time.*
---
title: Lint Coding Agent
emoji: πŸ’»
colorFrom: red
colorTo: purple
sdk: docker
pinned: false
app_port: 7860
base_path: /web
tags:
- openenv
---
> **System Status:** `Running` 🟒 | **Sandbox:** `Docker` 🐳 | **Latency:** `Ultra-Low` ⚑
A simple test environment that echoes back messages. Perfect for testing the env APIs as well as demonstrating environment usage patterns.
## Quick Start
The simplest way to use the Lint Coding Agent environment is through the `LintCodingAgentEnv` class:
```python
from lint_coding_agent import LintCodingAgentAction, LintCodingAgentEnv
try:
Β  Β  # Create environment from Docker image
Β  Β  lint_coding_agentenv = LintCodingAgentEnv.from_docker_image("lint_coding_agent-env:latest")
Β  Β  # Reset
Β  Β  result = lint_coding_agentenv.reset()
Β  Β  print(f"Reset: {result.observation.echoed_message}")
Β  Β  # Send multiple messages
Β  Β  messages = ["Hello, World!", "Testing echo", "Final message"]
Β  Β  for msg in messages:
Β  Β  Β  Β  result = lint_coding_agentenv.step(LintCodingAgentAction(message=msg))
Β  Β  Β  Β  print(f"Sent: '{msg}'")
Β  Β  Β  Β  print(f" Β β†’ Echoed: '{result.observation.echoed_message}'")
Β  Β  Β  Β  print(f" Β β†’ Length: {result.observation.message_length}")
Β  Β  Β  Β  print(f" Β β†’ Reward: {result.reward}")
finally:
Β  Β  # Always clean up
Β  Β  lint_coding_agentenv.close()
```
That's it! The `LintCodingAgentEnv.from_docker_image()` method handles:
- Starting the Docker container
- Waiting for the server to be ready
- Connecting to the environment
- Container cleanup when you call `close()`
## Building the Docker Image
Before using the environment, you need to build the Docker image:
```bash
# From project root
docker build -t lint_coding_agent-env:latest -f server/Dockerfile .
```
## Deploying to Hugging Face Spaces
You can easily deploy your OpenEnv environment to Hugging Face Spaces using the `openenv push` command:
```bash
# From the environment directory (where openenv.yaml is located)
openenv push
# Or specify options
openenv push --namespace my-org --private
```
The `openenv push` command will:
1. Validate that the directory is an OpenEnv environment (checks for `openenv.yaml`)
2. Prepare a custom build for Hugging Face Docker space (enables web interface)
3. Upload to Hugging Face (ensuring you're logged in)
### Prerequisites
- Authenticate with Hugging Face: The command will prompt for login if not already authenticated
### Options
- `--directory`, `-d`: Directory containing the OpenEnv environment (defaults to current directory)
- `--repo-id`, `-r`: Repository ID in format 'username/repo-name' (defaults to 'username/env-name' from openenv.yaml)
- `--base-image`, `-b`: Base Docker image to use (overrides Dockerfile FROM)
- `--private`: Deploy the space as private (default: public)
### Examples
```bash
# Push to your personal namespace (defaults to username/env-name from openenv.yaml)
openenv push
# Push to a specific repository
openenv push --repo-id my-org/my-env
# Push with a custom base image
openenv push --base-image ghcr.io/meta-pytorch/openenv-base:latest
# Push as a private space
openenv push --private
# Combine options
openenv push --repo-id my-org/my-env --base-image custom-base:latest --private
```
After deployment, your space will be available at:
`https://huggingface.co/spaces/<repo-id>`
The deployed space includes:
- **Web Interface** at `/web` - Interactive UI for exploring the environment
- **API Documentation** at `/docs` - Full OpenAPI/Swagger interface
- **Health Check** at `/health` - Container health monitoring
- **WebSocket** at `/ws` - Persistent session endpoint for low-latency interactions
## Environment Details
### Action
**LintCodingAgentAction**: Contains a single field
- `message` (str) - The message to echo back
### Observation
**LintCodingAgentObservation**: Contains the echo response and metadata
- `echoed_message` (str) - The message echoed back
- `message_length` (int) - Length of the message
- `reward` (float) - Reward based on message length (length Γ— 0.1)
- `done` (bool) - Always False for echo environment
- `metadata` (dict) - Additional info like step count
### Reward
The reward is calculated as: `message_length Γ— 0.1`
- "Hi" β†’ reward: 0.2
- "Hello, World!" β†’ reward: 1.3
- Empty message β†’ reward: 0.0
## Advanced Usage
### Connecting to an Existing Server
If you already have a Lint Coding Agent environment server running, you can connect directly:
```python
from lint_coding_agent import LintCodingAgentEnv
# Connect to existing server
lint_coding_agentenv = LintCodingAgentEnv(base_url="<ENV_HTTP_URL_HERE>")
# Use as normal
result = lint_coding_agentenv.reset()
result = lint_coding_agentenv.step(LintCodingAgentAction(message="Hello!"))
```
Note: When connecting to an existing server, `lint_coding_agentenv.close()` will NOT stop the server.
### Using the Context Manager
The client supports context manager usage for automatic connection management:
```python
from lint_coding_agent import LintCodingAgentAction, LintCodingAgentEnv
# Connect with context manager (auto-connects and closes)
with LintCodingAgentEnv(base_url="http://localhost:8000") as env:
Β  Β  result = env.reset()
Β  Β  print(f"Reset: {result.observation.echoed_message}")
Β  Β  # Multiple steps with low latency
Β  Β  for msg in ["Hello", "World", "!"]:
Β  Β  Β  Β  result = env.step(LintCodingAgentAction(message=msg))
Β  Β  Β  Β  print(f"Echoed: {result.observation.echoed_message}")
```
The client uses WebSocket connections for:
- **Lower latency**: No HTTP connection overhead per request
- **Persistent session**: Server maintains your environment state
- **Efficient for episodes**: Better for many sequential steps
### Concurrent WebSocket Sessions
The server supports multiple concurrent WebSocket connections. To enable this,
modify `server/app.py` to use factory mode:
```python
# In server/app.py - use factory mode for concurrent sessions
app = create_app(
Β  Β  LintCodingAgentEnvironment, Β # Pass class, not instance
Β  Β  LintCodingAgentAction,
Β  Β  LintCodingAgentObservation,
Β  Β  max_concurrent_envs=4, Β # Allow 4 concurrent sessions
)
```
Then multiple clients can connect simultaneously:
```python
from lint_coding_agent import LintCodingAgentAction, LintCodingAgentEnv
from concurrent.futures import ThreadPoolExecutor
def run_episode(client_id: int):
Β  Β  with LintCodingAgentEnv(base_url="http://localhost:8000") as env:
Β  Β  Β  Β  result = env.reset()
Β  Β  Β  Β  for i in range(10):
Β  Β  Β  Β  Β  Β  result = env.step(LintCodingAgentAction(message=f"Client {client_id}, step {i}"))
Β  Β  Β  Β  return client_id, result.observation.message_length
# Run 4 episodes concurrently
with ThreadPoolExecutor(max_workers=4) as executor:
Β  Β  results = list(executor.map(run_episode, range(4)))
```
## Development & Testing
### Direct Environment Testing
Test the environment logic directly without starting the HTTP server:
```bash
# From the server directory
python3 server/lint_coding_agent_environment.py
```
This verifies that:
- Environment resets correctly
- Step executes actions properly
- State tracking works
- Rewards are calculated correctly
### Running Locally
Run the server locally for development:
```bash
uvicorn server.app:app --reload
```
## Project Structure
```
lint_coding_agent/
β”œβ”€β”€ .github/ # GitHub Actions (CI/CD for testing)
β”‚ └── workflows/
β”‚ └── test.yml
β”œβ”€β”€ .dockerignore # Keep build context small
β”œβ”€β”€ .gitignore # Ignore __pycache__, .venv, etc.
β”œβ”€β”€ README.md # Enhanced with the code I gave you
β”œβ”€β”€ openenv.yaml # OpenEnv configuration
β”œβ”€β”€ pyproject.toml # Modern build system (replacing setup.py)
β”œβ”€β”€ uv.lock # Fast dependency locking
β”œβ”€β”€ src/ # Source code directory
β”‚ └── lint_coding_agent/ # The actual package
β”‚ β”œβ”€β”€ __init__.py # Expose main classes here
β”‚ β”œβ”€β”€ client.py # User-facing client
β”‚ β”œβ”€β”€ models.py # Pydantic/Data schemas
β”‚ └── server/ # Server-side logic
β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ app.py # FastAPI/WS entry point
β”‚ β”œβ”€β”€ core.py # renamed from lint_coding_agent_environment.py
β”‚ └── templates/ # Your 15-level folders should live here
β”‚ β”œβ”€β”€ level_1/
β”‚ └── ...
β”œβ”€β”€ tests/ # Dedicated test suite
β”‚ β”œβ”€β”€ __init__.py
β”‚ β”œβ”€β”€ test_client.py
β”‚ └── test_env_logic.py
└── Dockerfile # Multi-stage build for production
```