social_network.py

social_network.py is an agent for coding agents from NetMindAI-Open/NarraNexus. It costs 0 tokens per session (801 once invoked), scanned A, original, Apache-2.0.

A set of read-only web endpoints for viewing and searching the people and organizations an AI agent knows about. The data comes through a repository, which is a code layer for reading stored information.

In plain words
What is it for?
Use it to retrieve one known entity, list entities, or search the agent’s social-memory records by keyword or meaning.
Why use it?
It keeps callers working while moving data access to a different storage source. It also documents route ordering so search requests are not mistaken for requests for one person or organization.

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/social_network.py
Clone the repo
git clone --depth 1 https://github.com/NetMindAI-Open/NarraNexus

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for social_network.py

README.md
[![agentmods](https://agentmods.dev/badge/agents/netmindai-open/narranexus/social_network.py.svg)](https://agentmods.dev/agents/netmindai-open/narranexus/social_network.py)
Your own site
<a href="https://agentmods.dev/agents/netmindai-open/narranexus/social_network.py"><img src="https://agentmods.dev/badge/agents/netmindai-open/narranexus/social_network.py.svg" alt="Measured on agentmods" height="20"></a>
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 801 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.00801
Opus 5 $0.00000 $0.00400
Sonnet 5 $0.00000 $0.00160
Haiku 4.5 $0.00000 $0.00080

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

Security

Grade A, and why

social_network.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 4d 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/social_network.py.md · 48 lines

What it actually says

2026-06-08 — entity endpoints route through the repo

Both endpoints now go through SocialNetworkRepository (reading memory_entity) plus an _entity_to_info helper, instead of touching instance_social_entities. Behaviour for callers is unchanged; only the storage source moved.

agents/social_network.py — 社交网络实体查询路由

为什么存在

SocialNetworkModule 维护 Agent 认识的人/组织的档案,存储在 instance_social_entities 表。这个路由暴露三个只读接口:查询单个实体的详细信息、列出所有实体、关键词/语义搜索。这些接口服务于前端的社交网络面板,以及开发者调试社交记忆的需求。

上下游关系

  • 被谁用backend/routes/agents/core.py 聚合;前端社交网络面板
  • 依赖谁
    • InstanceRepository — 查询 SocialNetworkModule 实例 ID
    • SocialNetworkRepository — 语义搜索(semantic_search)和关键词搜索(keyword_search
    • (历史:语义搜索曾经由 agent_framework 的 embedding 工具生成 query 向量;该向量化子系统已整体移除)
    • xyz_agent_context.utils.db.db_factory.get_db_client — 直接查询 instance_social_entities

设计决策

路由注册顺序

/{agent_id}/social-network/search 必须在 /{agent_id}/social-network/{user_id} 之前注册,否则路径匹配时 "search" 会被当成 user_id 的字符串值,把搜索请求路由到单实体查询接口,导致查不到结果但也不报错。注释里专门标注了这个要求。FastAPI 在同一路由器内按注册顺序匹配,不按路径特异性排序。

硬限 1000 条

get_all_social_network_entitieslimit=1000 硬限制最大返回数量。对于正常使用场景(Agent 通过日常对话积累的社交关系,通常是几十到几百条)这够用,但如果一个 Agent 接入了大型通讯录,1000 条可能不够。目前没有分页接口。

语义搜索即时 embedding

搜索时调用 get_embedding(query) 实时生成向量,这会产生一次 LLM API 调用(embedding 接口)。如果 embedding 服务不可用,语义搜索会抛异常,前端需要处理。关键词搜索不依赖外部服务,更稳定。

Gotcha / 边界情况

  • 只查第一个实例:如果一个 Agent 有多个 SocialNetworkModule 实例(理论上可能,虽然实践中通常只有一个),这里只用 instances[0] 的实例 ID。其他实例的社交实体不会被查询到。
  • _parse_json 处理双重编码:代码里有处理 JSON 双重编码的逻辑(json.loads 结果如果还是字符串,再 json.loads 一次)。这说明历史数据里存在 identity_info 等 JSON 字段被双重序列化的情况,是历史遗留问题。

新人易踩的坑

单实体查询接口用 user_id 作为路径参数,但实际上查的是 entity_id 字段(WHERE entity_id = {user_id})。这个接口的命名继承自最初只处理"用户"类型实体的设计,实际上 entity_id 可以是任何类型实体的 ID,不限于用户。

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. 4d ago First seen · 48 lines · 0 tokens per session scan A 8d43a2433557

Subscribe to this mod's changes

social_network.py is an agent published in the GitHub repository NetMindAI-Open/NarraNexus (85 stars, last pushed yesterday), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 801 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.

Related

Other agents, from other repositories