Introducing a new way to review your PRs.

Read the announcement

getnao / nao

👾 nao is the #1 open source agentic BI. (1) Create context with nao-core cli, (2) deploy nao chat interface for everyone

View on GitHub

23 documents · Updated Nov 23, 2026

docs / agent-tools-memory-and-prompts

Agent tools, memory, and prompt policy

The agent combines a context-aware tool surface with project guidance and user-specific context. A run receives only the tools allowed for its mode and access grants, while its system prompt joins product policy, project rules, skills, persistent memory, and the current tool set. MCP (Model Context Protocol) clients can use the same context and data tools or delegate a full task to a persisted agent chat. This lets the same agent support data work, file work, code execution, stories, visual outputs, external services, automation, onboarding, and focused subagent tasks without giving every run the same powers. See Agent and chat for the product-level chat view and Agent runtime for the run lifecycle.

Agent tool surface

The tool surface is the agent's action boundary. It includes tools for finding and reading project context, querying data, running code in an isolated sandbox, creating displays and stories, changing saved files, asking for clarification, delegating work, managing automations, onboarding projects, and reaching approved MCP services. The run builder removes tools that the current mode, deployment, feature flag, storage layer, or user access does not support. apps/…/index.ts• L43-63, apps/…/index.ts• L65-117

The surface is not a fixed list. An agent run can receive a focused allowlist or exclusions, and tools can change their descriptions to match the available surface. Query tools can separate governed semantic queries from raw SQL, file tools can target project or user-owned storage, code tools can use an available sandbox, and story tools can support either classic documents or custom story files. apps/…/index.ts• L145-191, apps/…/execute-semantic-query.ts• L10-22, apps/…/execute-sql.ts• L221-265, apps/…/story.ts• L48-87

Core tool groups

The main tool groups describe the product actions available to an agent:

GroupPurpose
Context toolsFind and read project files, database definitions, stories, and other context.
Data toolsRun SQL or governed semantic queries and work with query results.
Compute toolsRun user-requested code in an isolated environment with selected inputs and outputs.
Output toolsShow charts, maps, or tables, create or update stories and saved files, and refine visual displays.
Control toolsAsk one focused clarification, suggest follow-up work, or delegate a self-contained task.
Extension toolsLoad skills and call approved MCP services.
Automation toolsRead automations, inspect run history, and change approved automation fields.
Onboarding toolsGuide setup flows when the run is explicitly an onboarding run.

Each group supports a different part of the agent loop. Context tools establish what the request means. Data and compute tools act on that understanding. Output tools turn the result into something the user can inspect or save. Control tools manage uncertainty or scope, while extension, automation, and onboarding tools add task-specific guidance or approved actions. apps/…/index.ts• L43-63, apps/…/index.ts• L11-25, apps/…/automation-editor.tsx• L8-16

The control surface also supports context-quality work. A recommendation agent can propose one exact change for a human-written context file or record guidance for a manual change when the source is generated or not linked to a code host. Each recommendation stays independent so one fix cannot silently include another fix. apps/…/propose-context-fix.ts• L73-80, apps/…/propose-context-fix.ts• L101-179

Follow-up suggestions are a terminal action rather than a side note. The agent must first provide a complete visible answer and then use the tool as its only final tool call. apps/…/suggest-follow-ups.ts• L4-20

Onboarding tools

Onboarding tools guide a new project through user choices, secure warehouse setup, and business-context capture. They keep sensitive connection values in a form rather than in chat, record progress, and wait for background setup to finish before the project generates its first RULES.md. Some tools end the turn so the next user action can control the next step. apps/…/index.ts• L11-25, apps/…/request-warehouse-credentials.ts• L4-18, apps/…/generate-onboarding-rules.ts• L6-28, apps/…/wait-for-warehouse-setup.ts• L7-23

The onboarding surface also supports recovery and local-agent handoff. A user can restart a stopped setup or receive an exact prompt or terminal command in a copyable presentation. This keeps setup state explicit instead of asking the model to infer whether an external step succeeded. apps/…/retry-warehouse-setup.ts• L6-30, apps/…/restart-onboarding.ts• L6-19, apps/…/onboarding-agent-prompt.ts• L4-13, apps/…/onboarding-command.ts• L4-13

References: apps/…/index.ts• L11-25 apps/…/request-warehouse-selection.ts• L4-13 apps/…/request-warehouse-credentials.ts• L4-18 apps/…/generate-onboarding-rules.ts• L6-28 apps/…/wait-for-warehouse-setup.ts• L7-23 apps/…/retry-warehouse-setup.ts• L6-30 apps/…/restart-onboarding.ts• L6-19

Data tools preserve a common query result that later displays and stories can use. A semantic query compiles governed metrics, dimensions, and filters before execution. Raw SQL can read local files and earlier results, while warehouse SQL remains subject to the project's mode and write policy. A result keeps a query ID so the agent can reshape it, page through it, or use it in a chart, table, map, or story. Semantic results must be changed by running the semantic query again rather than by editing their compiled SQL. apps/…/execute-semantic-query.ts• L10-37, apps/…/execute-sql.ts• L32-112, apps/…/execute-sql.ts• L169-228, apps/…/page-query-result.ts• L8-46

