Skip to content

Commit

Permalink
Merge pull request #402 from fetchai/develop
Browse files Browse the repository at this point in the history
Release v0.1.13
  • Loading branch information
DavidMinarsch authored Nov 8, 2019
2 parents 907fbad + f1f73df commit 9688dc8
Show file tree
Hide file tree
Showing 80 changed files with 2,117 additions and 717 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,3 @@ venv.bak/
data/*
temp_private_key.pem
.idea/

11 changes: 11 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,14 @@ Release History
- Fixes some examples and docs
- Refactors crypto modules and adds additional tests
- Multiple additional minor fixes and changes

0.1.13 (2019-11-08)
-------------------

- Adds envelope serializer
- Adds support for programmatically initializing an AEA
- Adds some tests for the gui and other components
- Exposes connection status to skills
- Updates oef connection to re-establish dropped connections
- Updates the car park agent
- Multiple additional minor fixes and changes
8 changes: 4 additions & 4 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ base58 = "*"
docker = "*"
click = "*"
pyyaml = ">=4.2b1"
oef = {index = "test-pypi",version = "==0.6.10"}
oef = "==0.8.1"
colorlog = "*"
jsonschema = "*"
protobuf = "*"
flask = "*"
connexion = ">=2.4.0"
watchdog = "*"
python-dotenv = "*"
fetchai-ledger-api = "*"
web3 = "*"
eth-account = "*"
fetchai-ledger-api = "==0.8.1"
web3 = "==5.2.2"
eth-account = "==0.4.0"

[requires]
python_version = "3.7"
214 changes: 110 additions & 104 deletions Pipfile.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ A framework for autonomous economic agent (AEA) development

This repository contains submodules. Clone with recursive strategy:

git clone git@github.com:fetchai/agents-aea.git --recursive && cd agents-aea
git clone https://github.com/fetchai/agents-aea.git --recursive && cd agents-aea

### Dependencies

Expand Down
2 changes: 1 addition & 1 deletion aea/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
__title__ = 'aea'
__description__ = 'Autonomous Economic Agent framework'
__url__ = 'https://github.com/fetchai/agents-aea.git'
__version__ = '0.1.12'
__version__ = '0.1.13'
__author__ = 'Fetch.AI Limited'
__license__ = 'Apache 2.0'
__copyright__ = '2019 Fetch.AI Limited'
28 changes: 13 additions & 15 deletions aea/aea.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

"""This module contains the implementation of an Autonomous Economic Agent."""
import logging
from pathlib import Path
from typing import Optional, cast

from aea.agent import Agent
Expand All @@ -31,7 +30,6 @@
from aea.registries.base import Filter, Resources
from aea.skills.error.handlers import ErrorHandler


logger = logging.getLogger(__name__)


Expand All @@ -42,29 +40,27 @@ def __init__(self, name: str,
mailbox: MailBox,
wallet: Wallet,
ledger_apis: LedgerApis,
resources: Resources,
timeout: float = 0.0,
debug: bool = False,
max_reactions: int = 20,
directory: str = '') -> None:
max_reactions: int = 20) -> None:
"""
Instantiate the agent.
:param name: the name of the agent
:param mailbox: the mailbox of the agent.
:param wallet: the wallet of the agent.
:param ledger_apis: the ledger apis of the agent.
:param resources: the resources of the agent.
:param timeout: the time in (fractions of) seconds to time out an agent between act and react
:param debug: if True, run the agent in debug mode.
:param max_reactions: the processing rate of messages per iteration.
:param directory: the path to the agent's resource directory.
| If None, we assume the directory is in the working directory of the interpreter.
:return: None
"""
super().__init__(name=name, wallet=wallet, timeout=timeout, debug=debug)

self.max_reactions = max_reactions
self._directory = directory if directory else str(Path(".").absolute())

self.mailbox = mailbox
self._decision_maker = DecisionMaker(self.name,
Expand All @@ -76,13 +72,14 @@ def __init__(self, name: str,
self.wallet.public_keys,
self.wallet.addresses,
ledger_apis,
self.mailbox.connection_status,
self.outbox,
self.decision_maker.message_in_queue,
self.decision_maker.ownership_state,
self.decision_maker.preferences,
self.decision_maker.is_ready_to_pursuit_goals)
self._resources = None # type: Optional[Resources]
self._filter = None # type: Optional[Filter]
self._resources = resources
self._filter = Filter(self.resources, self.decision_maker.message_out_queue)

@property
def decision_maker(self) -> DecisionMaker:
Expand All @@ -97,13 +94,16 @@ def context(self) -> AgentContext:
@property
def resources(self) -> Resources:
"""Get resources."""
assert self._resources is not None, "No resources initialized. Call setup."
return self._resources

@resources.setter
def resources(self, resources: 'Resources'):
"""Set resources."""
self._resources = resources

@property
def filter(self) -> Filter:
"""Get filter."""
assert self._filter is not None, "No filter initialized. Call setup."
return self._filter

def setup(self) -> None:
Expand All @@ -112,10 +112,8 @@ def setup(self) -> None:
:return: None
"""
self._resources = Resources.from_resource_dir(self._directory, self.context)
assert self._resources is not None, "No resources initialized. Error in setup."
self._resources.setup()
self._filter = Filter(self.resources, self.decision_maker.message_out_queue)
self.resources.load(self.context)
self.resources.setup()

def act(self) -> None:
"""
Expand Down
5 changes: 3 additions & 2 deletions aea/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from aea.crypto.ledger_apis import LedgerApis, _try_to_instantiate_fetchai_ledger_api, _try_to_instantiate_ethereum_ledger_api, SUPPORTED_LEDGER_APIS
from aea.crypto.wallet import Wallet, DEFAULT, SUPPORTED_CRYPTOS
from aea.mail.base import MailBox
from aea.registries.base import Resources


def _verify_or_create_private_keys(ctx: Context) -> None:
Expand Down Expand Up @@ -197,7 +198,7 @@ def run(click_context, connection_name: str, env_file: str, install_deps: bool):
connection_name = ctx.agent_config.default_connection if connection_name is None else connection_name
_try_to_load_protocols(ctx)
try:
connection = _setup_connection(connection_name, wallet.public_keys[DEFAULT], ctx)
connection = _setup_connection(connection_name, wallet.public_keys[FETCHAI], ctx)
except AEAConfigException as e:
logger.error(str(e))
sys.exit(1)
Expand All @@ -209,7 +210,7 @@ def run(click_context, connection_name: str, env_file: str, install_deps: bool):
click_context.invoke(install)

mailbox = MailBox(connection)
agent = AEA(agent_name, mailbox, wallet, ledger_apis, directory=str(Path(".")))
agent = AEA(agent_name, mailbox, wallet, ledger_apis, resources=Resources(str(Path("."))))
try:
agent.start()
except KeyboardInterrupt:
Expand Down
35 changes: 31 additions & 4 deletions aea/cli_gui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def stop_oef_node():
return "All fine", 200 # 200 (OK)


def start_agent(agent_id):
def start_agent(agent_id, connection_id):
"""Start a local agent running."""
# Test if it is already running in some form
if agent_id in flask.app.agent_processes:
Expand All @@ -279,7 +279,20 @@ def start_agent(agent_id):
return {"detail": "Agent {} is already running".format(agent_id)}, 400 # 400 Bad request

agent_dir = os.path.join(flask.app.agents_dir, agent_id)
agent_process = _call_aea_async(["aea", "run"], agent_dir)

if connection_id is not None and connection_id != "":
connections = get_local_items(agent_id, "connection")
has_named_connection = False
for element in connections:
if element["id"] == connection_id:
has_named_connection = True
if has_named_connection:
agent_process = _call_aea_async(["aea", "run", "--connection", connection_id], agent_dir)
else:
return {"detail": "Trying to run agent {} with non-existant connection: {}".format(agent_id, connection_id)}, 400 # 400 Bad request
else:
agent_process = _call_aea_async(["aea", "run"], agent_dir)

if agent_process is None:
return {"detail": "Failed to run agent {}".format(agent_id)}, 400 # 400 Bad request
else:
Expand Down Expand Up @@ -379,9 +392,8 @@ def _kill_running_oef_nodes():
subprocess.call(['docker', 'kill', oef_node_name])


def run():
def create_app():
"""Run the flask server."""
_kill_running_oef_nodes()
CUR_DIR = os.path.abspath(os.path.dirname(__file__))
app = connexion.FlaskApp(__name__, specification_dir=CUR_DIR)
flask.app.oef_process = None
Expand Down Expand Up @@ -410,8 +422,23 @@ def favicon():
return flask.send_from_directory(
os.path.join(app.root_path, 'static'), 'favicon.ico', mimetype='image/vnd.microsoft.icon')

return app


def run():
"""Run the GUI."""
_kill_running_oef_nodes()
app = create_app()
app.run(host='127.0.0.1', port=8080, debug=False)

return app


def run_test():
"""Run the gui in the form where we can run tests against it."""
app = create_app()
return app.app.test_client()


# If we're running in stand alone mode, run the application
if __name__ == '__main__':
Expand Down
8 changes: 6 additions & 2 deletions aea/cli_gui/aea_cli_rest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -292,17 +292,21 @@ paths:
description: id of agent to run
type: string
required: True
- name: connection_id
in: body
description: id f the connection to activate when running
schema:
type: string
required: True
responses:
201:
description: Start the OEF Nodoe
schema:
type: string

400:
description: Cannot start agent
schema:
type: string

get:
operationId: aea.cli_gui.get_agent_status
tags:
Expand Down
4 changes: 2 additions & 2 deletions aea/cli_gui/static/css/home.css
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,5 @@ td {
background-color: black;
color: red;
font-family: "Courier New", Courier, monospace;

}
}
own:hover .dropbtn {background-color: #3e8e41;}w {display:block;}
13 changes: 9 additions & 4 deletions aea/cli_gui/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,17 @@ <h3>Selected {{htmlElements[i][1]}}: <div id="{{htmlElements[i][2]}}SelectionId"

<div class="section editor">
<h2>Running "<span class="localItemHeading">NONE</span>" Agent</h2>

<button id="startAgent">Start Agent</button>
<label for="runConnectionId">with connection id:
<input id="runConnectionId" type="text" />
</label>
<br>
<button id="stopAgent">Stop Agent</button>
<h3 id="agentStatus">Agent Status: NONE</h3>
<div class="code" id="agentTTY">
</div>
<div class="code" id="agentTTY"></div>
<br>
<div class="codeError" id="agentError">
</div>
<div class="codeError" id="agentError"></div>
</div>

<br>
Expand Down Expand Up @@ -129,8 +132,10 @@ <h3>Selected {{htmlElements[i][1]}}: <div id="{{htmlElements[i][2]}}SelectionId"
<br>
{% endif %}
{% endfor %}

<div class="section editor">
<h2>OEF Node</h2>

<button id="startOEFNode">Start OEF Node</button>
<button id="stopOEFNode">Stop OEF Node</button>
<h3 id="oefStatus">OEF Node Status: NONE</h3>
Expand Down
9 changes: 6 additions & 3 deletions aea/cli_gui/templates/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,14 @@ class Model{
self.$event_pump.trigger('model_error', [xhr, textStatus, errorThrown]);
})
}
startAgent(agentId){
startAgent(agentId, runConnectionId){
var ajax_options = {
type: 'POST',
url: 'api/agent/' + agentId + '/run',
accepts: 'application/json',
contentType: 'plain/text'
contentType: 'application/json',
dataType: 'json',
data: JSON.stringify(runConnectionId)
};
var self = this;
$.ajax(ajax_options)
Expand Down Expand Up @@ -525,8 +527,9 @@ class Controller{
$('#startAgent').click({el: element}, function(e) {
e.preventDefault();
var agentId = $('#localAgentsSelectionId').html()
var connectionId = $('#runConnectionId').val()
if (self.validateId(agentId)){
self.model.startAgent(agentId)
self.model.startAgent(agentId, connectionId)
}
else{
alert('Error: Attempting to start agent with ID: ' + agentId);
Expand Down
Loading

0 comments on commit 9688dc8

Please sign in to comment.