Skip to content

Server

Foreman FastAPI application and dispatch loop.

CLASS DESCRIPTION
Dispatcher

Orchestrates the harness dispatch loop: fetch memory → build task → POST to agent → execute.

Classes

Dispatcher

Dispatcher(config: ForemanConfig, memory: MemoryStore)

Orchestrates the harness dispatch loop: fetch memory → build task → POST to agent → execute.

One :class:Dispatcher instance is created at startup and shared across the entire process. A per-agent-URL :class:asyncio.Lock ensures that at most one task is dispatched concurrently to any given agent endpoint.

PARAMETER DESCRIPTION
config

Validated :class:~foreman.config.ForemanConfig.

TYPE: ForemanConfig

memory

Open :class:~foreman.memory.MemoryStore instance.

TYPE: MemoryStore

METHOD DESCRIPTION
dispatch

Dispatch event to the agent described by route_target.

Functions

dispatch async
dispatch(event: dict[str, Any], route_target: RouteTarget) -> None

Dispatch event to the agent described by route_target.

Sequence: 1. Acquire per-agent-URL lock (serialise concurrent dispatches). 2. Fetch memory summary for this repo+issue. 3. Build a :class:~foreman.protocol.TaskMessage. 4. POST to route_target.url/task. 5. On non-200 response or network error: log and return. 6. Parse :class:~foreman.protocol.DecisionMessage. 7. Execute actions via :class:~foreman.executor.GitHubExecutor. 8. Write a summary to memory.

PARAMETER DESCRIPTION
event

Poller event dict with repo, issue_number, and payload keys.

TYPE: dict[str, Any]

route_target

Resolved :class:~foreman.routers.agent.RouteTarget.

TYPE: RouteTarget

Functions