Code execution

Sandboxed code execution gives the agent a bounded way to transform data or produce files without running code in the main service. The sandbox can receive selected project context, chat images, saved user files, and earlier query results. Successful outputs can be copied back to user storage, while secrets are available only to the sandbox process and are removed from returned output. apps/…/execute-sandboxed-code.ts• L175-245, apps/…/execute-sandboxed-code.ts• L264-316, apps/…/execute-sandboxed-code.ts• L324-403

Sandbox sessions can be reused by the same user and project for a short period. The ownership key prevents one context from reusing another context's files or secrets, and the run is serialized per sandbox. Project rules are rendered through the same access-aware view before they enter the sandbox. apps/…/execute-sandboxed-code.ts• L41-125, apps/…/execute-sandboxed-code.ts• L180-224, apps/…/execute-sandboxed-code.ts• L406-524

References: apps/…/execute-sandboxed-code.ts• L41-125 apps/…/execute-sandboxed-code.ts• L175-245 apps/…/execute-sandboxed-code.ts• L264-403 apps/…/execute-sandboxed-code.ts• L406-524

The grep tool gives the agent a project-scoped view of text context. A pattern can search the project folder, user storage, mounted stories, and the story library when the pattern targets those sources. Path checks, ignore rules, and rendered rule views keep results inside the permitted context and prevent hidden project rules from exposing content the user cannot access. apps/…/grep.ts• L68-94, apps/…/grep.ts• L96-178, apps/…/grep.ts• L284-432

The read tool turns permitted project, storage, mounted story, and story-library paths into model-readable text. It also makes supported binary documents readable and can attach nearby table annotations. Project reads stay inside the project and verify the opened file's identity and stability before returning it, so context lookup is both useful to the model and bounded by the access policy. apps/…/read.ts• L25-80, apps/…/read.ts• L93-123, apps/…/read.ts• L177-208

The list tool gives the agent a safe directory view that matches the same context boundary. Its project root can expose enabled user storage, custom story drafts, and the story library as virtual mounts, while hidden or disallowed entries remain absent. apps/…/list.ts• L31-53, apps/…/list.ts• L67-85, apps/…/list.ts• L150-160

Output tools support a review loop rather than only a one-time display. The client can show a chart, table, map, query, story status, or automation change; let the user change an allowed configuration; and save the accepted result back to the chat, story, or automation. Charts can be viewed as a visualization, source data, or SQL, exported, edited, and added to classic or custom stories when the target supports the output. apps/…/display-chart.tsx• L72-120, apps/…/display-chart.tsx• L220-277, apps/…/automation-editor.tsx• L22-49

Chart output accepts a prior query result and checks that the requested display has enough information to render. Built-in charts require their needed axis and series shape, while custom charts require both interactive-chat support and a project chart plug-in. This prevents a display request from claiming success when the current surface cannot render it. apps/…/display-chart.ts• L9-45, apps/…/display-chart.ts• L47-78

References: apps/…/display-chart.ts• L9-45 apps/…/display-chart.ts• L47-82 apps/…/display-chart.tsx• L72-120 apps/…/display-chart.tsx• L220-277 apps/…/automation-editor.tsx• L22-49

Story tools create and revise either classic stories or custom story applications. Classic stories use versioned document content with chart, table, map, grid, and tab blocks. They can also bind user filters and parameters to later data refreshes when the story declares the matching query and display rules. Custom stories use a draft file set that must build before publication. File edits to custom stories use exact replacements or file changes, while project context and the story library remain read-only. Story edits use locks and version checks so an agent does not silently overwrite a concurrent change. apps/…/story.ts• L29-79, apps/…/story.ts• L126-157, apps/…/story.ts• L239-277, apps/…/story.ts• L325-468

References: apps/…/index.ts• L43-191 apps/…/execute-semantic-query.ts• L10-37 apps/…/execute-sql.ts• L32-138 apps/…/grep.ts• L68-94 apps/…/read.ts• L25-123 apps/…/list.ts• L31-160 apps/…/execute-sandboxed-code.ts• L406-524 apps/…/story.ts• L29-87 apps/…/story.ts• L126-157 apps/…/story.ts• L239-277 apps/…/propose-context-fix.ts• L73-179 apps/…/suggest-follow-ups.ts• L4-20 apps/…/index.ts• L11-25 apps/…/automation-editor.tsx• L8-87 apps/…/display-chart.tsx• L72-277

MCP entry points

The MCP context layer exposes a small, task-oriented view of the agent surface to external clients. It offers file listing, search, file reads, SQL, semantic queries when enabled, and classic or custom story actions. Each tool description guides the caller toward context discovery before a query and toward governed metrics when the question uses the semantic layer. apps/…/context-layer.ts• L46-80, apps/…/context-layer.ts• L125-215

