File size: 3,331 Bytes
d66c84d
f527210
 
 
d66c84d
 
 
f527210
 
 
 
d66c84d
 
f527210
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
---
title: Agterm Environment Server
emoji: 🎼
colorFrom: purple
colorTo: blue
sdk: docker
pinned: false
app_port: 8000
base_path: /web
tags:
  - openenv
---

# Agterm Environment

Lightweight echo environment for testing OpenEnv-compatible clients and APIs.

This repository provides:

- A small FastAPI server that executes any command in a bash shell.
- A minimal Python client to connect to a running environment.
- A Dockerfile for building a containerized environment useful for CI or deployment.

## Quick Start β€” Python client

Install the project dependencies (see `pyproject.toml`) and use the client:

```python
from openenv_agterm import agtermAction, agtermEnv

env = agtermEnv.from_docker_image("openenv_agterm-env:latest")
try:
    res = env.reset()
    print("Reset echoed:", res.observation.echoed_message)

    r = env.step(AgtermAction(message="echo 'Hello World'"))
    print("Echo:", r.observation.result)
    print("Reward:", r.reward)
finally:
    env.close()
```

Notes:

- `from_docker_image()` starts the container, waits for readiness, and connects the client.
- If you connect with `AgtermEnv(base_url=...)`, `close()` will not stop the external server.

## Build & Run

Build the Docker image from the repository root:

```bash
docker build -t agterm-env:latest -f server/Dockerfile .
```

Run the server locally (development):

```bash
# from repository root
uvicorn server.app:app --reload
```

Or run the built image:

```bash
docker run --rm -p 8000:8000 agterm-env:latest
```

API surface (when server running):

- `GET /health` β€” health check
- `GET /docs` β€” OpenAPI/Swagger UI
- `GET /web` β€” web UI (if included in the image)

## Environment API & Models

Action (`AgtermAction`):

- `message` (str): text to echo back.

Observation (`AgtermObservation`):

- `result` (str): result of the command
- `reward` (float): computed reward
- `done` (bool): True if error
- `metadata` (dict): extra info (e.g., step count)

Reward formula:

- Successful result = 1.0
- Failed result = -1.0

## Development & Tests

Run the environment module directly for quick checks:

```bash
python3 server/agterm_environment.py
```

Run the FastAPI app locally:

```bash
uvicorn server.app:app --reload
```

## Project layout

- [client.py](client.py) β€” Python client implementation and helpers
- [models.py](models.py) β€” pydantic models for actions and observations
- [server/app.py](server/app.py) β€” FastAPI application entry
- [server/agterm_environment.py](server/AGTerm_environment.py) β€” core environment logic (scriptable)
- [server/Dockerfile](server/Dockerfile) β€” image definition used to build `agterm-env`
- [openenv.yaml](openenv.yaml) β€” OpenEnv manifest
- [pyproject.toml](pyproject.toml) β€” project metadata and dependencies

## Deployment

You can push this environment to Hugging Face Spaces or similar container hosts. If using `openenv` tooling, run `openenv push` from the environment directory (where `openenv.yaml` is located) and follow its prompts.

## Next steps

- Verify the server locally with `uvicorn` and exercise the client in a small script.
- Build the Docker image and test containerized runs.
- (Optional) Deploy to a Spaces/Cloud environment for public testing.

---

See [client.py](client.py) and [server/app.py](server/app.py) for implementation details.