aisysprojserver package

Submodules

aisysprojserver.act module

class aisysprojserver.act.AbandonAction(run: str)

Bases: object

run: str
class aisysprojserver.act.ActConfig(parallel_runs: bool = True)

Bases: object

parallel_runs: bool = True
class aisysprojserver.act.ActManager(env_id: str, request: RequestV1)

Bases: object

get_act_response() ResponseV1
get_action_result(action: ActionV1, run_data: RunData) ActionResult | None
get_agent_data_model(session) AgentDataModel
get_run_model_and_history(action: ActionV1 | AbandonAction, session) tuple[RunModel, list[tuple[Any, Any]]] | None
process_action(action: ActionV1 | AbandonAction)
process_outcome(outcome: Any, run_model: RunModel, session) bool

returns True iff cleanup is recommended

pydantic model aisysprojserver.act.ActionRequestV0

Bases: BaseModel

Show JSON schema
{
   "title": "ActionRequestV0",
   "type": "object",
   "properties": {
      "run": {
         "title": "Run",
         "type": "string"
      },
      "percept": {
         "title": "Percept"
      }
   },
   "required": [
      "run",
      "percept"
   ]
}

Config:
  • frozen: bool = True

  • extra: str = ignore

  • populate_by_name: bool = True

Fields:
field percept: Any [Required]
field run: Annotated[str, AfterValidator(func=_validate_old_runid)] [Required]
Constraints:
  • func = <function _validate_old_runid at 0x7faca21c1510>

pydantic model aisysprojserver.act.ActionRequestV1

Bases: BaseModel

Show JSON schema
{
   "title": "ActionRequestV1",
   "type": "object",
   "properties": {
      "percept": {
         "title": "Percept"
      },
      "run": {
         "title": "Run",
         "type": "string"
      },
      "act_no": {
         "title": "Act No",
         "type": "integer"
      }
   },
   "required": [
      "percept",
      "run",
      "act_no"
   ]
}

Config:
  • frozen: bool = True

  • extra: str = ignore

  • populate_by_name: bool = True

Fields:
field act_no: int [Required]
field percept: Any [Required]
field run: str [Required]
pydantic model aisysprojserver.act.ActionV0

Bases: BaseModel

Show JSON schema
{
   "title": "ActionV0",
   "type": "object",
   "properties": {
      "run": {
         "title": "Run",
         "type": "string"
      },
      "action": {
         "title": "Action"
      }
   },
   "required": [
      "run",
      "action"
   ]
}

Config:
  • frozen: bool = True

  • extra: str = ignore

  • populate_by_name: bool = True

Fields:
field action: Any [Required]
field run: Annotated[str, AfterValidator(func=_validate_old_runid)] [Required]
Constraints:
  • func = <function _validate_old_runid at 0x7faca21c1510>

pydantic model aisysprojserver.act.ActionV1

Bases: BaseModel

Show JSON schema
{
   "title": "ActionV1",
   "type": "object",
   "properties": {
      "action": {
         "title": "Action"
      },
      "run": {
         "title": "Run",
         "type": "string"
      },
      "act_no": {
         "title": "Act No",
         "type": "integer"
      }
   },
   "required": [
      "action",
      "run",
      "act_no"
   ]
}

Config:
  • frozen: bool = True

  • extra: str = ignore

  • populate_by_name: bool = True

Fields:
field act_no: int [Required]
field action: Any [Required]
field run: str [Required]
pydantic model aisysprojserver.act.Message

Bases: BaseModel

Show JSON schema
{
   "title": "Message",
   "type": "object",
   "properties": {
      "run": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Run"
      },
      "content": {
         "title": "Content",
         "type": "string"
      },
      "type": {
         "$ref": "#/$defs/MessageType"
      }
   },
   "$defs": {
      "MessageType": {
         "enum": [
            "error",
            "warning",
            "info"
         ],
         "title": "MessageType",
         "type": "string"
      }
   },
   "required": [
      "content",
      "type"
   ]
}

Config:
  • frozen: bool = True

  • extra: str = ignore

  • populate_by_name: bool = True

Fields:
field content: str [Required]
field run: str | None = None
field type: MessageType [Required]
class aisysprojserver.act.MessageType(value)