Query results keep a reusable query_id and can be linked to an authorized chat. The result data is cached so later chart and story actions can reuse it without making the caller send the rows again. SQL exposure changes with project configuration: warehouse database selection is validated when needed, while a project without warehouse SQL accepts only local SQL. apps/…/context-layer.ts• L168-289, apps/…/context-layer.ts• L223-239

Story actions keep the same high-level product contract for external clients. Classic stories use full markdown content with embedded output blocks, while custom stories use files and build-aware updates. Chat-linked operations verify that the chat belongs to the caller and project, and updates create a new version rather than changing an old one in place. apps/…/context-layer.ts• L295-460, apps/…/context-layer.ts• L531-625

An MCP client can call ask_nao when it wants the full reasoning loop instead of managing each step. The sub-agent reads project context, runs queries, builds outputs, and persists the work as a chat. A short run returns its answer; a longer run returns running with a chat ID for polling. An unclear request returns needs_clarification, which the caller sends back with the same chat ID. Completed results include query summaries and links to created or updated stories. apps/…/sub-agent.ts• L44-81, apps/…/sub-agent.ts• L129-244, apps/…/sub-agent.ts• L279-368, apps/…/sub-agent.ts• L417-472

Direct MCP calls still use the agent's access model. A requested chat ID is accepted only when it belongs to the calling user and project; otherwise the tool runs without a chat. This keeps query results, story links, and follow-up work attached only to an authorized context. apps/…/run-agent-tool.ts• L8-31, apps/…/context-layer.ts• L535-573, apps/…/sub-agent.ts• L385-390

References: apps/…/context-layer.ts• L46-80 apps/…/context-layer.ts• L125-289 apps/…/context-layer.ts• L295-460 apps/…/context-layer.ts• L476-500 apps/…/context-layer.ts• L531-625 apps/…/custom-story-mcp.ts• L37-55 apps/…/sub-agent.ts• L44-81 apps/…/sub-agent.ts• L129-244 apps/…/sub-agent.ts• L279-368 apps/…/run-agent-tool.ts• L8-31

Tool result presentation

The client maps tool names to focused views so tool use remains understandable during and after a run. Read results show the source context and line count, structured MCP reads show the server and operation, and internal skill or follow-up calls stay out of the main conversation because they are guidance rather than user-facing work. apps/…/read.tsx• L12-79, apps/…/read.tsx• L102-112, apps/…/index.tsx• L84-115

Charts keep the query, data, and display configuration linked. Users can switch between chart, data, and query views, edit supported built-in charts, export data, and add the accepted result to the current story. A chart added to a custom story becomes a story-kit block, while a classic story receives a chart block. apps/…/display-chart.tsx• L220-277, apps/…/display-chart.tsx• L398-457

Automation results use the same tool-call view to show the user what changed. The view names changed fields such as instructions, schedule, triggers, and delivery targets, while run history reports the number of past runs. This makes an automation update reviewable without exposing the full internal tool payload. apps/…/automation-editor.tsx• L18-49, apps/…/automation-editor.tsx• L53-97

References: apps/…/index.tsx• L40-115 apps/…/read.tsx• L12-123 apps/…/display-chart.tsx• L72-120 apps/…/display-chart.tsx• L220-277 apps/…/display-chart.tsx• L398-457 apps/…/display-chart.test.tsx• L20-75 apps/…/automation-editor.tsx• L18-97

Access boundaries

User-group access controls both what the agent can call and what the prompt says it may do. Database, file, document, MCP, skill, story, and automation access are resolved before the run. Feature restrictions are then added to the system prompt when a relevant action is unavailable, so the agent does not offer or attempt a blocked capability. apps/…/user-group-context-access.service.ts• L34-70, apps/…/user-group-feature-access.service.ts• L124-142

The boundary also applies to data and saved content. Warehouse SQL can be disabled while semantic queries remain available. Story creation, custom story authoring, storage edits, and story-library access each have separate checks. The client exposes editing only when the agent is not read-only or still running, but the backend remains the final authority. apps/…/execute-sql.ts• L37-73, apps/…/story.ts• L172-179, apps/…/story.ts• L293-301, apps/…/display-chart.tsx• L112-118

The boundary also applies to code and external services. Sandbox use requires the run's experimental setting and an available runtime. MCP tools are not placed in context by default. The agent first discovers a server's tool specification, then calls the named operation with validated arguments. If the user's account is not connected, the flow stops and asks the user to connect it instead of retrying. apps/…/load-skill.ts• L42-45, apps/…/execute-sandboxed-code.ts• L406-417, apps/…/mcp-call.ts• L7-30, apps/…/mcp-connect.ts• L8-15, apps/…/mcp.tsx• L206-243

