for key, value in attributes.items(): attribute_list.append(AttributeSchema(key, bool, False, value)) data_model = DataModel(data['name'], attribute_list, data['description']) return data_model def load_json_file(path): with open(path) as file_: data = json.load(file_) return data if __name__ == '__main__': search_terms = sys.argv[1].split('_') max_price = float(sys.argv[2]) net = sys.argv[3] oef = 'oef.economicagents.com' if net == 'test' else '127.0.0.1' query_array = [] for term in search_terms: query_array.append(Constraint(term, Eq(True))) query = Query(query_array) agent = Verifier('Verifier', oef_addr = oef, oef_port = 10000, max_price = max_price) agent.connect() agent.search_services(0, query) try: agent.run() finally: agent.stop() agent.disconnect()
transaction = json.loads(content.decode("utf-8")) print("[{0}]: Received contract from {1}".format( self.public_key, origin)) print("READY TO SUBMIT: ", transaction) self.stop() if __name__ == "__main__": # create and connect the agent agent = RiderAgent("RiderAgent", oef_addr="127.0.0.1", oef_port=10000) agent.connect() time.sleep(2) query = Query([Constraint(PRICE_PER_KM.name, Eq(True))], JOURNEY_MODEL) agent.search_services(0, query) time.sleep(1) try: agent.run() time.sleep(3) except Exception as ex: print("EXCEPTION:", ex) finally: try: agent.stop() agent.disconnect() except: pass
server_agent = GreetingsAgent(server_proxy) # connect the agents to the OEF client_agent.connect() server_agent.connect() # register the greetings service agent on the OEF say_hello = AttributeSchema("say_hello", bool, True, "The agent answers to 'hello' messages.") greetings_model = DataModel("greetings", [say_hello], "Greetings service.") greetings_description = Description({"say_hello": True}, greetings_model) server_agent.register_service(0, greetings_description) # the client executes the search for greetings services # we are looking for services that answers to "hello" messages query = Query([Constraint("say_hello", Eq(True))], greetings_model) print("[{}]: Search for 'greetings' services. search_id={}".format( client_agent.public_key, 0)) client_agent.search_services(0, query) # run the agents try: loop = asyncio.get_event_loop() loop.run_until_complete( asyncio.gather(client_agent.async_run(), server_agent.async_run())) finally: client_agent.stop() server_agent.stop() client_agent.disconnect()
self.stop() if __name__ == "__main__": local_node = OEFLocalProxy.LocalNode() client = WeatherClient("weather_client", local_node) server = WeatherStation("weather_station", local_node) client.connect() server.connect() server.register_service(0, server.weather_service_description) query = Query([ Constraint(TEMPERATURE_ATTR.name, Eq(True)), Constraint(AIR_PRESSURE_ATTR.name, Eq(True)), Constraint(HUMIDITY_ATTR.name, Eq(True)) ], WEATHER_DATA_MODEL) client.on_search_result(0, ["weather_station"]) try: loop = asyncio.get_event_loop() asyncio.ensure_future(local_node.run()) loop.run_until_complete( asyncio.gather(client.async_run(), server.async_run())) local_node.stop() finally: local_node.stop() client.stop()
#locate the agent account entity for interacting with the ledger. with open ('./workdir/Agent_Auction/client/client_private.key', 'r') as private_key_file: client_agentID = Entity.load(private_key_file) else: #create new entity for the agent client_agentID = Entity() #store private key of newly formed entity with open('./workdir/Agent_Auction/client/client_private.key', 'w') as private_key_file: client_agentID.dump(private_key_file) #give the account starting tokens api.sync(api.tokens.wealth(client_agentID, 1000)) startBalance = api.tokens.balance(client_agentID) # define an OEF Agent client_agent = ClientAgent(str(Address(client_agentID)), 50, 5, client_agentID, oef_addr="127.0.0.1", oef_port=10000) print('Balance Before:', startBalance) # connect it to the OEF Node client_agent.connect() # query OEF for DataService providers echo_query1 = Query([Constraint("timezone", Eq(3)), Constraint("twentyfour", Eq(False))],TIME_AGENT()) client_agent.search_services(0, echo_query1) client_agent.run()
# print("[{0}]: Sending contract to {1}".format(self.public_key, origin)) # self.send_message(0, dialogue_id, origin, encoded_data) if __name__ == "__main__": name = sys.argv[1] print('Name:', name) agent = ScooterAgent(name, oef_addr="127.0.0.1", oef_port=10000) agent.connect() time.sleep(2) query = Query([Constraint(PRICE_PER_ENERGY_PERCENT.name, Eq(True))], JOURNEY_MODEL) agent.search_services(0, query) time.sleep(1) print("[{}]: Waiting for clients...".format(agent.public_key)) try: agent.run() finally: try: agent.stop() agent.disconnect() except: pass