Create a service from scratch
Developing a new service with the Open Autonomy framework almost surely requires to build a dedicated agent for it, especially when the business logic of existing agents do not fit for the functionality of the service. This process requires to execute most of the development process pipeline, which is what we will be covering in this guide.
What you will learn
In this guide, you will learn how to execute the main steps of the development process to create and deploy a new agent service.
Before starting this guide, ensure that your machine satisfies the framework requirements and that you have followed the set up guide. As a result you should have a Pipenv workspace folder.
Draft the service idea. Define the business logic of your service as an FSM. Determine what are the states, events and transitions that the service needs to transition in order to achieve the desired functionality. Define what kind of consensus need agents to transit from one state to another (e.g., all agents must share a different value, or a threshold of agents need to agree on a common value).
Write the FSM specification file. This file formally encodes the FSM designed in the previous step in a language that is understood by the framework.
Example of an
Given a sketch of the FSM, the structure of the
fsm_specification.yamlfile is quite straightforward. Below we show the FSM specification file of the Hello World service.
alphabet_in: - DONE - NO_MAJORITY - RESET_TIMEOUT - ROUND_TIMEOUT default_start_state: RegistrationRound final_states:  label: packages.valory.skills.hello_world_abci.rounds.HelloWorldAbciApp start_states: - RegistrationRound states: - CollectRandomnessRound - PrintMessageRound - RegistrationRound - ResetAndPauseRound - SelectKeeperRound transition_func: (CollectRandomnessRound, DONE): SelectKeeperRound (CollectRandomnessRound, NO_MAJORITY): CollectRandomnessRound (CollectRandomnessRound, ROUND_TIMEOUT): CollectRandomnessRound (PrintMessageRound, DONE): ResetAndPauseRound (PrintMessageRound, ROUND_TIMEOUT): RegistrationRound (RegistrationRound, DONE): CollectRandomnessRound (ResetAndPauseRound, DONE): CollectRandomnessRound (ResetAndPauseRound, NO_MAJORITY): RegistrationRound (ResetAndPauseRound, RESET_TIMEOUT): RegistrationRound (SelectKeeperRound, DONE): PrintMessageRound (SelectKeeperRound, NO_MAJORITY): RegistrationRound (SelectKeeperRound, ROUND_TIMEOUT): RegistrationRound
Code the FSM App skill. This is the core component of every agent belonging to a service. It consists of a number of classes that implement the business logic of the service as an FSM. The framework provides a scaffold tool that will help you to create most of the boilerplate code. You can follow the guide to create an FSM App skill to learn. Alternatively, you can also use the developer template repository as the starting point. It includes the recommended linters, continuous integration and several other files so that you start from scratch.
Once you have finished coding and testing the FSM App skill, you can push it on a local or remote registry for future reuse of the component. Note down the skill public ID and the package hash.
We recommend that your developed components have exhaustive tests and pass the library linters before pushing them to a remote repository.
Define the agent. Create the agent and add the necessary components (connections, contracts, protocols and skills), including the FSM App skill that you have created in the previous step. You can achieve this through the commands
autonomy create <agent_name> cd <agent_name> autonomy add skill <fsm_app_package> ... autonomy add <component_type> <component_package>
You can browse the list of default packages of the Open Autonomy framework available on the default remote IPFS registry. If you require to develop other kind of custom components, you can browse the Open AEA documentation for further guidance. For example, have a look at how to create and interact with contracts in our contract development guide.
Once you have finished coding and testing the agent, pubish it on a local or remote registry for future reuse of the agent. Note down the agent public ID and the package hash.
When adding a component, it will automatically add all its dependencies to the agent. For this reason, it might be the case that you don't need additional components after adding the FSM App skill.
At this point, you will have an agent implementing the desired service functionality. Now, you can continue with Steps 5, 6 and 7 in the guide to create a service with an existing agent to define and deploy the corresponding agent service.