-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagente_facturacion.py
More file actions
44 lines (40 loc) · 1.51 KB
/
Copy pathagente_facturacion.py
File metadata and controls
44 lines (40 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
import asyncio
import random
from neural_protocol.agent.base_ws import WSNeuralAgent
from neural_protocol.core.signal import NeuralSignalType
class AgenteFacturacion(WSNeuralAgent):
async def handle_signal(self, signal):
print(f"\n📥 Facturación recibe: {signal.payload}")
if signal.signal_type == NeuralSignalType.GLUTAMATE:
await asyncio.sleep(1)
factura_id = f"FAC-{random.randint(1000,9999)}"
respuesta = {
"factura_id": factura_id,
"cliente": signal.payload.get("cliente"),
"producto": signal.payload.get("producto"),
"monto": signal.payload.get("monto"),
"pedido_id": signal.payload.get("pedido_id"),
"estado": "emitida",
"timestamp": asyncio.get_event_loop().time()
}
await self.transmit(signal.source, NeuralSignalType.SEROTONIN, respuesta)
print(f"✅ Factura {factura_id} generada y enviada a vendedor")
async def main():
agente = AgenteFacturacion(
agent_id="facturacion",
hub_host="localhost",
hub_port=8766,
domain="empresa-b.com"
)
await agente.start()
print("🟢 Agente de facturación conectado al hub B")
try:
await asyncio.Event().wait()
except KeyboardInterrupt:
pass
finally:
await agente.stop()
print("🔴 Agente de facturación desconectado")
if __name__ == "__main__":
asyncio.run(main())