Skip to content
Loom Docs
Esc
↑↓navigate↵open⌘Jpreview
Product
View as Markdown
On this page

A document worker beside an account host

An agent that runs beside an account host reads its documents through the host's tool channel, which adds the credential to each call.

An agent that runs beside an account host reads its documents through the host’s tool channel, which adds the credential to each call. This guide sets up the worker that syncs such a source into the agent’s namespace: approve a mapping, assign the source, run the job and read the status. It also says how old a copy can be and what each status asks of whom.

The worker is run_once in the loom-source-worker package (source worker). The host’s job calls it with two functions of its tool channel. The worker holds no credential, opens no listener, starts no model turn and raises no notice: what needs a person is in the summary it returns. The contract of the two functions and the trust of a host connection are in the worker boundary.

Approve a mapping digest

A read mapping is a JSON file that names the tools that list and fetch a connection’s documents and pins each by the digest of its definition. Review the file, then compute its digest with the worker version the job runs:

python - <<'PYTHON'
from pathlib import Path
from loom_source_worker.mapping import digest, load

print(digest(load(Path("mappings/docs.json").read_bytes())))
PYTHON

Put the file in the directory the job passes as mappings_dir. The worker claims only a source whose profile_digest is the digest of a file there, so a mapping nobody put there reads nothing. The directory holds at most 64 mappings, and a file that is not a mapping stops the run with a ValueError.

Assign the source

A namespace administrator, not the agent, assigns the source to the agent’s subject with knowledge.source.worker_assign (a source assigned to a worker subject):

loom knowledge source assign --namespace fleet-scout --name handbook \
  --worker-subject sa:fleet:scout --reader mcp_mapped --ref docs --generation 1 \
  --profile-digest <the digest of step 1> --selection listed --changed-since \
  --item <the container's id>
Field Beside a host
namespace The agent’s own namespace, which is the job’s home_namespace.
reader mcp_mapped.
ref The host’s id of the connection: a lower-case letter or digit, then at most 31 lower-case letters, digits or -. The job’s allowed_refs must name it.
profile_digest The digest of step 1.
selection, changed_since listed with one container id for a mapping that has list, and changed_since as that list declares it; selected with 1 to 1,000 ids for a mapping without list.

Run the job

The job calls run_once on its schedule. One call runs the turns that are due, eight at most (HostLimits.turns), and returns.

from pathlib import Path

from loom_source_worker.host import HostLimits, run_once

summary = await run_once(
    call_tool=call_tool,  # (ref, tool, arguments) -> ToolResult
    list_tools=list_tools,  # (ref) -> list[ToolDefinition]
    mappings_dir=Path("mappings"),
    allowed_refs=frozenset({"docs"}),
    org="acme",
    home_namespace="fleet-scout",
    limits=HostLimits(request_bytes=1_000_000),
)
  • allowed_refs holds the connections a person turned on for indexing at the host, and never a server the host’s platform runs for itself.
  • HostLimits.request_bytes is the channel’s request cap. A document whose upload is longer than the cap less 4,096 bytes is counted too_large and not sent. Leave it unset for a channel with no cap.
  • summary.turns holds one report a turn: its outcome, listing, error, counts and retired. summary.attention names the sources that wait for a person, each with its status and reason. summary.served is false when the server does not serve the turn ops; the worker then sends nothing else and logs one line a day in a process.

What a turn asks of the host’s channel, inside the caps the agent’s own calls share for the agent and for the tenant:

Source Calls a turn
Any One tool listing of the connection
listed One call a listing page, and one fetch for each document whose revision changed, or for every listed document when the mapping’s list has no revision_path
selected One fetch for every selected id, up to 1,000
A stored copy the upstream withdrew One more fetch, and one call that shows the scope still reads

Each turn also sends Loom one claim, the stored pages, one put a changed document, 40 a turn at most, one commit a listing page and a last one.

How old a copy can be

  • One turn per sync interval while the job runs. A source is due LOOM_KNOWLEDGE_SOURCE_SYNC_INTERVAL_SECONDS (900 at the default) after its last turn ended, or LOOM_KNOWLEDGE_SOURCE_SYNC_FULL_INTERVAL_SECONDS (86,400) for a listed source that is not asked for changes. knowledge.source.sync_now makes it due at once. A change reaches Loom on the first run of the job after the source is due.
  • Every hit says its age. A search hit of a copy carries synced_from: the source, the upstream’s title, link and document id, the subject that uploaded it and synced_at, the last time the worker read the source without an error.
  • Copies are retired past the age bound. When no turn ended without an error for LOOM_KNOWLEDGE_SOURCE_WORKER_COPY_MAX_AGE_SECONDS (seven days at the default), Loom retires the source’s copies; the next turn imports them again (how long an unverified source’s copies are served). An agent’s machine that is parked for longer than the bound loses its copies until it runs again.

A deployment can lower the bound to 86,400 seconds once the retirement worker’s silent_over_day count has stayed 0 for four weeks: until then some source goes a day without a turn, and the lower bound would retire its copies. Keep the bound above LOOM_KNOWLEDGE_SOURCE_SYNC_FULL_INTERVAL_SECONDS plus a turn’s bound while a listed source is not asked for changes.

Read the status

knowledge.source.list shows the source’s sync.status to every reader of the namespace, and the dashboard’s source row shows the same. The status table lists every status; this is what each means beside a host and who acts:

status reason Beside a host Remedy
ok, importing The worker reads the source; importing goes on with the job’s next run. None.
needs_reconnect The channel asked for a sign-in, or refused or lacked the credential. Reconnect the account at the host, then run sync_now.
blocked server_off The server is not enabled for the agent. Enable it at the host, then run sync_now.
blocked tool_not_allowed The connection is not in the job’s allowed_refs, its id is not of the form in step 2, or the host’s policy refused a tool. Turn indexing on for the connection at the host, then run sync_now.
blocked mapping_changed The assignment’s selection or changed_since is not the mapping’s, or a mapped tool is missing, not read-only or no longer as its digest pins it. Correct the assignment, or approve the changed mapping (step 1) and assign the source with its digest.
failed rate_limited, upstream_unavailable, timeout, protocol, internal The channel or the upstream failed, or the host’s adapter did not know the error. None: the turn is retried by itself, each wait twice the last up to six hours.
revoked The channel answered that the account’s access was withdrawn; Loom retired the source’s copies. Assign the source again.

A blocked or needs_reconnect source keeps its copies. They are served until the subject that assigned the source removes it (knowledge.source.remove) or the age bound passes.

A source whose profile_digest no file in mappings_dir has is not offered to the worker. No turn starts, its status does not change and sync.verified_at stops moving, so its copies are retired when the age bound passes.

Last updated on

Was this page helpful?