LemonRouter (lemon_router v0.1.0)
View SourceLemonRouter provides orchestration and routing for agent runs.
This app is responsible for:
- Session key management and parsing
- Run orchestration and lifecycle
- Stream coalescing for efficient channel output
- Policy merging for tool execution
- Abort handling and run cancellation
- Bridging between channels and gateway
Session Keys
Session keys provide a stable identifier for routing and state:
- Main:
agent:<agent_id>:main - Channel:
agent:<agent_id>:<channel_id>:<account_id>:<peer_kind>:<peer_id>[:thread:<thread_id>]
Architecture
[Channels] -> [Router] -> [Gateway] -> [Engine]
^ |
| v
+--- [StreamCoalescer]
Summary
Functions
Abort a session's active run.
Abort a specific run by ID.
How many run processes are currently supervised.
Every run currently active, newest first is not guaranteed — callers that
care about ordering should sort on :started_at_ms.
Whether the router runtime is up and able to accept work.
Orchestrator run counts.
Delete an endpoint alias.
Apply a watchdog keepalive decision to a specific run.
List agent directory entries with routing/session discoverability metadata.
List persisted endpoint aliases.
List known sessions from the agent directory/phonebook.
List known channel targets (for example Telegram rooms/topics) with friendly labels.
Resolve an agent session selector (:latest, :new, explicit key) to a concrete session.
Whether run_id is currently active.
Send a message to an agent inbox.
Upsert an endpoint alias for an agent.
Submit a run request to the router.
Types
@type active_run() :: %{ run_id: binary(), session_key: binary() | nil, agent_id: binary() | nil, engine: binary() | nil, started_at_ms: integer() | nil }
A run currently being orchestrated.
@type run_counts() :: %{ active: non_neg_integer(), queued: non_neg_integer(), completed_today: non_neg_integer() }
Run counts as reported by the orchestrator.
Functions
Abort a session's active run.
Abort a specific run by ID.
@spec active_run_count() :: non_neg_integer()
How many run processes are currently supervised.
Cheaper than active_runs/0 when only the count is needed; 0 when the
router is not running.
@spec active_runs() :: [active_run()]
Every run currently active, newest first is not guaranteed — callers that
care about ordering should sort on :started_at_ms.
Returns [] when the router is not running.
@spec available?() :: boolean()
Whether the router runtime is up and able to accept work.
Use this instead of probing for a router process by name.
@spec counts() :: run_counts()
Orchestrator run counts.
Always returns the full shape: when the router is not running, every counter is zero rather than the key being absent, so callers can read the fields without guarding.
Delete an endpoint alias.
Apply a watchdog keepalive decision to a specific run.
List agent directory entries with routing/session discoverability metadata.
List persisted endpoint aliases.
List known sessions from the agent directory/phonebook.
List known channel targets (for example Telegram rooms/topics) with friendly labels.
Resolve an agent session selector (:latest, :new, explicit key) to a concrete session.
Whether run_id is currently active.
@spec send_to_agent(binary(), binary(), keyword()) :: {:ok, %{run_id: binary(), session_key: binary(), selector: term()}} | {:error, term()}
Send a message to an agent inbox.
Supports session: :latest | :new | <session_key>.
Upsert an endpoint alias for an agent.
@spec submit(LemonCore.RunRequest.t() | map() | keyword()) :: {:ok, binary()} | {:error, term()}
Submit a run request to the router.
Accepts either a normalized %LemonCore.RunRequest{} or a legacy map/keyword
payload that can be normalized into one.