Deep-Agent runtime
How mucgpt-core-service/app/agent builds and runs the agent. Model profiles are registered once at startup; the agent itself is built per request in init_agent().

Startup (warmup_app())
- ModelRegistry — one chat model per
models[]entry (see Models). - Harness profile per model — enabled Deep Agents built-ins, summarization (80 %, keep 10) only if
enable_summarization, TodoList (ifwrite_todos), per-tool run limits frombuiltin_tool_run_limits(default: 20 calls forread_fileandgrep; configurable per model,nulldisables a limit), sub-agent only if task +enable_subagents. - PromptPool — Langfuse prompts with local
.mdfallbacks (see Prompts). - Postgres —
FencedPostgresSaverandAsyncPostgresStore.
Per request (init_agent())
ToolCollection.get_tools(user)— local + MCP tools (see Tools & MCP).CompositeBackend— state files plus the read-only/documents/mount (see Virtual file system).- Checkpointer only if
persist(otherwise approval tools are removed). MUCGPTAgent→create_deep_agent(...)with the MUCGPT middleware chain: Context → ToolStatus → ToolError → TokenUsage, plus Deep Agents defaults and harness-profile extras. State isDefaultAgentState, context isRequestContext, andinterrupt_oncovers tools that require approval.
Agent loop (one run)
- START: messages (+
data_sources). - Model call:
ContextMiddlewareinjects enabled tools, date,data_sourcesand the prompt;ToolStatusMiddlewareadds thestatus_messageargument;TokenUsageMiddlewarerecords usage. - Tool execution (local · MCP · built-ins):
ToolStatusMiddlewarestripsstatus_messageagain,ToolErrorMiddlewaremaps exceptions to tool messages. - Loop back to the model until no tool calls remain → END with the final answer.
- A tool call that needs approval raises an approval interrupt before the tool runs: the run pauses, the user decides, the run resumes.
- With
persist, a checkpoint is written after every step (thread_id= conversation id).