References: apps/…/index.ts• L82-135 apps/…/user-group-context-access.service.ts• L34-70 apps/…/user-group-feature-access.service.ts• L124-142 apps/…/execute-sql.ts• L37-73 apps/…/load-skill.ts• L42-45 apps/…/execute-sandboxed-code.ts• L406-417 apps/…/story.ts• L172-179 apps/…/story.ts• L293-301 apps/…/mcp-call.ts• L7-30 apps/…/mcp-connect.ts• L8-15 apps/…/display-chart.tsx• L112-118 apps/…/mcp.tsx• L206-243

Skill loading

A skill is a playbook that explains work the tools alone do not explain well. The prompt lists available project skills and built-in skills with a short description. The agent loads a relevant body before starting that work. Project skills can be preloaded for a user group, but long preloaded content is capped and may be truncated; on-demand skills keep the normal prompt smaller. apps/…/skill.ts• L25-28, apps/…/skill.ts• L106-138, apps/…/system-prompt.tsx• L374-401

Project skills are subject to the same grant and path checks as other project context. A project skill with the same name as a built-in skill takes precedence when it is available to the run. A skill reports only capabilities that the current run can use, such as sandbox access, so its guidance does not promise an unavailable action. apps/…/load-skill.ts• L16-45, apps/…/load-skill.ts• L48-81

References: apps/…/skill.ts• L25-28 apps/…/skill.ts• L106-138 apps/…/load-skill.ts• L16-45 apps/…/load-skill.ts• L48-81 apps/…/system-prompt.tsx• L374-401

Delegated tasks

The task tool starts a subagent with a fresh context and returns its report to the parent agent. The parent must provide a self-contained prompt because the subagent does not see the current conversation. This keeps broad exploration from filling the parent context while preserving a clear handoff between the two runs. apps/…/task.ts• L6-24

The explore subagent is a focused example. It uses read-only context tools and receives project context plus applicable user rules. The parent should use it for discovery that needs more than a few direct lookups, then verify only the findings needed for the answer. apps/…/explore.ts• L14-33

References: apps/…/task.ts• L6-24 apps/…/explore.ts• L14-33

Prompt policy

The system prompt is the policy layer for an agent run. It describes the agent's role, the safe way to use the current tool surface, the project's context model, and the output rules that apply to the client. The prompt is built from the run's actual tools and context, so instructions do not promise actions the run cannot perform. apps/…/system-prompt.tsx• L72-123, apps/…/agent.ts• L718-767

Prompt composition

Prompt construction follows a clear precedence path. A project can provide a provider-specific prompt override or a default agent/…/system.md. An override can replace the default completely, or it can include {{ nao_prompt }} to embed the generated default. The agent profile may then append a profile-specific policy, and user-group restrictions are added after that. apps/…/system-prompts.ts• L20-35, apps/…/agent.ts• L704-715, apps/…/agent.ts• L689-693

The generated default prompt joins the context that shapes execution. It includes user rules, available connections, granted skills, preloaded skills, enabled MCP servers, selected memories, and tool-dependent options. The current tool names control which instructions appear, so a focused run receives a smaller and more accurate policy. apps/…/agent.ts• L718-767

References: apps/…/system-prompts.ts• L20-35 apps/…/agent.ts• L689-715 apps/…/agent.ts• L718-767 apps/…/system-prompt.tsx• L32-100

This diagram shows how access and context become the final policy sent with the conversation.

flowchart TD
    A[Project and user access] --> B[Allowed tool surface]
    A --> C[Rules, skills, and connections]
    D[Persistent memory] --> E[Generated default prompt]
    B --> E
    C --> E
    E --> F[Project prompt override]
    F --> G[Profile appendix]
    G --> H[User-group restrictions]
    H --> I[Agent model]

References: apps/…/system-prompts.ts• L20-35 apps/…/agent.ts• L689-767 apps/…/system-prompt.tsx• L32-100

Project rules

RULES.md is the project-level rule source. The agent reads it as user guidance and applies the access-aware rendered form, so rules can be narrowed to the user's groups before they enter the prompt. The same rendered view is used when project rules are searched or copied into a sandbox, and the same rules guide the explore subagent. apps/…/user-rules.ts• L13-35, apps/…/grep.ts• L151-161, apps/…/execute-sandboxed-code.ts• L180-224, apps/…/explore.ts• L23-32

Project rules are different from persistent memory. Rules describe the project's working policy and can include access-sensitive project guidance. Memory describes facts or durable preferences tied to the user and is enabled separately. Database context is also filtered before it becomes prompt context, so table and column guidance does not bypass data access policy. Keeping these sources distinct makes it clear whether a behavior comes from the project or from the person using it. apps/…/user-rules.ts• L92-129, apps/…/user-rules.ts• L352-410

References: apps/…/user-rules.ts• L13-35 apps/…/user-rules.ts• L92-129 apps/…/user-rules.ts• L352-410 apps/…/agent-visible-project-file.service.ts• L1-29 apps/…/grep.ts• L151-161 apps/…/execute-sandboxed-code.ts• L180-224 apps/…/explore.ts• L23-32

System prompt overrides

