我正在使用名为OsBrain的多代理框架。我有两个代理在同一台机器上运行,但运行不同。我正在使用NameServer检索代理到代理。虽然当我打电话给agent_proxy.addr(alias = 'some_alias')
时,它会永远陷入困境。
以下是我正在使用的示例代码
def request_ally(ns, agent, allies, energy_amt, time):
ally_proxy = ns.proxy(name = allies[0], timeout=1.0)
agents = ns.agents()
ally_proxy_addr = ally_proxy.addr(alias='energy_request')
message = {
'topic': 'ENERGY_REQUEST',
'time': time,
'energy': energy_amt
}
agent.log_info("Contacting ally for: %"%message)
resp = send_message(server_agent = agent, client_addr = ally_proxy_addr, alias = 'energy_request', message = message)
def send_message(server_agent, client_addr, alias, message):
server_agent.connect(client_addr, alias=alias)
server_agent.send(alias, message=message)
reply = server_agent.recv(alias)
server_agent.log_info("Recieved: "+str(reply))
server_agent.close(alias=alias)
return reply
远程接收代理具有以下配置:
agent = run_agent(name = args.agentname, nsaddr = ns.addr(), serializer='json', transport='tcp')
agent.bind('REP', alias='energy_request', handler=energy_request_handler)