Team Ai
Apppublic

openenv/echo_env

sourceHugging Faceupdated 1d agoView on Hugging Face
6likes
app.py73 linesDownload Raw Back to server
1# Copyright (c) Meta Platforms, Inc. and affiliates.2# All rights reserved.3#4# This source code is licensed under the BSD-style license found in the5# LICENSE file in the root directory of this source tree.6 7"""8FastAPI application for the Echo Environment.9 10This module creates an HTTP server that exposes the EchoEnvironment11over HTTP and WebSocket endpoints, compatible with MCPToolClient.12 13Usage:14    # Development (with auto-reload):15    uvicorn server.app:app --reload --host 0.0.0.0 --port 800016 17    # Production:18    uvicorn server.app:app --host 0.0.0.0 --port 8000 --workers 419 20    # Or run directly:21    uv run --project . server22"""23 24import os25 26from openenv.core.env_server.types import Observation27 28# Support both in-repo and standalone imports29try:30    # In-repo imports (when running from OpenEnv repository)31    from openenv.core.env_server.http_server import create_app32    from openenv.core.env_server.mcp_types import CallToolAction, CallToolObservation33 34    from .echo_environment import EchoEnvironment35except ImportError:36    # Standalone imports (when environment is standalone with openenv from pip)37    from openenv.core.env_server.http_server import create_app38    from openenv.core.env_server.mcp_types import CallToolAction, CallToolObservation39    from server.echo_environment import EchoEnvironment40 41# Create the app with web interface and README integration42# Pass the class (factory) instead of an instance for WebSocket session support43# Use MCP types for action/observation since this is a pure MCP environment44max_concurrent = int(os.getenv("MAX_CONCURRENT_ENVS", "8"))45 46app = create_app(47    EchoEnvironment,48    CallToolAction,49    CallToolObservation,50    reset_observation_cls=Observation,51    env_name="echo_env",52    max_concurrent_envs=max_concurrent,53)54 55 56def main():57    """58    Entry point for direct execution via uv run or python -m.59 60    This function enables running the server without Docker:61        uv run --project . server62        python -m envs.echo_env.server.app63        openenv serve echo_env64 65    """66    import uvicorn67 68    uvicorn.run(app, host="0.0.0.0", port=8000)69 70 71if __name__ == "__main__":72    main()73