A system prompt override is a project-owned policy document selected by provider when present. The reader rejects empty files and refuses paths that resolve outside the project folder. A provider-specific file takes priority over the shared default, which lets a project adapt policy to a model family without changing the agent's core prompt builder. apps/…/system-prompts.ts• L20-59

The placeholder is the safe composition point. A full override without {{ nao_prompt }} replaces the generated default, while an override with the placeholder keeps the generated agent policy and adds project wording around it. This choice is important because a full replacement can omit core operating rules. apps/…/system-prompts.ts• L10-18, apps/…/agent.ts• L704-715

References: apps/…/system-prompts.ts• L10-18 apps/…/system-prompts.ts• L20-59 apps/…/agent.ts• L704-715

Well-formed prompt construction

Before a model request is sent, the provider wrapper repairs malformed strings throughout the prompt value. In particular, lone UTF-16 surrogate values become the replacement character instead of producing invalid JSON for strict providers. This protects later turns because the full stored history can be sent again after one malformed message. apps/…/well-formed-prompt.ts• L5-29, apps/…/providers.ts• L242-248

References: apps/…/well-formed-prompt.ts• L5-29 apps/…/providers.ts• L242-248

Prompt caching

Prompt caching reduces repeated input work for providers that support it without changing the agent's instructions. The system prompt receives a long-lived cache point, while recent conversation content receives shorter-lived points. The cache helper applies the matching provider format only to direct Anthropic models and Anthropic Claude models reached through Vertex, OpenRouter, or Bedrock. apps/…/prompt-cache.ts• L15-56, apps/…/agent.ts• L460-472

Chat artifacts are appended to the latest user turn, so the cache boundary is placed immediately before that changing block. The preceding user turn is marked again on later turns, which keeps a stable prefix available even when a tool loop adds messages between user turns. The provider tests verify that this prefix remains stable across turns and that the number of cache points stays within the provider limit. apps/…/prompt-cache.ts• L58-99, apps/…/prompt-cache-artifacts.test.ts• L30-81

References: apps/…/prompt-cache.ts• L15-56 apps/…/prompt-cache.ts• L58-118 apps/…/prompt-cache-artifacts.test.ts• L30-81

Persistent memory

Persistent memory carries selected user instructions and user facts from one conversation into later agent runs. It is a user-level aid rather than a transcript store: only active memories are injected, and the project and user must both allow memory. apps/…/memory.ts• L21-45, apps/…/memory.ts• L7-50

Memory categories

The memory policy separates behavior instructions from profile facts:

CategoryMeaningExtraction standard
Global user ruleA durable instruction for future conversations.Requires a clear permanence signal and a meaningful effect on future behavior.
Personal factA stable fact about the user such as role, company, language, or location.Can be saved when it is useful and not already present.

The extractor defaults to no change. A one-off request, temporary context, or uncertain preference stays in the current conversation. When a new fact or rule replaces an old one, the extractor identifies the old memory so the service can supersede it instead of leaving conflicting active memories. apps/…/memory-system-prompt.tsx• L15-20, apps/…/memory-system-prompt.tsx• L65-109, apps/…/memory.ts• L7-16

References: apps/…/memory-system-prompt.tsx• L15-20 apps/…/memory-system-prompt.tsx• L65-109 apps/…/memory.ts• L7-16

Memory extraction flow

Memory extraction runs after a user message as background work. It reviews recent conversation text together with the active memory list, returns structured instructions and profile facts, and persists only valid additions or replacements. The next eligible agent run reads the active results into its system prompt. apps/…/memory.ts• L47-102, apps/…/memory-extractor-llm.ts• L26-58

This diagram shows the separation between the user-facing agent turn and the later memory update.

sequenceDiagram
    participant User
    participant Agent
    participant Memory as Memory service
    participant Store as Active memory store
    participant Extractor as Extraction model

    User->>Agent: Send message
    Agent->>Store: Read active memories when enabled
    Store-->>Agent: Rules and profile facts
    Agent-->>User: Complete the current turn
    Agent-)Memory: Schedule extraction
    Memory->>Store: Read active memories
    Memory->>Extractor: Review recent conversation and memories
    Extractor-->>Memory: New or superseding memories
    Memory->>Store: Save changes

The extractor uses a bounded recent conversation and a separate current-memory message. It returns both memory categories as structured data. A superseding record marks the old record inactive, so later prompt assembly does not present an obsolete version as active. apps/…/memory-extractor-llm.ts• L20-24, apps/…/memory.ts• L52-80

References: apps/…/memory.ts• L47-102 apps/…/memory-extractor-llm.ts• L26-58 apps/…/memory-extractor-llm.ts• L60-83 apps/…/memory.ts• L52-80

Memory prompt placement

Active memories appear near the end of the generated project context under a dedicated Memory section. Global rules have priority over personal facts, and only memories that fit the prompt token budget are included. The prompt tells the agent that later user instructions can make an earlier memory obsolete. apps/…/system-prompt.tsx• L983-1036

References: apps/…/system-prompt.tsx• L983-1036 apps/…/agent.ts• L718-767

