Skip to main content
Middleware for injecting local context into system prompt. Detects git state, project structure, package managers, runtimes, and directory layout by running a bash script via the backend. Because the script executes inside the backend (local shell or remote sandbox), the same detection logic works regardless of where the agent runs.

uom_deep_agent.local_context.build_detect_script

View Source Concatenate all section functions into the full detection script. Independent sections run as parallel background jobs writing to temp files, then results are concatenated in the original display order. The header (CWD / IN_GIT) and project section (sets ROOT) run first because later sections depend on their variables. Returns: Complete bash heredoc ready for backend.execute().

uom_deep_agent.local_context.LocalContextState Objects

View Source State for local context middleware.

LocalContextState.local_context: NotRequired[str]

Formatted local context: cwd, project, package managers, runtimes, git, test command, files, tree, Makefile.

uom_deep_agent.local_context.LocalContextMiddleware Objects

View Source Inject local context (git state, project structure, etc.) into the system prompt. Runs a bash detection script via backend.execute() on first interaction and again after each summarization event, stores the result in state, and appends it to the system prompt on every model call. Because the script runs inside the backend, it works for both local shells and remote sandboxes.

LocalContextMiddleware.__init__

View Source Initialize with a backend that supports shell execution. Arguments:
  • backend - Backend instance that provides shell command execution.

LocalContextMiddleware.before_agent

View Source Run context detection on first interaction and refresh after summarization. On the first invocation, runs the detection script and stores the result. After a summarization event (indicated by a new _summarization_event in state), re-runs the script to capture any environment changes that occurred during the session. Arguments:
  • state - Current agent state.
  • runtime - Runtime context.
Returns: State update with local_context populated on success. On a post-summarization refresh failure, returns a state update recording the cutoff (without local_context) to prevent retry loops. Returns None if context is already set and no refresh is needed, or if initial detection fails.

LocalContextMiddleware.wrap_model_call

View Source Inject local context into system prompt. Arguments:
  • request - The model request being processed.
  • handler - The handler function to call with the modified request.
Returns: The model response from the handler.

LocalContextMiddleware.awrap_model_call

View Source Inject local context into system prompt (async). Arguments:
  • request - The model request being processed.
  • handler - The async handler function to call with the modified request.
Returns: The model response from the handler.