feat: add agent that is able to receive messages from UI
Inside the `/message` enpoint we put a message onto the internal event queue, which gets read by TestAgent. This agent, in turn, logs the message (temporary behaviour until we implement RI integration). The name TestAgent is of course temporary, this is just for exploratory purposes. ref: N25B-165
This commit is contained in:
@@ -3,10 +3,13 @@ import contextlib
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
import logging
|
||||
import zmq
|
||||
|
||||
# Internal imports
|
||||
from control_backend.agents.test_agent import TestAgent
|
||||
from control_backend.api.v1.router import api_router
|
||||
from control_backend.core.config import settings
|
||||
from control_backend.core.zmq_context import context
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
@@ -14,6 +17,17 @@ logging.basicConfig(level=logging.INFO)
|
||||
@contextlib.asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
logger.info("%s starting up.", app.title)
|
||||
|
||||
# Initiate sockets
|
||||
internal_comm_socket = context.socket(zmq.PUB)
|
||||
internal_comm_address = settings.zmq_settings.internal_comm_address
|
||||
internal_comm_socket.bind(internal_comm_address)
|
||||
app.state.internal_comm_socket = internal_comm_socket
|
||||
logger.info("Internal publishing socket bound to %s", internal_comm_socket)
|
||||
|
||||
# Initiate agents
|
||||
test_agent = TestAgent("test_agent@localhost", "test_agent")
|
||||
await test_agent.start()
|
||||
|
||||
yield
|
||||
|
||||
@@ -34,4 +48,4 @@ app.include_router(api_router, prefix="") # TODO: make prefix /api/v1
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
return {"status": "ok"}
|
||||
return {"status": "ok"}
|
||||
|
||||
Reference in New Issue
Block a user