Spaces:
Paused
Paused
File size: 2,610 Bytes
8697ae6 | 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 | """CLI entry point for running the sample HR agent."""
from __future__ import annotations
import argparse
import json
import logging
import sys
from agent.hr_agent import HRAgent
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(name)s %(levelname)s %(message)s")
logger = logging.getLogger(__name__)
def run_episode(url: str, model: str = "claude-sonnet-4-6", seed: int = 42) -> float:
"""Run a complete episode against the HR environment server.
Args:
url: WebSocket URL of the environment server.
model: Claude model to use.
seed: Random seed for the environment.
Returns:
Final episode score.
"""
from hr_env.client import HRProductivityEnv
from hr_env.models import HRAction
agent = HRAgent(model=model)
with HRProductivityEnv(base_url=url) as env:
result = env.reset(seed=seed)
obs = result.observation
logger.info(f"Episode started: {obs.message}")
step = 0
while not obs.done:
# Convert observation to dict for the agent
obs_dict = obs.model_dump()
# Get agent's action
action_dict = agent.decide(obs_dict)
logger.info(
f"Step {step} | Q{obs.current_quarter} {obs.current_phase} | "
f"Action: {action_dict.get('action_type')} | "
f"Rationale: {action_dict.get('rationale', 'N/A')}"
)
# Build and execute action
action = HRAction(**action_dict)
result = env.step(action)
obs = result.observation
if result.reward is not None:
logger.info(f" Reward: {result.reward}")
step += 1
logger.info(f"Episode complete after {step} steps. Final score: {result.reward}")
return result.reward or 0.0
def main() -> None:
parser = argparse.ArgumentParser(description="Run the sample HR agent")
parser.add_argument("--url", default="ws://localhost:8000", help="Environment server WebSocket URL")
parser.add_argument("--model", default="claude-sonnet-4-6", help="Claude model to use")
parser.add_argument("--seed", type=int, default=42, help="Environment random seed")
args = parser.parse_args()
try:
score = run_episode(args.url, args.model, args.seed)
print(f"\nFinal Score: {score:.4f}")
except KeyboardInterrupt:
print("\nInterrupted.")
sys.exit(1)
except Exception as e:
logger.error(f"Episode failed: {e}", exc_info=True)
sys.exit(1)
if __name__ == "__main__":
main()
|