// Copyright 2020 Artificial Intelligence Redefined <dev+cogment@ai-r.com>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

syntax = "proto3";

package cogment;

import "cogment/api/common.proto";

// This is the connection between a model application and the orchestrator.
// The service is hosted on the model.
// Expected metadata for all calls except `Version`:
//   - trial-id: The id of the trial
//   - actor-name: The name of the actor within the trial
service AgentEndpoint {

  rpc OnStart(AgentStartRequest) returns (AgentStartReply) {}

  rpc OnObservation(stream AgentObservationRequest) returns (stream AgentActionReply) {}
  rpc OnReward(AgentRewardRequest) returns (AgentRewardReply) {}
  rpc OnMessage(AgentMessageRequest) returns (AgentMessageReply) {}

  rpc OnEnd(AgentEndRequest) returns (AgentEndReply) {}

  rpc Version(VersionRequest) returns (VersionInfo) {}
}


// Requests that a single agent be created.
message AgentStartRequest {
  // Name of the actor implementation to use.
  // This can be useful if there are multiple actor implementations
  // being served from the same service.
  string impl_name = 1;

  // Project-specific actor configuration. The content has to match the
  // actor's class config_type.
  ActorConfig config = 2;

  // Actors present in the trial (inclusive of the new actor).
  repeated TrialActor actors_in_trial = 3;
}

message AgentStartReply {}

message AgentObservationRequest {
  Observation observation = 1;
}

message AgentActionReply {
  Action action = 1;
  repeated Reward rewards = 2;
  repeated Message messages = 3;
}

message AgentRewardRequest {
  Reward reward = 1;
}

message AgentRewardReply {}

message AgentMessageRequest {
  repeated Message messages = 1;
}

message AgentMessageReply {};

message AgentEndRequest {
  ActorPeriodData final_data = 1;
}

message AgentEndReply {}