Execution relationships

The agent uses the tool surface and prompt policy together. The prompt tells the model what a tool means and when to use it, while the tool builder remains the hard boundary that decides whether the call can exist. Skills add narrow operating guidance, rules add project policy, and memory adds user context. None of these sources replaces access checks.

The resulting execution pattern is:

  1. Resolve the user's project access and the run's mode.
  2. Build the allowed tools and any surface-specific descriptions.
  3. Assemble the default prompt from policy and available context.
  4. Apply project overrides, profile policy, and user-group restrictions.
  5. Prepare the provider-specific prompt with cache markers and normalize it before sending it to the selected model.
  6. Let the agent use tools, run bounded code, load relevant skills, or delegate bounded work.
  7. Render query results as client output, allow supported edits, and persist accepted chart, map, table, story, or automation changes.
  8. Schedule memory extraction after the turn when memory is enabled.

The client-side output loop keeps the tool result and saved artifact aligned. A chart or table edit updates the chat view before persistence and reports a save error instead of hiding the failed change. Story additions convert the accepted output into the target story format, while custom story publication reports build errors instead of exposing an unfinished version. apps/…/display-chart.tsx• L220-277, apps/…/story.ts• L426-468, apps/…/custom-story-mcp.ts• L245-269

This relationship matters when a feature changes. A new capability is incomplete if it adds a callable tool but does not add the matching prompt guidance, access rule, client output path, or MCP contract when external clients can use it.

References: apps/…/index.ts• L82-229 apps/…/agent.ts• L689-715 apps/…/agent.ts• L718-767 apps/…/user-group-feature-access.service.ts• L124-142 apps/…/prompt-cache.ts• L24-39 apps/…/providers.ts• L242-248 apps/…/execute-sandboxed-code.ts• L406-524 apps/…/execute-sql.ts• L32-112 apps/…/story.ts• L426-468 apps/…/context-layer.ts• L292-457 apps/…/sub-agent.ts• L129-244 apps/…/display-chart.tsx• L220-277 apps/…/automation-editor.tsx• L22-49

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep getTools conditions aligned with the tool-dependent sections in SystemPrompt; otherwise the agent can receive instructions for a tool it cannot call.
  • Keep user-group feature restrictions aligned with both tool availability and the actions described in the prompt.
  • When changing skill names, grants, locations, or skill capabilities, update the prompt catalog and the load-time access checks together.
  • When changing sandbox inputs or outputs, keep project and storage path checks, query-result access, secret redaction, ownership, and saved-file behavior aligned.
  • When changing memory categories or extraction output, update the extractor prompt, schema, active-memory query, and prompt rendering as one contract.
  • When changing project rules, keep the prompt view, grep view, sandbox copy, database context, and group filtering aligned.
  • When changing prompt overrides, preserve the {{ nao_prompt }} composition behavior and the project-folder path boundary.
  • When adding a new model provider, keep the well-formed prompt wrapper and prompt-cache selection on every model construction path.
  • When changing chat artifact placement or tool-loop message order, keep the cache boundary before the artifacts and within the provider's cache-point limit.
  • When changing query modes, keep the tool description, warehouse and local execution guards, query-result reuse, and semantic-query edit path aligned.
  • When changing query paging or display validation, keep query IDs, cached-result limits, chart capability checks, and the client render path aligned.
  • When changing story filters or parameters, update the tool guidance, query templates, story validation, and chart or table tags together.
  • When changing classic or custom story actions, keep version state, draft files, publish status, locks, and client action labels aligned.
  • When changing searchable context mounts, preserve path sanitization, ignore rules, rendered rules, and access checks for each source.
  • When changing storage or custom story editing, keep the tool description, exact-replacement behavior, file locks, and read-only boundaries aligned.
  • When extending agent-created visual outputs, keep the tool message state, saved configuration mutation, and preview validation aligned.
  • When changing chart configuration fields, keep interactive rendering, title semantics, and export-safe number-format validation aligned.
  • When changing MCP context or story tools, keep input schemas, access checks, reusable query data, and structured output contracts aligned.
  • When changing ask_nao, keep synchronous timeout behavior, polling states, clarification handoff, persisted chat recovery, and story links aligned.
  • When changing tool-call rendering, keep static and dynamic tool-name maps aligned and keep internal guidance calls hidden from the user view.
  • When changing automation fields, keep the field labels and result summary aligned with the fields that the agent can update.
  • When changing onboarding actions, keep turn-ending behavior, secure credential forms, setup status polling, retry behavior, and generated project rules aligned.
  • When changing context recommendation fixes, preserve per-recommendation isolation and the boundary between human-written edits and manual guidance.
  • When changing follow-up suggestions, preserve the requirement for a complete visible answer before the terminal tool call.

Important failure modes

