Context for AI agents and human contributors working in (maintaining/extending) or with (consuming/implementing services for) the PyAres library.
PyAres is the official Python SDK and gRPC service framework for the ARES
self-driving laboratory ecosystem. It bridges native Python
code with the centralized ARES OS 2 orchestrator using
Protocol Buffers and gRPC via ares-datamodel.
Official documentation for all aspects of the ARES ecosystem is located on the Docs Page.
PyAres abstracts away raw Protobuf messages and gRPC boilerplate, exposing clean, idiomatic Python interfaces to implement four core service archetypes:
- Device Services (
AresDeviceService) — Control laboratory hardware, actuators, and sensors; expose executable commands, schemas, and live telemetry; implement safety interlocks and safe-mode procedures. - Planning Services (
AresPlannerService) — Drive experimental campaigns using optimization algorithms, active learning, Bayesian optimization, heuristic search, etc. to suggest the next parameter values to evaluate. - Analysis Services (
AresAnalyzerService) — Extract quantitative objectives and metrics from raw experimental outputs, passing structured results to planners and ARES OS. - Visualizer Services (
AresVisualizerService) — Render charts and dashboard widgets (e.g., Plotly figures) for display in the ARES OS web interface.
- Consult TOML for Dependencies and Build Info The
pyproject.tomlfile in the repository root file serves as the single source of truth for dependencies and build information. - Dynamic Versioning: The
hatchlingbuild back ends reads the package version dynamically from thePYARES_PACKAGE_VERSIONenvironment variable (required duringbuildorpip install -e .):export PYARES_PACKAGE_VERSION="0.0.1" # or matching release tag
# Clone and enter repo
cd PyAres
# Set version for hatchling
export PYARES_PACKAGE_VERSION="0.0.1"
# Install in editable mode with test dependencies
pip install -e .
pip install grpcio grpcio-tools protobuf pytest
# Run full test suite
pytest -v tests/PyAres/
├── pyproject.toml # Hatchling build specification & dependencies
├── README.md # Upstream package summary & centralized docs link
├── AGENTS.md # This File
├── LICENSE # MIT License
├── .github/workflows/ # CI/CD: unit tests (ubuntu, py3.10) & PyPI publishing
├── tests/ # Unit tests & MockGrpcContext
└── PyAres/ # Root package directory
├── __init__.py # Public top-level API exports
├── Device/ # Hardware control service framework
│ ├── device_service.py # AresDeviceService & AresDeviceServiceWrapper (gRPC servicer)
│ ├── device_models.py # DeviceCommandDescriptor, DeviceCommandResponse, StatusCode, etc.
│ └── device_warnings.py # Warning categories for device services
├── Planning/ # Campaign & experiment planning framework
│ ├── planning_service.py # AresPlannerService & AresPlannerServiceWrapper (gRPC servicer)
│ └── planner_models.py # PlanRequest, PlanResponse, PlanningParameter, Plan, etc.
├── Analyzing/ # Experiment evaluation & objective calculation framework
│ ├── analysis_service.py # AresAnalyzerService & AresAnalyzerServiceWrapper (gRPC servicer)
│ └── analyzer_models.py # AnalysisRequest, AnalysisResponse, Objective, ObjectiveSchema
├── Visualizers/ # UI Visualization rendering framework
│ ├── visualizer_service.py # AresVisualizerService & AresVisualizerServiceWrapper
│ └── visualizing_models.py # VisualizationOption, VisualizationRequest, DataPoint
├── Models/ # Shared data models & enums
│ └── ares_data_models.py # AresDataType, Outcome, PlanStatusCode, RequestMetadata, Limits
├── Utils/ # Protobuf ↔ Python conversion utilities & base infrastructure
│ ├── grpc_base.py # AresGrpcServiceBase: server lifecycle, thread pool, message size
│ ├── ares_service_base.py # AresBaseService & AresServiceWrapperBase: common RPCs & async resolver
│ ├── metadata_interceptors.py # DatamodelVersionServerInterceptor: handshake version header
│ ├── ares_value_utils.py # Primitive/AresValue protobuf bi-directional conversion
│ ├── ares_struct_utils.py # Dict/AresStruct conversion helpers
│ ├── ares_data_schema_utils.py # Schema builder helpers for inputs, settings, and outputs
│ ├── ares_data_type_utils.py # AresDataType enum translation
│ ├── device_status_code_utils.py # Status code mapping & success evaluation
│ ├── ares_outcome_utils.py # Outcome enum translation
│ ├── plan_request_utils.py # Protobuf PlanRequest unpacking
│ └── plan_response_utils.py # Protobuf PlanResponse packaging
├── test_tools/ # Standalone test clients
│ ├── analyzer_tester.py # AnalyzerTestClient: test Analyzer services without ARES OS
│ └── planner_tester.py # PlannerTestClient: test Planner services without ARES OS
└── Demo/ # Working reference implementations
├── BEST_PRACTICES.md # Best Practcies for PyAres Service Implementations
├── Devices/ # Example devices (hotplate, rotary mixer, random generator, etc.)
├── Planners/ # Example planners (grid, random, test-tools integration)
└── Analyzers/ # Example analyzers (basic, Ax analyzer, test-tools integration)
Every service in PyAres (Device, Planning, Analyzing, Visualizer) is split into two components:
- The User-Facing Service (
AresBaseServicesubclass):- Manages the gRPC server lifecycle (
start(),stop()). - Configures networking (
port,use_localhost,max_message_size). - Manages service settings and capability schema declarations.
- Manages the gRPC server lifecycle (
- The Internal gRPC Servicer Wrapper (
AresServiceWrapperBasesubclass):- Implements generated gRPC Servicer stubs from
ares-datamodel. - Exposes standard diagnostic RPCs:
GetInfo,GetConnectionStatus,GetState. - Intercepts requests, translates protobuf messages to native Python data structures, executes registered callbacks, and packs Python returns back into protobuf responses.
- Implements generated gRPC Servicer stubs from
All services run with DatamodelVersionServerInterceptor (PyAres/Utils/metadata_interceptors.py).
Every RPC attaches the datamodel-version header corresponding to the installed ares_datamodel
version. This ensures ARES OS and external orchestrators can verify protocol compatibility.
User-supplied logic (e.g., enter_safe_mode, plan_logic, custom_analysis_logic, commands)
can be written as standard synchronous functions or async coroutines. The wrapper automatically
resolves awaitables via _resolve_awaitable() (PyAres/Utils/ares_service_base.py).
- Device Service:
7100(configurable viaport) - Planner Service:
7082(configurable viaport) - Analyzer Service:
7083(configurable viaport)
- Examples and guidelines for implementation best bractices are located in
PyAres/Demos/.
- PyAres depends strictly on
ares-datamodel. Never import raw gRPC files from custom paths; always import fromares_datamodel.... - If a Protobuf schema in
ares-datamodelchanges, update the translation layers inPyAres/Utils/(ares_value_utils.py,ares_struct_utils.py,ares_data_schema_utils.py, etc.) and ensure both forward and backwards compatibility.
- Many existing laboratory devices run older PyAres conventions.
- When introducing a new model or schema structure, provide an adapter or backwards compatibility fallback (e.g., how
ExecuteCommandstill accepts legacy raw dict returns and emits aFutureWarning, or howAnalysisResponsehandles legacyresult). - Use Python's
warnings.warnwithFutureWarningorDeprecationWarningrather than throwing errors on older API patterns.
AresGrpcServiceBasedefaultsuse_localhost=True, binding tolocalhost:{port}.- Setting
use_localhost=Falsebinds to[::]:{port}(IPv6 wildcard, allowing LAN access from other host machines). - Never hardcode IP addresses or assume external network access.
- Place unit tests under
tests/. - Name test files
test_*.py. - Use
unittest.TestCaseorpytest. - Use
MockGrpcContext(fromtests/mock_grpc_context.pyor inline) to test gRPC servicer logic without needing live socket bindings. - When spinning up a real service in a test, always ensure
service.stop()is invoked intearDown()to release the port.
- License: MIT License (see
LICENSE). - Clearance: AFRL Clearance: Distribution A. Approved for public release: distribution unlimited. AFRL-2025-5332.
- Keep all first-party code MIT licensed. Do not vendor or introduce copyleft/GPL code into PyAres.