CLI <-> Backend Communication
This page details the communication mechanism between the JuliaOS frontends (CLI, Python Wrapper) and the Julia backend server.
Overview
Communication relies on a client-server model where frontends act as clients sending requests to the Julia backend server.
Server: The Julia backend (
julia/julia_server.jl
) runs an HTTP server (usingHTTP.jl
) listening on a specific port (default: 8052). A WebSocket server on port 8053 is prepared but currently disabled in the code.Clients: The Node.js CLI (
packages/cli/
) and the Python Wrapper (packages/python-wrapper/
) initiate connections to the HTTP server.Bridge Component: A dedicated component within the clients (e.g.,
@juliaos/julia-bridge
in Node.js, or internal HTTP client in Python) handles formatting requests, sending them, and parsing responses.Protocol: Communication uses HTTP POST requests to the
/api/command
endpoint. Payloads are JSON objects containing acommand
string (e.g.,"agents.create_agent"
) and aparams
orpayload
object/array containing arguments.
Request/Response Flow
Client Action: User interacts with the CLI or calls a Python API function.
Bridge Formatting: The client-side bridge constructs a JSON payload.
HTTP Request: The bridge sends an HTTP POST request to
http://<backend_host>:8052/api/command
with the JSON payload.Server Receives: The Julia HTTP server (
julia_server.jl
) receives the request at the/api/command
route.Command Parsing: The server parses the JSON body to extract the
command
string andparams
/payload
.Command Handling: The server's command handler (likely defined in
julia_server.jl
or a dedicated command module) looks up the function associated with thecommand
string in a registry (likeBridge.command_handlers
).Backend Logic: The registered handler function (e.g.,
AgentSystem.handle_create_agent(...)
) is called with the parameters from the payload.Response Formatting: The handler function returns a result (e.g., data object or error).
HTTP Response: The Julia server sends an HTTP response (typically JSON) back to the client bridge, often wrapping the result.
Bridge Parsing: The client-side bridge receives the HTTP response and parses the JSON, checking for errors.
Client Update: The result data or error is returned to the original caller (CLI displays message, Python function returns value or raises exception).
Communication Diagram
Key Components
/julia/julia_server.jl
: Contains the HTTP server (HTTP.jl
), routing for/api/command
, request parsing, and command dispatch logic./julia/src/Bridge.jl
: Defines request/response structs, manages thecommand_handlers
registry, provides utility functions (get_token_address
,execute_trade
,submit_signed_transaction
), and handles the corerun_command
logic.Client Libraries (
/packages/julia-bridge/
or Python internal): Responsible for making the HTTP POST calls and handling responses on the client side.