awareness.py

API routes for an agent’s awareness profile: information about who it is, what it can do, and where it applies.

In plain words
What is it for?
They support viewing and updating an agent’s identity, capabilities, and intended use cases.
Why use it?
They give the frontend a way to read and edit this profile, creating the required profile record automatically when needed.

Agent

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add agents/netmindai-open/narranexus/awareness.py
Clone the repo
git clone --depth 1 https://github.com/NetMindAI-Open/NarraNexus
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 661 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00661
Opus 5 $0.00000 $0.00331
Sonnet 5 $0.00000 $0.00132
Haiku 4.5 $0.00000 $0.00066

Measured 3d ago against content hash a9a397fcca70, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

awareness.py scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 3d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.mindflow/mirror/backend/routes/agents/awareness.py.md · 41 lines

What it actually says

agents/awareness.py — Agent Awareness 读写路由

为什么存在

Awareness 是 Agent 的自我认知配置——它知道自己是谁、有什么能力、适用于哪些场景。这些信息存储在 instance_awareness 表里,通过 AwarenessModule 的实例 ID 关联到 Agent。这个路由文件暴露 GET/PUT 两个接口,让前端能读取和编辑 Awareness 内容。

上下游关系

  • 被谁用backend/routes/agents/core.py 聚合并挂载到 /api/agents;前端 AwarenessPanel 组件
  • 依赖谁
    • InstanceRepository — 查询或创建 AwarenessModule 实例
    • InstanceAwarenessRepository — upsert awareness 内容到 instance_awareness
    • xyz_agent_context.utils.db.db_factory.get_db_client — 直接查询 instance_awareness 表读取结果

设计决策

自动创建实例的 _ensure_awareness_instance

这个路由的一个关键设计是:如果 Agent 还没有 AwarenessModule 实例,GET 和 PUT 请求都会自动创建一个,而不是返回 404。理由是 Awareness 对每个 Agent 来说是必要的,在 Agent 创建时就应该存在,自动补齐比强迫调用者先创建实例更好用。

这个决策的代价是:GET 请求在极端情况下会有写副作用(创建实例),打破了 HTTP 语义中 GET 应该是幂等无副作用的约定。但实际上第一次 GET 之后实例就存在了,后续 GET 不会再写,所以问题有限。

分开 Repository 和直接 DB 查询

写操作用 InstanceAwarenessRepository.upsert(),读操作用 db_client.get_one() 直接查表,没有通过 Repository 封装。这是轻微的不一致,但读 Repository 的实现本质上也是 get_one,直接调没有额外风险。

Gotcha / 边界情况

  • Awareness 数据不存在时 GET 返回 success=False:即使实例创建成功,如果 instance_awareness 表里还没有这个实例的记录(比如 Awareness 从未被写过),GET 会返回 success=False, error="Awareness data not found",而不是空数据。前端需要处理这个情况,把它区别于真正的错误。
  • PUT 之后立即重读:upsert 成功后会再次 get_one 读取刚写入的数据并返回,这是为了确保返回值反映数据库的实际状态(比如 updated_at 字段由数据库生成)。

新人易踩的坑

instance_awareness 表的主键是 instance_id,而不是 agent_id。必须先通过 _ensure_awareness_instance 拿到实例 ID,再用实例 ID 查询,不能用 agent_id 直接查 instance_awareness

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 3d ago First seen · 41 lines · 0 tokens per session scan A a9a397fcca70

Subscribe to this mod's changes

awareness.py is an agent published in the GitHub repository NetMindAI-Open/NarraNexus (84 stars, last pushed 9d ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 661 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.