Bases: str, Enum

An enumeration.

error = 'error'
info = 'info'
warning = 'warning'
pydantic model aisysprojserver.act.RequestV0

Bases: BaseModel

Show JSON schema
{
   "title": "RequestV0",
   "type": "object",
   "properties": {
      "agent": {
         "title": "Agent",
         "type": "string"
      },
      "pwd": {
         "title": "Pwd",
         "type": "string"
      },
      "actions": {
         "items": {
            "$ref": "#/$defs/ActionV0"
         },
         "title": "Actions",
         "type": "array"
      },
      "single_request": {
         "default": false,
         "title": "Single Request",
         "type": "boolean"
      }
   },
   "$defs": {
      "ActionV0": {
         "properties": {
            "run": {
               "title": "Run",
               "type": "string"
            },
            "action": {
               "title": "Action"
            }
         },
         "required": [
            "run",
            "action"
         ],
         "title": "ActionV0",
         "type": "object"
      }
   },
   "required": [
      "agent",
      "pwd"
   ]
}

Config:
  • frozen: bool = True

  • extra: str = ignore

  • populate_by_name: bool = True

Fields:
field actions: list[ActionV0] [Optional]
field agent: str [Required]
field pwd: str [Required]
field single_request: bool = False
to_v1() RequestV1
pydantic model aisysprojserver.act.RequestV1

Bases: BaseModel

Show JSON schema
{
   "title": "RequestV1",
   "type": "object",
   "properties": {
      "agent": {
         "title": "Agent",
         "type": "string"
      },
      "pwd": {
         "title": "Pwd",
         "type": "string"
      },
      "actions": {
         "items": {
            "$ref": "#/$defs/ActionV1"
         },
         "title": "Actions",
         "type": "array"
      },
      "parallel_runs": {
         "default": true,
         "title": "Parallel Runs",
         "type": "boolean"
      },
      "to_abandon": {
         "items": {
            "type": "string"
         },
         "title": "To Abandon",
         "type": "array"
      },
      "client": {
         "default": "",
         "title": "Client",
         "type": "string"
      }
   },
   "$defs": {
      "ActionV1": {
         "properties": {
            "action": {
               "title": "Action"
            },
            "run": {
               "title": "Run",
               "type": "string"
            },
            "act_no": {
               "title": "Act No",
               "type": "integer"
            }
         },
         "required": [
            "action",
            "run",
            "act_no"
         ],
         "title": "ActionV1",
         "type": "object"
      }
   },
   "required": [
      "agent",
      "pwd"
   ]
}

Config:
  • frozen: bool = True

  • extra: str = ignore

  • populate_by_name: bool = True

Fields:
field actions: list[ActionV1] [Optional]
field agent: str [Required]
field client: str = ''
field parallel_runs: bool = True
field pwd: str [Required]
field to_abandon: list[str] [Optional]
pydantic model aisysprojserver.act.ResponseV0

Bases: BaseModel

Show JSON schema
{
   "title": "ResponseV0",
   "type": "object",
   "properties": {
      "errors": {
         "items": {
            "type": "string"
         },
         "title": "Errors",
         "type": "array"
      },
      "messages": {
         "items": {
            "type": "string"
         },
         "title": "Messages",
         "type": "array"
      },
      "action_requests": {
         "items": {
            "$ref": "#/$defs/ActionRequestV0"
         },
         "title": "Action Requests",
         "type": "array"
      }
   },
   "$defs": {
      "ActionRequestV0": {
         "properties": {
            "run": {
               "title": "Run",
               "type": "string"
            },
            "percept": {
               "title": "Percept"
            }
         },
         "required": [
            "run",
            "percept"
         ],
         "title": "ActionRequestV0",
         "type": "object"
      }
   }
}

Config:
  • frozen: bool = True

  • extra: str = ignore

  • populate_by_name: bool = True

Fields:
field action_requests: list[ActionRequestV0] [Optional]
field errors: list[str] [Optional]
field messages: list[str] [Optional]
pydantic model aisysprojserver.act.ResponseV1

Bases: BaseModel