TriggerConsequenceGuard
A tool is added without matching access or prompt policy.The agent may offer an action that the run cannot perform, or users may lose needed guidance.Build the tool through getTools and derive prompt rules from the final tool names.
Code execution is requested when the sandbox runtime or run setting is unavailable.The action fails instead of running code in the main service.Expose the tool only when sandbox support and the experimental setting allow it.
A reused sandbox belongs to another user or project.Files or secrets could cross context boundaries.Key pooled sandboxes by user and project and serialize access per sandbox.
Code writes a file outside the sandbox output area or saves a path rather than a file name.The result is not saved and the tool returns an error.Write kept files to the output directory and accept only safe single-file names under user storage.
Sandbox output contains a resolved secret.Sensitive values could enter the agent context.Pass secrets only as environment values and redact them from standard output and errors.
A grep target resolves outside the allowed project or storage root.The search result is dropped or the request is rejected.Canonicalize display paths and apply the source-specific access checks.
A grep search matches hidden rule content that is not allowed for the user.The agent can receive project policy from another group.Search the rendered rules view and retain source-to-visible-line mapping.
A project file changes path or content while the read tool verifies it.The read is rejected rather than returning content from an unapproved file.Keep project reads inside the allowed root and verify the opened file before returning it.
Raw SQL is used where the project allows warehouse access only through the semantic layer.The query is rejected even though the same metric may be available through governed query execution.Use execute_semantic_query for warehouse metrics and reserve local SQL for files or earlier results.
A semantic query is edited as compiled SQL.The result can no longer reflect the governed metric definition.Re-run the semantic query with changed metrics, dimensions, or filters.
Multiple warehouse databases are configured and database_id is missing or unknown.The MCP SQL call is rejected before it can run against the wrong database.Select one of the database IDs reported by the tool schema.
An MCP call uses an undiscovered or malformed schema.The external call fails before dispatch or the agent repeats invalid arguments.Connect or discover the server first, then read the operation schema and fix validation errors.
An MCP caller supplies another user's chat ID.The tool runs without that chat or refuses the operation instead of exposing its messages or data.Accept a chat only after ownership and project checks.
A project skill is outside the granted path or group.The skill is unavailable and its existence is not exposed.Apply both the skill grant and project-context path checks.
A skill promises sandbox behavior when the run cannot call the sandbox.The agent follows guidance for an unavailable action.Build skill capability text from the same sandbox availability check as the tool surface.
A short-lived request is stored as memory.Future conversations receive unwanted behavior or irrelevant facts.Require permanence signals for instructions and default to no extraction when intent is unclear.
A memory replacement does not supersede the old record.Conflicting active instructions can enter later prompts.Persist the new memory with the existing memory id as its superseded record.
A full prompt override omits core policy by mistake.The agent loses default tool, context, or output rules.Use {{ nao_prompt }} when the override should retain generated policy.
A stored message contains a lone UTF-16 surrogate.A strict model provider rejects the request and later turns can remain broken.Normalize the complete prompt through withWellFormedPrompt.
A changing artifact block or long tool loop moves the cache boundary.Later turns lose the stable cached prefix or exceed the provider's cache-point limit.Reapply the previous-turn marker and place the current boundary before the artifacts.
A story query uses invalid filter or parameter syntax.A story may render stale data or report template warnings instead of applying the requested control.Keep filter blocks, semantic dimensions, parameter placeholders, and chart tags consistent.
A custom story is published before its draft builds.The live story remains unchanged and the agent receives build errors.Edit the draft files, then publish only after the bundle builds.
A file edit targets project context or the read-only story library.The edit is rejected rather than changing protected content.Edit only permitted storage or custom story paths through the supported file tool.
A chart or map edit updates only the client view or only the saved configuration.The chat can show stale output after the user saves a change.Apply the edit to the tool message and persist the same validated configuration together.
A chart format is valid for the interactive chart but not the story export.Save is blocked or the interactive chart and exported story show different values.Validate chart formats against the export-safe set before saving.
An ask_nao run exceeds the MCP request budget and the caller does not poll.The caller sees no final answer even though the persisted agent run continues.Poll get_nao_answer with the returned chat ID until the status is complete or error.
A clarification answer starts a new chat instead of continuing the same one.The sub-agent loses the context needed to resolve the user's question.Relay the answer through ask_nao with the same chat ID.
A tool call has no matching client renderer or uses a stale tool name.The user sees a generic or missing result instead of the useful tool state.Keep static and dynamic tool-name maps synchronized with the available tools.
A chart request lacks the axis or series shape required by its chart type.The tool rejects the display instead of producing a misleading chart.Validate the chart type, axis, and series count before recording the generated artifact.
A paging request uses a made-up or missing query ID.The agent cannot inspect the cached result and may repeat a query unnecessarily.Use the query ID returned by execute_sql and page only cached results.
An automation update summary omits a changed field.The user cannot review the action that the agent applied.Render every returned changed field through the automation field map.
An MCP result shape is treated as plain text when it contains structured data or a chart block.The user loses a readable table, object view, or visualization.Parse the returned shape and reuse query data for chart blocks.
A story update sends partial markdown instead of the full content or uses files for a classic story.The update is rejected or replaces the story with incomplete content.Use full markdown for classic stories and file changes only for custom stories.
Onboarding asks for warehouse credentials in chat or continues after a turn-ending form.Secrets can enter the conversation or setup can advance without the user's selected input.Use the secure credential tool and stop until the user response resumes the flow.
Warehouse setup stops after business context is saved and the agent does not wait or retry.The project does not reach the state where its initial rules can be generated.Follow the setup status and use retry or restart based on the returned state.
A context fix includes another recommendation's edit or targets generated content.The proposed patch can overwrite unrelated work or be lost on the next sync.Keep edits scoped to one recommendation and use manual guidance for generated sources.
Follow-up suggestions are called before the answer is visible.The user sees a follow-up prompt without the requested answer.Write the complete visible answer before the sole final follow-up call.

