Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)7.6k · #13148

context-awareness

Skill này làm gì

Skill này giải thích cách ứng dụng Agent-Native cho agent biết những gì đang hiển thị trên màn hình. Nó bao gồm trạng thái điều hướng, chi tiết bản ghi đang thấy và lựa chọn hiện tại. Skill dành cho lập trình viên muốn agent hành động trên những gì người dùng thấy.

Khi nào nên dùng

  • ✓Khi agent hỏi bạn muốn nói đến mục nào, dù bạn đang xem một mục.
  • ✓Khi bạn muốn agent hành động trên lựa chọn hiện tại trong ứng dụng.
  • ✓Khi bạn gỡ lỗi vì sao agent có vẻ không biết màn hình hiện tại.

Liên kết skill

https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/context-awareness/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/BuilderIO/agent-native/blob/main/.agents/skills/context-awareness/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Bạn có thể làm cho agent biết tôi đang mở email nào, để tôi yêu cầu nó trả lời mà không cần nêu tên email không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Ứng dụng ghi trạng thái màn hình hiện tại vào một hook trạng thái route chia sẻ mỗi khi trang đổi. Mỗi lượt agent đều bao gồm ảnh chụp màn hình hiện tại, nên agent biết chế độ xem và mục được chọn.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Context Awareness

Rule

Apps can sync semantic navigation state when the route changes by using the shared route-state hook. When screen context is available, Core includes a <current-screen> snapshot in each agent turn, so the agent can get basic route context without first calling another tool. Apps can add concise visible-record details to that snapshot and expose selection in tab-scoped state.

Why

Without context awareness, the agent is blind. It asks "which email?" when the user is staring at one. It cannot act on the current selection, cannot provide relevant suggestions, and cannot modify what the user sees. Context awareness is what makes the agent feel like a collaborator rather than a disconnected chatbot.

The Core Patterns

1. Navigation State (navigation key)

Use the shared route-state hook to write a tab-scoped navigation key as the route changes. Include semantic screen state such as the view, open IDs, active tab, and focused object.

UI side — use useAgentRouteState in the app's route-state hook. The app can wrap it in an app-owned useNavigationState hook to map route paths to semantic views and consume the agent's navigate command.

// app/hooks/use-navigation-state.ts
import { useAgentRouteState } from "@agent-native/core/client/navigation";
import { TAB_ID } from "@/lib/tab-id";

export function useNavigationState() {
  useAgentRouteState({
    browserTabId: TAB_ID,
    requestSource: TAB_ID,
    getNavigationState: ({ pathname, searchParams }) => ({
      view:
        pathname === "/"
          ? "home"
          : pathname === "/sign-in"
            ? "sign-in"
            : pathname.replace(/^\/+/, ""),
      // Optional semantic alias. Raw query params are already exposed in
      // <current-url> and controllable with set-search-params.
      label: searchParams.get("label"),
    }),
    getCommandPath: (command: any) =>
      command.path ?? `/${command.view === "home" ? "home" : command.view}`,
  });
}

The default scaffold uses /home for home and /sign-in for authentication; / redirects according to the configured home route. Map navigation to the app's actual routes and pass an explicit path for destinations that do not follow the /<view> convention.

TAB_ID comes from the framework's getBrowserTabId() (see the scaffolded app/lib/tab-id.ts; never redefine it). The server resolves tab-scoped application_state writes and page-local WebMCP calls (X-Agent-Native-Browser-Tab) against this same id, so a hand-rolled random id silently breaks selection sync for hidden and background tabs.

Agent side — read before acting:

import { readAppState } from "@agent-native/core/application-state";

const navigation = await readAppState("navigation");
// e.g. { view: "thread", threadId: "abc123", subject: "Re: Q3 Planning" }

What to include in navigation state:

  • view — the current page/section (e.g., "inbox", "form-builder", "dashboard")
  • Item IDs — the selected/open item (e.g., threadId, formId, issueKey)
  • Semantic aliases — label names, active tabs, focused row, or stable filter names the agent should reason about
  • Focused object IDs and active tabs that are not already represented by URL state

Keep text-selection ranges and excerpts in the tab-scoped selection key, not in navigation.

Raw URL query params are already synced by the framework to __url__ and shown to the built-in agent as <current-url>. Keep shareable filters in URL state, then use view-screen to summarize important query params as activeFilters when helpful.

Keep application_state values small. Do not store pasted files, base64 images, recording chunks, screenshots, or other large blobs in navigation or app-state keys; upload them and store only a URL or storage handle.

Selection state

For app-owned per-tab selection, suffix the key with TAB_ID; requestSource labels the write origin but does not scope the key. Keep the value to stable ids and a short label or excerpt, never the full document:

import { writeClientAppState } from "@agent-native/core/client/hooks";
import { TAB_ID } from "@/lib/tab-id";

await writeClientAppState(
  `selection:${TAB_ID}`,
  { kind: "text", id: "artifact-123", text: "short excerpt" },
  { requestSource: TAB_ID },
);

A server action can read that tab's value with readAppStateForCurrentTab("selection"). A view-screen result may include the selection and a specific next a

Câu hỏi thường gặp

Ảnh chụp gồm những gì?

Nó gồm chế độ xem hiện tại và các chi tiết như ID đang mở, tab đang hoạt động và bản ghi đang được focus.

Agent có cần gọi công cụ để thấy màn hình không?

Ngữ cảnh route cơ bản đã được đưa vào mỗi lượt, nên không cần lời gọi công cụ thêm cho phần đó.

Agent có thể thay đổi những gì tôi đang thấy không?

Skill có bao gồm các action điều hướng cho phép agent đưa người dùng tới một màn hình.

Chi tiết

Mô tả gốc của tác giả

How the agent knows what the user is looking at. Use when exposing UI state to the agent, implementing view-screen or navigate actions, wiring navigation state, or debugging agent context issues.

repo: BuilderIO/agent-native

Độ phổ biến

Sao GitHub
7.6k
Vị trí xếp hạng
#13148
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự