Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- evaluate_protocal.py +31 -15
- frontend/index.html +3 -3
- openenv_agent_language.egg-info/PKG-INFO +1 -0
- openenv_agent_language.egg-info/SOURCES.txt +2 -2
- openenv_agent_language.egg-info/requires.txt +1 -0
- pyproject.toml +1 -0
- sample_conversation.json +39 -0
- server/.env +1 -0
- server/agent_language_environment.py +3 -4
- server/app.py +6 -1
- uv.lock +2 -0
evaluate_protocal.py
CHANGED
|
@@ -3,6 +3,7 @@ import os
|
|
| 3 |
import random
|
| 4 |
import re
|
| 5 |
import sys
|
|
|
|
| 6 |
from dataclasses import dataclass, field
|
| 7 |
from datetime import datetime, timezone
|
| 8 |
from pathlib import Path
|
|
@@ -395,21 +396,29 @@ def run_experiment(
|
|
| 395 |
lang_spec: str,
|
| 396 |
n: int,
|
| 397 |
experiment_id: str | None = None,
|
|
|
|
| 398 |
) -> dict:
|
| 399 |
exp_id = experiment_id or "unnamed"
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
|
| 414 |
experiment = {
|
| 415 |
"experiment_id": exp_id,
|
|
@@ -497,8 +506,15 @@ def evaluate_lang_spec(lang_spec: str, n: int = 5) -> float:
|
|
| 497 |
api_key=os.environ["OPENROUTER_API_KEY"],
|
| 498 |
)
|
| 499 |
model = "google/gemini-3-flash-preview"
|
| 500 |
-
|
| 501 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 502 |
return sum(t["combined_completion_tokens"] for t in trials) / len(trials)
|
| 503 |
|
| 504 |
|
|
|
|
| 3 |
import random
|
| 4 |
import re
|
| 5 |
import sys
|
| 6 |
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 7 |
from dataclasses import dataclass, field
|
| 8 |
from datetime import datetime, timezone
|
| 9 |
from pathlib import Path
|
|
|
|
| 396 |
lang_spec: str,
|
| 397 |
n: int,
|
| 398 |
experiment_id: str | None = None,
|
| 399 |
+
max_workers: int = 8,
|
| 400 |
) -> dict:
|
| 401 |
exp_id = experiment_id or "unnamed"
|
| 402 |
+
trials = [None] * n
|
| 403 |
+
|
| 404 |
+
def _run(i: int) -> tuple[int, dict]:
|
| 405 |
+
rng = random.Random()
|
| 406 |
+
return i, run_trial(client, model, lang_spec, rng)
|
| 407 |
+
|
| 408 |
+
completed = 0
|
| 409 |
+
with ThreadPoolExecutor(max_workers=max_workers) as executor:
|
| 410 |
+
futures = {executor.submit(_run, i): i for i in range(n)}
|
| 411 |
+
for future in as_completed(futures):
|
| 412 |
+
i, trial = future.result()
|
| 413 |
+
trials[i] = trial
|
| 414 |
+
completed += 1
|
| 415 |
+
status = "CORRECT" if trial["correct"] else "INCORRECT"
|
| 416 |
+
print(
|
| 417 |
+
f"[{completed}/{n}] {status} | "
|
| 418 |
+
f"chars={trial['combined_chars']} | "
|
| 419 |
+
f"tokens={trial['combined_completion_tokens']} | "
|
| 420 |
+
f"turns={trial['total_turns']}"
|
| 421 |
+
)
|
| 422 |
|
| 423 |
experiment = {
|
| 424 |
"experiment_id": exp_id,
|
|
|
|
| 506 |
api_key=os.environ["OPENROUTER_API_KEY"],
|
| 507 |
)
|
| 508 |
model = "google/gemini-3-flash-preview"
|
| 509 |
+
|
| 510 |
+
def _run(_: int) -> dict:
|
| 511 |
+
return run_trial(client, model, lang_spec, random.Random())
|
| 512 |
+
|
| 513 |
+
with ThreadPoolExecutor(max_workers=n) as executor:
|
| 514 |
+
trials = list(executor.map(_run, range(n)))
|
| 515 |
+
|
| 516 |
+
Path("sample_conversation.json").write_text(json.dumps(trials[0], indent=2) + "\n")
|
| 517 |
+
|
| 518 |
return sum(t["combined_completion_tokens"] for t in trials) / len(trials)
|
| 519 |
|
| 520 |
|
frontend/index.html
CHANGED
|
@@ -325,7 +325,7 @@
|
|
| 325 |
const res = await fetch(`${BASE_URL}/step`, {
|
| 326 |
method: 'POST',
|
| 327 |
headers: { 'Content-Type': 'application/json' },
|
| 328 |
-
body: JSON.stringify({ language_specification: message }),
|
| 329 |
});
|
| 330 |
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
| 331 |
const data = await res.json();
|
|
@@ -333,9 +333,9 @@
|
|
| 333 |
updateObsDisplay(obs);
|
| 334 |
if (data.state) {
|
| 335 |
updateStateDisplay({ ...data.state, status: 'Running' });
|
| 336 |
-
addToHistory(data.state.step_count, message,
|
| 337 |
} else {
|
| 338 |
-
addToHistory(actionHistory.length + 1, message,
|
| 339 |
}
|
| 340 |
document.getElementById('messageInput').value = '';
|
| 341 |
} catch (e) {
|
|
|
|
| 325 |
const res = await fetch(`${BASE_URL}/step`, {
|
| 326 |
method: 'POST',
|
| 327 |
headers: { 'Content-Type': 'application/json' },
|
| 328 |
+
body: JSON.stringify({ action: { language_specification: message } }),
|
| 329 |
});
|
| 330 |
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
| 331 |
const data = await res.json();
|
|
|
|
| 333 |
updateObsDisplay(obs);
|
| 334 |
if (data.state) {
|
| 335 |
updateStateDisplay({ ...data.state, status: 'Running' });
|
| 336 |
+
addToHistory(data.state.step_count, message, data.reward ?? 0);
|
| 337 |
} else {
|
| 338 |
+
addToHistory(actionHistory.length + 1, message, data.reward ?? 0);
|
| 339 |
}
|
| 340 |
document.getElementById('messageInput').value = '';
|
| 341 |
} catch (e) {
|
openenv_agent_language.egg-info/PKG-INFO
CHANGED
|
@@ -5,6 +5,7 @@ Summary: Agent Language environment for OpenEnv
|
|
| 5 |
Requires-Python: >=3.10
|
| 6 |
Requires-Dist: openai>=2.26.0
|
| 7 |
Requires-Dist: openenv-core[core]>=0.2.0
|
|
|
|
| 8 |
Provides-Extra: dev
|
| 9 |
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
| 10 |
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
|
|
| 5 |
Requires-Python: >=3.10
|
| 6 |
Requires-Dist: openai>=2.26.0
|
| 7 |
Requires-Dist: openenv-core[core]>=0.2.0
|
| 8 |
+
Requires-Dist: python-dotenv>=1.2.2
|
| 9 |
Provides-Extra: dev
|
| 10 |
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
| 11 |
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
openenv_agent_language.egg-info/SOURCES.txt
CHANGED
|
@@ -5,6 +5,7 @@ models.py
|
|
| 5 |
pyproject.toml
|
| 6 |
./__init__.py
|
| 7 |
./client.py
|
|
|
|
| 8 |
./models.py
|
| 9 |
openenv_agent_language.egg-info/PKG-INFO
|
| 10 |
openenv_agent_language.egg-info/SOURCES.txt
|
|
@@ -14,5 +15,4 @@ openenv_agent_language.egg-info/requires.txt
|
|
| 14 |
openenv_agent_language.egg-info/top_level.txt
|
| 15 |
server/__init__.py
|
| 16 |
server/agent_language_environment.py
|
| 17 |
-
server/app.py
|
| 18 |
-
server/evaluate_protocal.py
|
|
|
|
| 5 |
pyproject.toml
|
| 6 |
./__init__.py
|
| 7 |
./client.py
|
| 8 |
+
./evaluate_protocal.py
|
| 9 |
./models.py
|
| 10 |
openenv_agent_language.egg-info/PKG-INFO
|
| 11 |
openenv_agent_language.egg-info/SOURCES.txt
|
|
|
|
| 15 |
openenv_agent_language.egg-info/top_level.txt
|
| 16 |
server/__init__.py
|
| 17 |
server/agent_language_environment.py
|
| 18 |
+
server/app.py
|
|
|
openenv_agent_language.egg-info/requires.txt
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
openai>=2.26.0
|
| 2 |
openenv-core[core]>=0.2.0
|
|
|
|
| 3 |
|
| 4 |
[dev]
|
| 5 |
pytest>=8.0.0
|
|
|
|
| 1 |
openai>=2.26.0
|
| 2 |
openenv-core[core]>=0.2.0
|
| 3 |
+
python-dotenv>=1.2.2
|
| 4 |
|
| 5 |
[dev]
|
| 6 |
pytest>=8.0.0
|
pyproject.toml
CHANGED
|
@@ -27,6 +27,7 @@ dependencies = [
|
|
| 27 |
# "gymnasium>=0.29.0",
|
| 28 |
# "openspiel>=1.0.0",
|
| 29 |
# "smolagents>=1.22.0,<2",
|
|
|
|
| 30 |
]
|
| 31 |
|
| 32 |
[project.optional-dependencies]
|
|
|
|
| 27 |
# "gymnasium>=0.29.0",
|
| 28 |
# "openspiel>=1.0.0",
|
| 29 |
# "smolagents>=1.22.0,<2",
|
| 30 |
+
"python-dotenv>=1.2.2",
|
| 31 |
]
|
| 32 |
|
| 33 |
[project.optional-dependencies]
|
sample_conversation.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"correct": false,
|
| 3 |
+
"errors": [
|
| 4 |
+
"Agent said NO_VALID_TIME but valid meetings exist"
|
| 5 |
+
],
|
| 6 |
+
"num_overlaps": 1,
|
| 7 |
+
"valid_meetings": [
|
| 8 |
+
{
|
| 9 |
+
"day": "Th",
|
| 10 |
+
"location": "NYC",
|
| 11 |
+
"start": 11.0,
|
| 12 |
+
"end": 15.0
|
| 13 |
+
}
|
| 14 |
+
],
|
| 15 |
+
"schedules": {
|
| 16 |
+
"T": "Monday in SF, 10-16; Thursday in NYC, 11-15",
|
| 17 |
+
"J": "Monday in NYC, 16-18; Tuesday in SF, 10-16; Wednesday in SF, 12-17; Thursday in NYC, 10-18; Friday in SF, 16-18"
|
| 18 |
+
},
|
| 19 |
+
"combined_completion_tokens": 34,
|
| 20 |
+
"combined_chars": 132,
|
| 21 |
+
"total_turns": 1,
|
| 22 |
+
"agents": {
|
| 23 |
+
"T": {
|
| 24 |
+
"turns": 1,
|
| 25 |
+
"completion_tokens": 34
|
| 26 |
+
},
|
| 27 |
+
"J": {
|
| 28 |
+
"turns": 0,
|
| 29 |
+
"completion_tokens": 0
|
| 30 |
+
}
|
| 31 |
+
},
|
| 32 |
+
"meeting": null,
|
| 33 |
+
"conversation": [
|
| 34 |
+
{
|
| 35 |
+
"agent": "T",
|
| 36 |
+
"content": "Please provide the details (M?, T:, J:) for the meeting request so I can evaluate the slots. Otherwise:\n\nNO_VALID_TIME\nTASK_COMPLETE"
|
| 37 |
+
}
|
| 38 |
+
]
|
| 39 |
+
}
|
server/.env
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
OPENROUTER_API_KEY=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
|
server/agent_language_environment.py
CHANGED
|
@@ -46,13 +46,12 @@ class AgentLanguageEnvironment(Environment):
|
|
| 46 |
# getting their own environment instance (when using factory mode in app.py).
|
| 47 |
SUPPORTS_CONCURRENT_SESSIONS: bool = True
|
| 48 |
|
| 49 |
-
def __init__(self
|
| 50 |
"""Initialize the agent_language environment."""
|
| 51 |
self._state = AgentLanguageState(episode_id=str(uuid4()), step_count=0)
|
| 52 |
self._reset_count = 0
|
| 53 |
-
self.seed = seed
|
| 54 |
|
| 55 |
-
def reset(self
|
| 56 |
"""
|
| 57 |
Reset the environment.
|
| 58 |
|
|
@@ -83,7 +82,7 @@ class AgentLanguageEnvironment(Environment):
|
|
| 83 |
"""
|
| 84 |
self._state.step_count += 1
|
| 85 |
language_specification = action.language_specification
|
| 86 |
-
reward = evaluate_lang_spec(language_specification)
|
| 87 |
return AgentLanguageObservation(
|
| 88 |
message="Do not call any more function.",
|
| 89 |
done=True,
|
|
|
|
| 46 |
# getting their own environment instance (when using factory mode in app.py).
|
| 47 |
SUPPORTS_CONCURRENT_SESSIONS: bool = True
|
| 48 |
|
| 49 |
+
def __init__(self):
|
| 50 |
"""Initialize the agent_language environment."""
|
| 51 |
self._state = AgentLanguageState(episode_id=str(uuid4()), step_count=0)
|
| 52 |
self._reset_count = 0
|
|
|
|
| 53 |
|
| 54 |
+
def reset(self) -> AgentLanguageObservation:
|
| 55 |
"""
|
| 56 |
Reset the environment.
|
| 57 |
|
|
|
|
| 82 |
"""
|
| 83 |
self._state.step_count += 1
|
| 84 |
language_specification = action.language_specification
|
| 85 |
+
reward = -evaluate_lang_spec(language_specification)
|
| 86 |
return AgentLanguageObservation(
|
| 87 |
message="Do not call any more function.",
|
| 88 |
done=True,
|
server/app.py
CHANGED
|
@@ -35,12 +35,17 @@ except Exception as e: # pragma: no cover
|
|
| 35 |
"openenv is required for the web interface. Install dependencies with '\n uv sync\n'"
|
| 36 |
) from e
|
| 37 |
|
|
|
|
|
|
|
|
|
|
| 38 |
from fastapi.middleware.cors import CORSMiddleware
|
| 39 |
|
|
|
|
|
|
|
| 40 |
# Import from local models.py (PYTHONPATH includes /app/env in Docker)
|
| 41 |
from models import AgentLanguageAction, AgentLanguageObservation
|
| 42 |
-
from .agent_language_environment import AgentLanguageEnvironment
|
| 43 |
|
|
|
|
| 44 |
|
| 45 |
# Create the app with web interface and README integration
|
| 46 |
app = create_app(
|
|
|
|
| 35 |
"openenv is required for the web interface. Install dependencies with '\n uv sync\n'"
|
| 36 |
) from e
|
| 37 |
|
| 38 |
+
import os
|
| 39 |
+
|
| 40 |
+
import dotenv
|
| 41 |
from fastapi.middleware.cors import CORSMiddleware
|
| 42 |
|
| 43 |
+
dotenv.load_dotenv()
|
| 44 |
+
|
| 45 |
# Import from local models.py (PYTHONPATH includes /app/env in Docker)
|
| 46 |
from models import AgentLanguageAction, AgentLanguageObservation
|
|
|
|
| 47 |
|
| 48 |
+
from .agent_language_environment import AgentLanguageEnvironment
|
| 49 |
|
| 50 |
# Create the app with web interface and README integration
|
| 51 |
app = create_app(
|
uv.lock
CHANGED
|
@@ -1077,6 +1077,7 @@ source = { editable = "." }
|
|
| 1077 |
dependencies = [
|
| 1078 |
{ name = "openai" },
|
| 1079 |
{ name = "openenv-core", extra = ["core"] },
|
|
|
|
| 1080 |
]
|
| 1081 |
|
| 1082 |
[package.optional-dependencies]
|
|
@@ -1091,6 +1092,7 @@ requires-dist = [
|
|
| 1091 |
{ name = "openenv-core", extras = ["core"], specifier = ">=0.2.0" },
|
| 1092 |
{ name = "pytest", marker = "extra == 'dev'", specifier = ">=8.0.0" },
|
| 1093 |
{ name = "pytest-cov", marker = "extra == 'dev'", specifier = ">=4.0.0" },
|
|
|
|
| 1094 |
]
|
| 1095 |
provides-extras = ["dev"]
|
| 1096 |
|
|
|
|
| 1077 |
dependencies = [
|
| 1078 |
{ name = "openai" },
|
| 1079 |
{ name = "openenv-core", extra = ["core"] },
|
| 1080 |
+
{ name = "python-dotenv" },
|
| 1081 |
]
|
| 1082 |
|
| 1083 |
[package.optional-dependencies]
|
|
|
|
| 1092 |
{ name = "openenv-core", extras = ["core"], specifier = ">=0.2.0" },
|
| 1093 |
{ name = "pytest", marker = "extra == 'dev'", specifier = ">=8.0.0" },
|
| 1094 |
{ name = "pytest-cov", marker = "extra == 'dev'", specifier = ">=4.0.0" },
|
| 1095 |
+
{ name = "python-dotenv", specifier = ">=1.2.2" },
|
| 1096 |
]
|
| 1097 |
provides-extras = ["dev"]
|
| 1098 |
|