Key files

FileWhy to read it
apps/…/index.tsShows how the run-specific tool surface is assembled and restricted.
apps/…/grep.tsShows how searchable project, storage, story, and rule context stays within access boundaries.
apps/…/read.tsShows how permitted context sources become safe, model-readable file results.
apps/…/execute-sandboxed-code.tsShows how bounded code execution receives context and returns safe files and output.
apps/…/execute-semantic-query.tsShows how governed metric requests become reusable query results.
apps/…/execute-sql.tsShows the boundary between local, warehouse, semantic, and write-enabled query work.
apps/…/page-query-result.tsShows how the agent reads more rows from an existing cached query result.
apps/…/display-chart.tsShows the checks that make chart and table output valid for the current surface.
apps/…/list.tsShows how project context and virtual mounts become a bounded directory view.
apps/…/story.tsShows the product-level story lifecycle for classic and custom stories.
apps/…/index.tsShows the onboarding tool set and which actions wait for user input.
apps/…/generate-onboarding-rules.tsShows how business context starts warehouse setup and rule generation.
apps/…/wait-for-warehouse-setup.tsShows how background setup status becomes agent-readable progress.
apps/…/propose-context-fix.tsShows how recommendations become isolated patches or manual fix guidance.
apps/…/suggest-follow-ups.tsShows the terminal contract for visible answers and follow-up suggestions.
apps/…/str-replace.tsShows the allowed exact-edit paths for saved text content.
apps/…/context-layer.tsShows how context, query, and story capabilities are exposed to MCP clients.
apps/…/sub-agent.tsShows the persisted ask_nao and polling contract for delegated agent work.
apps/…/run-agent-tool.tsShows how direct MCP calls obtain an authorized agent tool context.
apps/…/custom-story-mcp.tsShows custom story files, query data, build results, and MCP edit locks.
apps/…/agent.tsShows how messages, prompt context, overrides, and restrictions join before a model call.
apps/…/system-prompt.tsxDefines the high-level agent policy and the placement of skills, rules, and memory.
apps/…/system-prompts.tsDefines project prompt override selection and safe placeholder injection.
apps/…/user-rules.tsDefines how project rules and access-aware database context enter the agent context.
apps/…/skill.tsDefines project skill discovery, preloading, and prompt-size limits.
apps/…/load-skill.tsDefines on-demand skill loading, capability guidance, and its access boundary.
apps/…/memory.tsCoordinates memory injection, background extraction, and persistence.
apps/…/memory-system-prompt.tsxStates the policy for deciding what is worth remembering.
apps/…/memory-extractor-llm.tsShows the bounded input and structured output used by memory extraction.
apps/…/well-formed-prompt.tsProtects model requests from malformed prompt strings.
apps/…/prompt-cache.tsKeeps repeated system and conversation input reusable across supported model providers.
apps/…/user-group-context-access.service.tsResolves project context, skill, MCP, and rules access before a run.
apps/…/index.tsxMaps tool results to user-facing views and hides internal guidance calls.
apps/…/read.tsxShows how file and MCP read results appear in chat.
apps/…/display-chart.tsxShows how query results become interactive charts, tables, exports, and story additions.
apps/…/display-chart.test.tsxShows the client guarantees for chart titles and citable output parts.
apps/…/automation-editor.tsxShows how automation reads, run history, and field updates appear to users.
apps/…/display-chart-edit-dialog.tsxShows how users edit and save chart output created by an agent.
apps/…/chart-editor-preview.tsxShows how chart drafts and source data become chart, table, or split previews.
apps/…/display-chart-table.tsxShows table formatting edits and adding a table result to a story.
apps/…/display-map.tsxShows map views, editing, export, and story integration.
apps/…/display-map-edit-dialog.tsxShows the user-facing map configuration choices.
apps/…/display-map-view.tsxShows how point, bubble, and region data become an interactive map and how its camera survives viewport releases.
apps/…/display-map-view.test.tsxShows the guarantees for camera restoration and fresh fitting after off-screen data changes.
apps/…/mcp.tsxShows how MCP status, structured results, chart blocks, and auth requests appear in chat.
apps/…/story.tsxShows how story tool actions become chat status and openable story results.