agent_run
- class agentos.agent_run.AgentRun(run_type: str, parent_run: Optional[str] = None, agent_name: Optional[str] = None, environment_name: Optional[str] = None)
An AgentRun provides an API that agents can use to log agent related data/stats/tags/etc. AgentRun can be one of two flavors (which we call
run_type
), ‘evaluate’ and ‘learn’.The AgentRun can contain tags that reference other AgentRuns for tracking the training history of an agent.
An
AgentRun
inherits fromRun
, and adds functionality specific to runs of agents, such as runs that evaluate the agent’s performance in an environment, or runs that cause the agent to learn in an environment.Like a
Run
, anAgentRun
can be used as a context manager, so that the developer doesn’t need to remember to mark a run as finished, for example:with AgentRun('evaluate', parent_run=self.__component__.active_run) as run: # run an episode run.log_episode( # episode_data ... )
- AGENT_NAME_KEY = 'agent_name'
- ENV_NAME_KEY = 'environment_name'
- EVALUATE_KEY = 'evaluate'
- IS_AGENT_RUN_TAG = 'pcs.is_agent_run'
- LEARN_KEY = 'learn'
- RESET_KEY = 'reset'
- RESTORE_KEY = 'restore'
- RUN_TYPE_TAG = 'run_type'
- __init__(run_type: str, parent_run: Optional[str] = None, agent_name: Optional[str] = None, environment_name: Optional[str] = None) None
Create a new AgentRun.
- Parameters
run_type – must be ‘evaluate’ or ‘learn’
parent_run – Optionally, specify the identifier of another Run that this run is a sub-run of. Setting this will result in this AgentRun being visually nested under the parent_run in the MLflow UI.
agent_name – The name of the agent component being evaluated or trained. Defaults to “agent”.
environment_name – The name of the environment component being evaluated or trained. Defaults to “environment”.
- add_episode_data(steps: int, reward: float)
- end(status: str = 'FINISHED', print_results: bool = True) None
This is copied and adapted from MLflow’s fluent api mlflow.end_run
- get_training_info() -> (<class 'int'>, <class 'int'>)
- log_agent_name(agent_name: str) None
- log_environment_name(environment_name: str) None
- log_run_metrics()
- log_run_type(run_type: str) None
- print_results()
- class agentos.agent_run.RunStats(episode_count, step_count, max_reward, median_reward, mean_reward, min_reward, training_episode_count, training_step_count)
- episode_count
Alias for field number 0
- max_reward
Alias for field number 2
- mean_reward
Alias for field number 4
- median_reward
Alias for field number 3
- min_reward
Alias for field number 5
- step_count
Alias for field number 1
- training_episode_count
Alias for field number 6
- training_step_count
Alias for field number 7