Show JSON schema
{
   "title": "ResponseV1",
   "type": "object",
   "properties": {
      "action_requests": {
         "items": {
            "$ref": "#/$defs/ActionRequestV1"
         },
         "title": "Action Requests",
         "type": "array"
      },
      "active_runs": {
         "items": {
            "type": "string"
         },
         "title": "Active Runs",
         "type": "array"
      },
      "messages": {
         "items": {
            "$ref": "#/$defs/Message"
         },
         "title": "Messages",
         "type": "array"
      },
      "finished_runs": {
         "title": "Finished Runs",
         "type": "object"
      }
   },
   "$defs": {
      "ActionRequestV1": {
         "properties": {
            "percept": {
               "title": "Percept"
            },
            "run": {
               "title": "Run",
               "type": "string"
            },
            "act_no": {
               "title": "Act No",
               "type": "integer"
            }
         },
         "required": [
            "percept",
            "run",
            "act_no"
         ],
         "title": "ActionRequestV1",
         "type": "object"
      },
      "Message": {
         "properties": {
            "run": {
               "anyOf": [
                  {
                     "type": "string"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Run"
            },
            "content": {
               "title": "Content",
               "type": "string"
            },
            "type": {
               "$ref": "#/$defs/MessageType"
            }
         },
         "required": [
            "content",
            "type"
         ],
         "title": "Message",
         "type": "object"
      },
      "MessageType": {
         "enum": [
            "error",
            "warning",
            "info"
         ],
         "title": "MessageType",
         "type": "string"
      }
   }
}

Config:
  • frozen: bool = True

  • extra: str = ignore

  • populate_by_name: bool = True

Fields:
field action_requests: list[ActionRequestV1] [Optional]
field active_runs: list[str] [Optional]
field finished_runs: dict[str, Any] [Optional]
field messages: list[Message] [Optional]
to_v0() ResponseV0
aisysprojserver.act.act(env_id: str)

aisysprojserver.active_env module

class aisysprojserver.active_env.ActiveEnvironment(identifier: str)

Bases: ModelMixin[ActiveEnvironmentModel]

property display_name: str
property env_class_refstr: str
get_env_data() EnvData
get_env_instance() GenericEnvironment
classmethod new(identifier: str, env_class: str, display_name: str, display_group: str, config: str, overwrite: bool = False) ActiveEnvironment
property recent_runs_key: str
aisysprojserver.active_env.get_all_active_envs() list[ActiveEnvironment]

aisysprojserver.active_env_management module

pydantic model aisysprojserver.active_env_management.MakeEnvRequest

Bases: BaseModel

Show JSON schema
{
   "title": "MakeEnvRequest",
   "type": "object",
   "properties": {
      "env_class": {
         "title": "Env Class",
         "type": "string"
      },
      "display_name": {
         "title": "Display Name",
         "type": "string"
      },
      "config": {
         "title": "Config"
      },
      "display_group": {
         "default": "",
         "title": "Display Group",
         "type": "string"
      },
      "overwrite": {
         "default": false,
         "title": "Overwrite",
         "type": "boolean"
      }
   },
   "required": [
      "env_class",
      "display_name",
      "config"
   ]
}

Config:
  • frozen: bool = True

  • extra: str = ignore

  • populate_by_name: bool = True

Fields:
field config: Any [Required]
field display_group: str = ''
field display_name: str [Required]
field env_class: str [Required]
field overwrite: bool = False
aisysprojserver.active_env_management.makeenv(env: str)

aisysprojserver.admin module

aisysprojserver.admin.deleteunusedagents(env_id: str)
aisysprojserver.admin.diskusage()
aisysprojserver.admin.errors()
aisysprojserver.admin.get_env_results(active_env: ActiveEnvironment)
aisysprojserver.admin.getenvs()
aisysprojserver.admin.removenonrecentruns()
aisysprojserver.admin.results()
aisysprojserver.admin.results_env(env_id: str)

aisysprojserver.agent_account module

class aisysprojserver.agent_account.AgentAccount(environment: str, agentname: str, is_client: bool = False)

Bases: ModelMixin[AgentAccountModel]

block()
delete()
classmethod from_request(environment: str, agent: str | None = None) AgentAccount
is_active() bool
is_authenticated() bool
require_active()
require_authenticated()
signup(overwrite: bool = False) str

The caller must have verified that the environment and agentname are valid. Returns the password.

unblock()
class aisysprojserver.agent_account.AgentStatus(value)

Bases: IntEnum

An enumeration.

ACTIVE = 1
LOCKED = 0
exception aisysprojserver.agent_account.NoSuchAgentError

Bases: Exception

aisysprojserver.agent_account.get_all_agentaccounts_for_env(env_id: str) list[AgentAccount]

aisysprojserver.agent_account_management module

aisysprojserver.agent_account_management.blockagent(env: str, agent: str)
aisysprojserver.agent_account_management.makeagent(env: str, agent: str)
aisysprojserver.agent_account_management.unblockagent(env: str, agent: str)

aisysprojserver.agent_data module

class aisysprojserver.agent_data.AgentData(identifier)

Bases: ModelMixin[AgentDataModel]

delete(session=None)
delete_nonrecent_runs(session=None)
property display_name: str
identifier: str
to_agent_data_summary() AgentDataSummary
aisysprojserver.agent_data.get_all_agentdata() list[AgentData]
aisysprojserver.agent_data.get_all_agentdata_for_env(env_id: str) list[AgentData]

aisysprojserver.app module

aisysprojserver.app.create_app(configuration: Config | None = None) Flask
aisysprojserver.app.exception_handler(exception)
aisysprojserver.app.main()

aisysprojserver.authentication module

Functionality for password hashing and checking.

Design decisions:

  • The way a password is stored is indicated by a prefix. That makes it possible to change the scheme later on if desired.

  • We do not allow users to set a password (the server sets high-entropy passwords). That way we don’t have to use slow hashing algorithms like bcrypt.

aisysprojserver.authentication.default_pwd_hash(password: str) str
aisysprojserver.authentication.generate_admin_password()
aisysprojserver.authentication.get_admin_hashes() list[str]
aisysprojserver.authentication.require_admin_auth()
aisysprojserver.authentication.require_password_match(password: str, stored_hash: str)

aisysprojserver.config module

class aisysprojserver.config.Config

Bases: object

ADMIN_AUTH = None
CACHE_DEFAULT_TIMEOUT = 5
CACHE_TYPE = 'SimpleCache'
CONFIG_NAME: str = 'test'
property DATABASE_URI: str
property LOG_FILE: Path
MAX_CONTENT_LENGTH: int = 1000000
MIN_LOG_LEVEL = 20
OTLP_ENDPOINT: str | None = None
PERSISTENT: Path = PosixPath('/tmp')
property PLUGINS_DIR: Path
PROMETHEUS_PORT: int | None = 9464
register(app: Flask)
class aisysprojserver.config.TestConfig

Bases: Config

ADMIN_AUTH = 'sha256:f7a03f48c0e2aa2d5e55ca186c20032ddbf53b7f5f93fce387d65c3f83433e8d'
class aisysprojserver.config.UwsgiConfig

Bases: Config

ADMIN_AUTH = None
CONFIG_NAME: str = 'uwsgi'
OTLP_ENDPOINT: str | None = 'http://localhost:4318/v1/metrics'
PERSISTENT: Path = PosixPath('/app/persistent')
PROMETHEUS_PORT: int | None = None
aisysprojserver.config.get() Config

aisysprojserver.env_interface module

class aisysprojserver.env_interface.AbbreviatedRunData(run_id: 'int', outcome: 'Optional[Any]', agent_name: 'str')

Bases: object

agent_name: str
outcome: Any | None
run_id: int
class aisysprojserver.env_interface.ActionHistoryEntry(action: 'Any', extra_info: 'Any')

Bases: object

action: Any
extra_info: Any
class aisysprojserver.env_interface.ActionRequest(content: 'Any')

Bases: object

content: Any
class aisysprojserver.env_interface.ActionResult(new_state: 'Optional[Any]' = None, message: 'Optional[str]' = None, action_extra_info: 'Any' = None, outcome: 'Optional[Any]' = None)

Bases: object

action_extra_info: Any = None
classmethod error(message: str) ActionResult
message: str | None = None
new_state: Any | None = None
outcome: Any | None = None
class aisysprojserver.env_interface.AgentDataSummary(agent_name: 'str', agent_rating: 'float', current_agent_rating: 'float', recent_runs: 'list[AbbreviatedRunData]', total_number_of_runs: 'int', fully_evaluated: 'bool')

Bases: object

agent_name: str
agent_rating: float
current_agent_rating: float
fully_evaluated: bool
recent_runs: list[AbbreviatedRunData]
total_number_of_runs: int
class aisysprojserver.env_interface.EnvData(agents: 'list[AgentDataSummary]', recent_runs: 'list[AbbreviatedRunData]')

Bases: object

agents: list[AgentDataSummary]
recent_runs: list[AbbreviatedRunData]
class aisysprojserver.env_interface.EnvInfo(display_name: 'str', identifier: 'str')

Bases: object

display_name: str
identifier: str
class aisysprojserver.env_interface.GenericEnvironment(env_info: EnvInfo, config_json: Any)

Bases: ABC

abstract act(action: Any, run_data: RunData) ActionResult
get_abandon_outcome(run_data: RunData) Any
abstract get_action_request(run_data: RunData) ActionRequest
abstract new_run() Any
settings: EnvSettings = <aisysprojserver.env_settings.EnvSettings object>
view_agent(agent_data: AgentDataSummary) str
view_env(env_data: EnvData) str
view_run(run_data: RunData) str
class aisysprojserver.env_interface.RunData(action_history: 'list[ActionHistoryEntry]', state: 'Any', outcome: 'Optional[Any]', run_id: 'int', agent_name: 'str')

Bases: object

action_history: list[ActionHistoryEntry]
agent_name: str
outcome: Any | None
run_id: int
state: Any

aisysprojserver.env_mixins module

class aisysprojserver.env_mixins.SimpleViewAgent

Bases: object

settings: EnvSettings
view_agent(agent_data: AgentDataSummary) str
class aisysprojserver.env_mixins.SimpleViewEnv

Bases: object

settings: EnvSettings
view_env(env_data: EnvData) str

aisysprojserver.env_settings module

The environment settings tells the server how to work with the environment.

Note that only the relevant subset of settings is actually used.

class aisysprojserver.env_settings.EnvSettings

Bases: object

CAN_ABANDON_RUNS: bool = False
DESCRIPTION: str = ''
INITIAL_RATING: float = 0.0
MIN_RUNS_FOR_FULLY_EVALUATED: int = 50
NUMBER_OF_ACTION_REQUESTS: int = 5
RATING_OBJECTIVE: str = 'max'
RATING_STRATEGY: str = 'average'
STORE_ACTION_HISTORY: bool = True

aisysprojserver.group module

class aisysprojserver.group.Group(identifier: str)

Bases: ModelMixin[GroupModel]

add_env(env: ActiveEnvironment)
add_subgroup(subgroup: Group)
delete()
property description: str
property display_name: str
get_envs() list[ActiveEnvironment]
get_subgroups() list[Group]
classmethod new(identifier: str, title: str, description: str, overwrite: bool = False) Group
aisysprojserver.group.get_all_groups() list[Group]

aisysprojserver.group_management module

pydantic model aisysprojserver.group_management.MakeGroupRequest

Bases: BaseModel

Show JSON schema
{
   "title": "MakeGroupRequest",
   "type": "object",
   "properties": {
      "title": {
         "title": "Title",
         "type": "string"
      },
      "description": {
         "title": "Description",
         "type": "string"
      },
      "overwrite": {
         "default": false,
         "title": "Overwrite",
         "type": "boolean"
      }
   },
   "required": [
      "title",
      "description"
   ]
}

Config:
  • frozen: bool = True

  • extra: str = ignore

  • populate_by_name: bool = True

Fields:
field description: str [Required]
field overwrite: bool = False
field title: str [Required]
aisysprojserver.group_management.addenv(group: str, env: str)
aisysprojserver.group_management.addsubgroup(group: str, subgroup: str)
aisysprojserver.group_management.deletegroup(group: str)
aisysprojserver.group_management.makegroup(group: str)

aisysprojserver.models module

Database models for the AI system project server

Note that this has grown organically without any expertise in database design, using only the most basic features. It is not a good example of how to structure a database model.

class aisysprojserver.models.ActiveEnvironmentModel(**kwargs)

Bases: Base

config
displaygroup
displayname
env_class
identifier
signup
status
class aisysprojserver.models.AgentAccountModel(**kwargs)

Bases: Base

environment
identifier
password
status
class aisysprojserver.models.AgentDataModel(**kwargs)

Bases: Base

best_rating
current_rating
environment
fully_evaluated
identifier
recent_results
recently_finished_runs
total_runs
class aisysprojserver.models.GroupEntryModel(**kwargs)

Bases: Base

entry
entry_type
group
class aisysprojserver.models.GroupModel(**kwargs)

Bases: Base

description_html
displayname
identifier
class aisysprojserver.models.KeyValAccess(session)

Bases: object

class aisysprojserver.models.KeyValModel(**kwargs)

Bases: Base

key
val
class aisysprojserver.models.ModelMixin(model_class: type[_M])

Bases: Generic[_M]

Mixin for classes that are linked to a model

exists() bool
identifier: str | int
class aisysprojserver.models.RunModel(**kwargs)

Bases: Base

agent
environment
finished
history
identifier
outcome
outstanding_action
state
aisysprojserver.models.setup(config: Config)

aisysprojserver.plugins module

exception aisysprojserver.plugins.BadPluginError

Bases: Exception

class aisysprojserver.plugins.Plugin(package_name: str)

Bases: object

property init_module
is_valid: bool = True
package_name: str
unimport()
property version: str | None
class aisysprojserver.plugins.PluginManager

Bases: object

classmethod get(reference: str)

reference can be ‘module.submodule’ or ‘module.submodule:attribute’

classmethod is_initialized() bool
classmethod load_from_zipfile(zf: ZipFile) str
plugins: dict[str, Plugin] = {}
plugins_dir: Path | None = None
classmethod reload_all_plugins()
classmethod set_plugins_dir(plugins_dir: Path)
aisysprojserver.plugins.upload()

aisysprojserver.run module

class aisysprojserver.run.Run(identifier)

Bases: ModelMixin[RunModel]

env_str() str
get_history() list[str]
get_state() Any
identifier: int
to_abbreviated_run_data() AbbreviatedRunData
to_run_data() RunData

aisysprojserver.telemetry module

class aisysprojserver.telemetry.MonitoredBlueprint(name: str, import_name: str, static_folder: str | ~os.PathLike[str] | None = None, static_url_path: str | None = None, template_folder: str | ~os.PathLike[str] | None = None, url_prefix: str | None = None, subdomain: str | None = None, url_defaults: dict[str, ~typing.Any] | None = None, root_path: str | None = None, cli_group: str | None = <object object>)

Bases: Blueprint

route(rule, **options)

Decorate a view function to register it with the given URL rule and options. Calls add_url_rule(), which has more details about the implementation.

@app.route("/")
def index():
    return "Hello, World!"

See url-route-registrations.

The endpoint name for the route defaults to the name of the view function if the endpoint parameter isn’t passed.

The methods parameter defaults to ["GET"]. HEAD and OPTIONS are added automatically.

Parameters:
  • rule – The URL rule string.

  • options – Extra options passed to the Rule object.

aisysprojserver.telemetry.get_pid() int
aisysprojserver.telemetry.measure_action_processing(env_class_refstr: str)
aisysprojserver.telemetry.measure_run_creation_duration(env_class_refstr: str)
aisysprojserver.telemetry.report_action(env_id: str, protocol_version: str, number_of_actions: int = 1, client: str | None = None)
aisysprojserver.telemetry.setup(config: Config)

aisysprojserver.util module

aisysprojserver.util.json_dump(thing) str
aisysprojserver.util.json_load(string: str) Any
aisysprojserver.util.parse_request(model: type[_T], request) _T

aisysprojserver.website module

aisysprojserver.website.agent_page(env: str, agent: str)
aisysprojserver.website.env_page(env: str)
aisysprojserver.website.frontpage()
aisysprojserver.website.group_page(group: str | Group)
aisysprojserver.website.plugins_page()
aisysprojserver.website.run_page(env: str, runid: str)

Module contents