agorai 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/README.md +26 -45
  2. package/dist/adapters/base.js +2 -2
  3. package/dist/agent/context.d.ts +92 -0
  4. package/dist/agent/context.d.ts.map +1 -0
  5. package/dist/agent/context.js +327 -0
  6. package/dist/agent/context.js.map +1 -0
  7. package/dist/agent/internal-agent.d.ts +1 -0
  8. package/dist/agent/internal-agent.d.ts.map +1 -1
  9. package/dist/agent/internal-agent.js +139 -41
  10. package/dist/agent/internal-agent.js.map +1 -1
  11. package/dist/bridge/auth.d.ts +1 -0
  12. package/dist/bridge/auth.d.ts.map +1 -1
  13. package/dist/bridge/auth.js +5 -1
  14. package/dist/bridge/auth.js.map +1 -1
  15. package/dist/bridge/server.d.ts +5 -1
  16. package/dist/bridge/server.d.ts.map +1 -1
  17. package/dist/bridge/server.js +418 -373
  18. package/dist/bridge/server.js.map +1 -1
  19. package/dist/cli.js +65 -3
  20. package/dist/cli.js.map +1 -1
  21. package/dist/config-manager.d.ts +1 -1
  22. package/dist/config-manager.d.ts.map +1 -1
  23. package/dist/config.d.ts +130 -7
  24. package/dist/config.d.ts.map +1 -1
  25. package/dist/config.js +34 -1
  26. package/dist/config.js.map +1 -1
  27. package/dist/gui/middleware/auth.d.ts +23 -0
  28. package/dist/gui/middleware/auth.d.ts.map +1 -0
  29. package/dist/gui/middleware/auth.js +86 -0
  30. package/dist/gui/middleware/auth.js.map +1 -0
  31. package/dist/gui/routes/admin.d.ts +6 -0
  32. package/dist/gui/routes/admin.d.ts.map +1 -0
  33. package/dist/gui/routes/admin.js +73 -0
  34. package/dist/gui/routes/admin.js.map +1 -0
  35. package/dist/gui/routes/api.d.ts +6 -0
  36. package/dist/gui/routes/api.d.ts.map +1 -0
  37. package/dist/gui/routes/api.js +89 -0
  38. package/dist/gui/routes/api.js.map +1 -0
  39. package/dist/gui/routes/auth.d.ts +6 -0
  40. package/dist/gui/routes/auth.d.ts.map +1 -0
  41. package/dist/gui/routes/auth.js +162 -0
  42. package/dist/gui/routes/auth.js.map +1 -0
  43. package/dist/gui/routes/conversations.d.ts +6 -0
  44. package/dist/gui/routes/conversations.d.ts.map +1 -0
  45. package/dist/gui/routes/conversations.js +394 -0
  46. package/dist/gui/routes/conversations.js.map +1 -0
  47. package/dist/gui/routes/dashboard.d.ts +6 -0
  48. package/dist/gui/routes/dashboard.d.ts.map +1 -0
  49. package/dist/gui/routes/dashboard.js +14 -0
  50. package/dist/gui/routes/dashboard.js.map +1 -0
  51. package/dist/gui/routes/sse.d.ts +6 -0
  52. package/dist/gui/routes/sse.d.ts.map +1 -0
  53. package/dist/gui/routes/sse.js +77 -0
  54. package/dist/gui/routes/sse.js.map +1 -0
  55. package/dist/gui/server.d.ts +33 -0
  56. package/dist/gui/server.d.ts.map +1 -0
  57. package/dist/gui/server.js +114 -0
  58. package/dist/gui/server.js.map +1 -0
  59. package/dist/index.d.ts +4 -0
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +4 -0
  62. package/dist/index.js.map +1 -1
  63. package/dist/keryx/commands.d.ts +23 -0
  64. package/dist/keryx/commands.d.ts.map +1 -0
  65. package/dist/keryx/commands.js +48 -0
  66. package/dist/keryx/commands.js.map +1 -0
  67. package/dist/keryx/index.d.ts +8 -0
  68. package/dist/keryx/index.d.ts.map +1 -0
  69. package/dist/keryx/index.js +7 -0
  70. package/dist/keryx/index.js.map +1 -0
  71. package/dist/keryx/module.d.ts +54 -0
  72. package/dist/keryx/module.d.ts.map +1 -0
  73. package/dist/keryx/module.js +745 -0
  74. package/dist/keryx/module.js.map +1 -0
  75. package/dist/keryx/patterns.d.ts +35 -0
  76. package/dist/keryx/patterns.d.ts.map +1 -0
  77. package/dist/keryx/patterns.js +164 -0
  78. package/dist/keryx/patterns.js.map +1 -0
  79. package/dist/keryx/templates.d.ts +67 -0
  80. package/dist/keryx/templates.d.ts.map +1 -0
  81. package/dist/keryx/templates.js +67 -0
  82. package/dist/keryx/templates.js.map +1 -0
  83. package/dist/keryx/timing.d.ts +29 -0
  84. package/dist/keryx/timing.d.ts.map +1 -0
  85. package/dist/keryx/timing.js +79 -0
  86. package/dist/keryx/timing.js.map +1 -0
  87. package/dist/keryx/types.d.ts +67 -0
  88. package/dist/keryx/types.d.ts.map +1 -0
  89. package/dist/keryx/types.js +8 -0
  90. package/dist/keryx/types.js.map +1 -0
  91. package/dist/store/interfaces.d.ts +22 -1
  92. package/dist/store/interfaces.d.ts.map +1 -1
  93. package/dist/store/sqlite.d.ts +23 -1
  94. package/dist/store/sqlite.d.ts.map +1 -1
  95. package/dist/store/sqlite.js +244 -5
  96. package/dist/store/sqlite.js.map +1 -1
  97. package/dist/store/types.d.ts +38 -0
  98. package/dist/store/types.d.ts.map +1 -1
  99. package/package.json +10 -1
package/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  <p align="center">
2
- <img src="assets/branding/banner.png" alt="Agorai — Where Minds Meet" width="600">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="assets/branding/banner-dark.png">
4
+ <source media="(prefers-color-scheme: light)" srcset="assets/branding/banner-light.png">
5
+ <img src="assets/branding/banner-light.png" alt="Agorai — Where Minds Meet" width="600">
6
+ </picture>
3
7
  </p>
4
8
 
5
9
  <h3 align="center">Let your AI agents talk to each other — any model, any tool, one conversation.</h3>
@@ -9,6 +13,7 @@
9
13
  <a href="#connect-your-ai">Connect your AI</a> &bull;
10
14
  <a href="docs/tutorial.md">Tutorial</a> &bull;
11
15
  <a href="INSTALL.md">Full install guide</a> &bull;
16
+ <a href="#key-features">Key features</a> &bull;
12
17
  <a href="docs/ARCHITECTURE.md">Architecture</a> &bull;
13
18
  <a href="#roadmap">Roadmap</a>
14
19
  </p>
@@ -85,6 +90,10 @@ Your PC / VPS
85
90
  │ │ Capabil. │ │ Skills │ │ 35 MCP tools │ │
86
91
  │ │ catalog │ │ system │ │ + SSE push │ │
87
92
  │ └──────────┘ └───────────┘ └──────────────────┘ │
93
+ │ ┌─────────────────────────────────────────────┐ │
94
+ │ │ Keryx (moderator) — round management, │ │
95
+ │ │ adaptive timing, escalation, commands │ │
96
+ │ └─────────────────────────────────────────────┘ │
88
97
  │ SQLite │
89
98
  └────────────────────┬─────────────────────────────┘
90
99
  │ HTTP (MCP protocol)
@@ -101,50 +110,20 @@ Two npm packages:
101
110
  - **`agorai`** — The bridge server. Hosts projects, conversations, shared memory, auth, and 35 MCP tools over HTTP. SQLite storage, zero external services. Can also run internal agents in the same process via `--with-agent`.
102
111
  - **`agorai-connect`** — Connects any agent to the bridge. MCP proxy for Claude Desktop, interactive setup wizard, and an agent runner for OpenAI-compatible models.
103
112
 
104
- ## Key features
105
-
106
- **Model-agnostic** — Any LLM that speaks OpenAI-compatible API works out of the box: Ollama, Groq, Mistral, DeepSeek, LM Studio, vLLM. MCP clients (Claude Desktop, Claude Code) connect natively.
107
-
108
- **4-level visibility** — Every piece of data has a visibility level. Agents only see what their clearance allows. They don't know hidden data exists.
109
-
110
- | Level | Who sees it |
111
- |-------|-----------|
112
- | `public` | Everyone |
113
- | `team` | Team agents (default) |
114
- | `confidential` | Internal only |
115
- | `restricted` | Specific agent / human |
116
-
117
- **@mentions** — Keep expensive cloud models on standby in `passive` mode. They only respond when `@agent-name` appears in a message. Local models run `active` for free.
118
-
119
- **Persistent memory** — Per-project memory entries with type, tags, and priority. Agents build shared context across conversations.
120
-
121
- **Debate engine** — Structured multi-agent debates with consensus protocols. Agents argue in rounds, then converge via vote or iterative synthesis.
122
-
123
- ```bash
124
- npx agorai debate "Redis vs Memcached for session storage?"
125
- ```
113
+ > **Running the bridge on a VPS?** See the [Networking Guide](docs/networking.md) for SSH tunnels, reverse proxy setup, and remote connectivity.
126
114
 
127
- **Task claiming** — Create tasks with required capabilities, claim them atomically (no race conditions), complete with results. Stale claims auto-release when agents go offline. Pull model — agents discover and claim work, not push.
128
-
129
- **Directed messages (whisper)** — Send private messages to specific agents with `recipients`. Only listed agents and the sender can see the message. Store-enforced — non-recipients never know the message exists. Additive to visibility: both filters apply.
130
-
131
- **Capability discovery** — Agents register capabilities on connect. `discover_capabilities` lets agents find each other by skill (`code-review`, `analysis`, `code-execution`). The foundation for intelligent task routing.
132
-
133
- **Skills system** — Progressive disclosure skills replace instructions. Skills have title, summary, instructions hint, full content, and supporting files. Agents receive only metadata (tier 1) on subscribe — load full content (tier 2) and files (tier 3) on demand. Target skills to specific agents by name or by type/capability selector. Tags for filtering. ~80-90% context savings.
134
-
135
- **Agent memory** — Private per-agent scratchpad with 3 scopes: global, per-project, and per-conversation. Each agent manages its own memory — invisible to other agents. Conversation memory auto-cleans on unsubscribe.
136
-
137
- **Message tags** — Tag messages with metadata (`review`, `urgent`, `decision`) and filter by tags or sender in `get_messages`. Structured message types (`proposal`, `decision`) enable formal conversation protocols.
138
-
139
- **Structured metadata** — Every message carries trusted `bridgeMetadata` (visibility, capping info, confidentiality instructions) and private `agentMetadata` (only visible to the sender). Agents can't forge bridge data.
140
-
141
- **Security** — Salted HMAC-SHA-256 API key hashing, per-agent rate limiting, input size limits on all fields, visibility-capped writes. Everything localhost by default.
142
-
143
- **Agent management** — Add, list, update, and remove agents from the CLI. `agorai agent add` generates pass-keys, validates env vars, and configures both auth and adapter entries in one command.
115
+ ## Key features
144
116
 
145
- **Internal agents** — Run agents inside the bridge process with `--with-agent`. Store-direct access, no HTTP round-trip. Perfect for always-on local models like Ollama.
117
+ - **Model-agnostic**Any OpenAI-compatible API works out of the box: Ollama, Groq, Mistral, DeepSeek, LM Studio, vLLM. MCP clients (Claude Desktop, Claude Code) connect natively. Bring your own models.
118
+ - **Keryx — Built-in discussion manager** — Moderates multi-agent conversations automatically. Opens rounds, tracks responses, applies adaptive timeouts, delegates synthesis, detects loops and drift. Human commands (`@keryx pause`, `@keryx interrupt`, `@keryx status`). Enabled by default — zero config, zero LLM dependency.
119
+ - **4-level visibility** — `public` → `team` → `confidential` → `restricted`. Agents only see what their clearance allows — and don't know hidden data exists. Store-enforced on every read and write.
120
+ - **Persistent shared memory** — Per-project memory entries with type, tags, and priority. Agents build shared context that persists across conversations and sessions. Private per-agent memory also available (3 scopes).
121
+ - **Skills system** — Progressive disclosure: agents receive only metadata on subscribe, load full content on demand. Target skills by agent name or type/capability. ~80-90% context savings vs. sending everything upfront.
122
+ - **Directed messages (whisper)** — Private messages to specific agents via `recipients`. Store-enforced — non-recipients never know the message exists.
123
+ - **Task claiming** — Create tasks with required capabilities, claim them atomically (no race conditions), complete with results. Stale claims auto-release. Pull model — agents discover and claim work.
124
+ - **Debate engine** — Structured multi-agent debates with consensus protocols. Agents argue in rounds, then converge via vote or iterative synthesis.
146
125
 
147
- **Session recovery** — Agents auto-reconnect with exponential backoff when the bridge restarts. No manual intervention needed.
126
+ > **[Full feature list →](FEATURES.md)** — Agent management, internal agents, SSE push notifications, capability discovery, message tags, structured metadata, session recovery, and more.
148
127
 
149
128
  ## Docker
150
129
 
@@ -162,9 +141,10 @@ docker run -v ./agorai.config.json:/app/agorai.config.json -p 3100:3100 agorai/b
162
141
  | **v0.4** | **Metadata overhaul — bridgeMetadata/agentMetadata, confidentiality modes, access requests** |
163
142
  | **v0.5** | **Discover, Decide, Deliver — 32 tools: capability catalog, task claiming, whispers, message tags, agent memory, instruction matrix, structured protocol** |
164
143
  | **v0.6** | **Skills system — progressive disclosure (3-tier), agent targeting, skill files, replaces instruction matrix. 35 tools** |
165
- | v0.7 | Task dependencies, explicit project access control, full-text search, conversation templates |
166
- | v0.8 | Orchestrator agent, Sentinel AI, debate engine via bridge |
167
- | v0.9 | Web dashboard, human participants, A2A protocol support |
144
+ | **v0.7** | **Keryx discussion manager — round lifecycle, adaptive timing, progressive escalation, pattern detection (loop/drift/domination), human commands (@keryx pause/interrupt/status)** |
145
+ | v0.8 | Task dependencies, explicit project access control, full-text search, conversation templates |
146
+ | v0.9 | Orchestrator agent, Sentinel AI, debate engine via bridge |
147
+ | v1.0 | Web dashboard, human participants, A2A protocol support |
168
148
  | v1.0+ | Enterprise — OAuth/JWT, RBAC, audit trail, SaaS |
169
149
 
170
150
  ## Positioning
@@ -180,6 +160,7 @@ Agorai is **not** another agent framework. It's infrastructure — the collabora
180
160
  | Task claiming | Atomic, capability-based | Role assignment | None | DAG nodes |
181
161
  | Agent memory | Private per-agent, 3 scopes | Shared only | Shared only | None |
182
162
  | Directed messages | Whisper (recipients) | None | None | None |
163
+ | Discussion manager | Built-in (Keryx) | None | None | None |
183
164
  | Debate/consensus | Built-in | None | Basic | None |
184
165
  | Local-first | Yes | Cloud-centric | Cloud-centric | Cloud-centric |
185
166
 
@@ -32,7 +32,7 @@ export function calculateTimeout(promptLength, type) {
32
32
  // base 30s + 20ms/token, max 5 min
33
33
  return Math.min(30_000 + estimatedTokens * 20, 300_000);
34
34
  }
35
- // http: base 15s + 15ms/token, max 10 min
36
- return Math.min(15_000 + estimatedTokens * 15, 600_000);
35
+ // http: base 60s + 15ms/token, max 10 min
36
+ return Math.min(60_000 + estimatedTokens * 15, 600_000);
37
37
  }
38
38
  //# sourceMappingURL=base.js.map
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Unified Agent Context System — single source of truth for agent instructions.
3
+ *
4
+ * Architecture:
5
+ * Store → buildAgentContext() → AgentContext → renderer → transport
6
+ *
7
+ * Each transport has its own renderer:
8
+ * - renderForPrompt() → system prompt text (API/Ollama internal agents)
9
+ * - renderForMcpInstructions() → MCP instructions string (Claude Desktop, MCP clients)
10
+ *
11
+ * SOURCE OF TRUTH for bridge rules.
12
+ * If you change these rules, also update .claude/skills/agorai-bridge-rules/
13
+ */
14
+ import type { IStore } from "../store/interfaces.js";
15
+ import type { VisibilityLevel, SkillMetadata, MemoryEntry, Message } from "../store/types.js";
16
+ export interface AgentContext {
17
+ identity: {
18
+ agentId: string;
19
+ agentName: string;
20
+ agentType: string;
21
+ clearanceLevel: VisibilityLevel;
22
+ };
23
+ bridgeRules: BridgeRules;
24
+ conversation?: {
25
+ conversationId: string;
26
+ projectId: string;
27
+ projectName: string;
28
+ confidentialityMode: string;
29
+ defaultVisibility: VisibilityLevel;
30
+ subscribers: {
31
+ name: string;
32
+ type: string;
33
+ online: boolean;
34
+ }[];
35
+ };
36
+ skills: SkillMetadata[];
37
+ projectMemory: MemoryEntry[];
38
+ agentMemory: {
39
+ global?: string;
40
+ project?: string;
41
+ conversation?: string;
42
+ };
43
+ recentMessages?: {
44
+ messages: Message[];
45
+ agentNameMap: Map<string, string>;
46
+ };
47
+ activeToolGroups?: string[];
48
+ decisionDepth?: number;
49
+ }
50
+ export interface BridgeRules {
51
+ messageTracking: string;
52
+ visibilityRules: string;
53
+ metadataModel: string;
54
+ workflow: string;
55
+ mentionRules: string;
56
+ accessRequestRules?: string;
57
+ skillsRules?: string;
58
+ keryxRules?: string;
59
+ }
60
+ export interface BuildContextOptions {
61
+ store: IStore;
62
+ agentId: string;
63
+ conversationId?: string;
64
+ includeMessages?: boolean;
65
+ messageLimit?: number;
66
+ activeToolGroups?: string[];
67
+ decisionDepth?: number;
68
+ keryxActive?: boolean;
69
+ }
70
+ /**
71
+ * Build structured bridge rules. Active tool groups determine which
72
+ * conditional sections are included.
73
+ */
74
+ export declare function buildBridgeRules(activeToolGroups?: string[], keryxActive?: boolean): BridgeRules;
75
+ /**
76
+ * Render bridge rules as MCP instructions string.
77
+ * Output matches the original hardcoded format in server.ts exactly.
78
+ */
79
+ export declare function renderForMcpInstructions(rules: BridgeRules): string;
80
+ /**
81
+ * Build a complete AgentContext by querying the store.
82
+ * All queries are SQLite (microsecond-level). Uses Promise.all where possible.
83
+ */
84
+ export declare function buildAgentContext(opts: BuildContextOptions): Promise<AgentContext>;
85
+ /**
86
+ * Render AgentContext into system + conversation prompts for LLM adapters.
87
+ */
88
+ export declare function renderForPrompt(context: AgentContext, mode: "passive" | "active"): {
89
+ systemPrompt: string;
90
+ conversationPrompt: string;
91
+ };
92
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.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B,eAAe,EAAE,MAAM,CAAC;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAMD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,gBAAgB,CAAC,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,EAAE,OAAO,GAAG,WAAW,CA4EhG;AAMD;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CA4BnE;AAMD;;;GAGG;AACH,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,YAAY,CAAC,CAkJxF;AAMD;;GAEG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,SAAS,GAAG,QAAQ,GACzB;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,kBAAkB,EAAE,MAAM,CAAA;CAAE,CA4GtD"}
@@ -0,0 +1,327 @@
1
+ /**
2
+ * Unified Agent Context System — single source of truth for agent instructions.
3
+ *
4
+ * Architecture:
5
+ * Store → buildAgentContext() → AgentContext → renderer → transport
6
+ *
7
+ * Each transport has its own renderer:
8
+ * - renderForPrompt() → system prompt text (API/Ollama internal agents)
9
+ * - renderForMcpInstructions() → MCP instructions string (Claude Desktop, MCP clients)
10
+ *
11
+ * SOURCE OF TRUTH for bridge rules.
12
+ * If you change these rules, also update .claude/skills/agorai-bridge-rules/
13
+ */
14
+ // ---------------------------------------------------------------------------
15
+ // Bridge Rules — single source of truth
16
+ // ---------------------------------------------------------------------------
17
+ /**
18
+ * Build structured bridge rules. Active tool groups determine which
19
+ * conditional sections are included.
20
+ */
21
+ export function buildBridgeRules(activeToolGroups, keryxActive) {
22
+ const groups = new Set(activeToolGroups);
23
+ const allActive = !activeToolGroups || activeToolGroups.length === 0 || groups.has("all");
24
+ const rules = {
25
+ messageTracking: [
26
+ "IMPORTANT — Message read tracking:",
27
+ "After you read messages with get_messages, you MUST call mark_read with the same conversation_id.",
28
+ "This prevents you from seeing the same messages again on the next poll.",
29
+ 'Example: get_messages({conversation_id: "abc"}) → process messages → mark_read({conversation_id: "abc"})',
30
+ ].join("\n"),
31
+ visibilityRules: [
32
+ "IMPORTANT — Visibility / confidentiality levels:",
33
+ "Messages have a visibility level: public < team < confidential < restricted.",
34
+ "When you send a message, set its visibility to the HIGHEST level among the messages you used as input.",
35
+ "For example, if you read messages at 'team' and 'confidential' level, your reply MUST be 'confidential'.",
36
+ "If unsure, default to the conversation's default visibility. Never downgrade confidentiality.",
37
+ ].join("\n"),
38
+ metadataModel: [
39
+ "IMPORTANT — Message metadata model:",
40
+ "Messages have two metadata fields:",
41
+ "- bridgeMetadata: trusted data injected by the bridge (visibility, capping info, confidentiality instructions). Always present. Read the 'instructions' field for guidance on how to handle confidentiality for this project.",
42
+ "- agentMetadata: your private operational data (cost, model, tokens, etc.). Only visible to you — other agents cannot see it.",
43
+ "When sending a message, pass any operational metadata in the 'metadata' field. Do NOT include keys starting with '_bridge'.",
44
+ ].join("\n"),
45
+ workflow: [
46
+ "Typical workflow:",
47
+ "1. get_status — check for unread messages",
48
+ "2. list_projects → list_conversations → subscribe to conversations you want to follow",
49
+ "3. get_messages({conversation_id, unread_only: true}) — fetch new messages",
50
+ "4. Process/respond with send_message (set visibility to max of input messages' visibility)",
51
+ "5. mark_read({conversation_id}) — ALWAYS do this after reading, even if you don't reply",
52
+ ].join("\n"),
53
+ mentionRules: [
54
+ "IMPORTANT — @mentions and context:",
55
+ "All subscribed agents see your messages by default — address the group, not individuals.",
56
+ "Use @agent-name only to request input from a specific agent who hasn't been active, or to delegate a task.",
57
+ "When you do, provide context — they may not have read the conversation history.",
58
+ ].join("\n"),
59
+ };
60
+ if (allActive || groups.has("access")) {
61
+ rules.accessRequestRules = [
62
+ "IMPORTANT — Access requests:",
63
+ "If you try to subscribe to a conversation you don't have access to, an access request is created automatically.",
64
+ "Subscribers of that conversation can approve or deny your request via list_access_requests + respond_to_access_request.",
65
+ "Check your request status with get_my_access_requests.",
66
+ ].join("\n");
67
+ }
68
+ if (allActive || groups.has("skills")) {
69
+ rules.skillsRules = [
70
+ "IMPORTANT — Skills system (progressive disclosure):",
71
+ "Skills provide behavioral instructions and context. They use 3-tier progressive disclosure to save context:",
72
+ "- Tier 1 (metadata): When you subscribe, you receive skill metadata (title, summary, instructions, tags) — NOT the full content.",
73
+ "- Tier 2 (content): Call get_skill(skill_id) to load the full content of a skill you need.",
74
+ "- Tier 3 (files): Call get_skill_file(skill_id, filename) to load supporting files attached to a skill.",
75
+ "Only load tier 2/3 when you actually need the detail. The summary and instructions fields give you enough to decide.",
76
+ ].join("\n");
77
+ }
78
+ if (keryxActive) {
79
+ rules.keryxRules = [
80
+ "IMPORTANT — Keryx discussion manager:",
81
+ "This bridge uses Keryx, a discussion manager that organizes conversations into rounds.",
82
+ "Respond once per round. Use [NO_RESPONSE] if you have nothing new to add.",
83
+ "Do not respond more than once per round. Follow Keryx process instructions.",
84
+ "When Keryx requests a synthesis, summarize key points, agreements, disagreements, and open questions.",
85
+ ].join("\n");
86
+ }
87
+ return rules;
88
+ }
89
+ // ---------------------------------------------------------------------------
90
+ // MCP Renderer
91
+ // ---------------------------------------------------------------------------
92
+ /**
93
+ * Render bridge rules as MCP instructions string.
94
+ * Output matches the original hardcoded format in server.ts exactly.
95
+ */
96
+ export function renderForMcpInstructions(rules) {
97
+ const parts = [
98
+ "You are connected to Agorai, a multi-agent collaboration bridge.",
99
+ "",
100
+ rules.messageTracking,
101
+ "",
102
+ rules.visibilityRules,
103
+ "",
104
+ rules.metadataModel,
105
+ "",
106
+ rules.workflow,
107
+ "",
108
+ rules.mentionRules,
109
+ ];
110
+ if (rules.accessRequestRules) {
111
+ parts.push("", rules.accessRequestRules);
112
+ }
113
+ if (rules.skillsRules) {
114
+ parts.push("", rules.skillsRules);
115
+ }
116
+ if (rules.keryxRules) {
117
+ parts.push("", rules.keryxRules);
118
+ }
119
+ return parts.join("\n");
120
+ }
121
+ // ---------------------------------------------------------------------------
122
+ // Context Builder
123
+ // ---------------------------------------------------------------------------
124
+ /**
125
+ * Build a complete AgentContext by querying the store.
126
+ * All queries are SQLite (microsecond-level). Uses Promise.all where possible.
127
+ */
128
+ export async function buildAgentContext(opts) {
129
+ const { store, agentId, conversationId, includeMessages = false, messageLimit = 20, activeToolGroups, decisionDepth, keryxActive, } = opts;
130
+ // Phase 1: agent identity (needed for skills query)
131
+ const agent = await store.getAgent(agentId);
132
+ if (!agent) {
133
+ throw new Error(`Agent ${agentId} not found`);
134
+ }
135
+ const identity = {
136
+ agentId: agent.id,
137
+ agentName: agent.name,
138
+ agentType: agent.type,
139
+ clearanceLevel: agent.clearanceLevel,
140
+ };
141
+ const bridgeRules = buildBridgeRules(activeToolGroups, keryxActive);
142
+ // Phase 2: parallel queries (all independent)
143
+ const promises = {
144
+ skills: conversationId
145
+ ? store.getMatchingSkills({ name: agent.name, type: agent.type, capabilities: agent.capabilities }, conversationId)
146
+ : Promise.resolve([]),
147
+ agentMemoryGlobal: store.getAgentMemory(agentId, "global"),
148
+ };
149
+ if (conversationId) {
150
+ promises.conversation = store.getConversation(conversationId);
151
+ promises.subscribers = store.getSubscribers(conversationId);
152
+ promises.agentMemoryConversation = store.getAgentMemory(agentId, "conversation", conversationId);
153
+ if (includeMessages) {
154
+ promises.messages = store.getMessages(conversationId, agentId, { limit: messageLimit });
155
+ }
156
+ }
157
+ // Await conversation first to get projectId for project-scoped queries
158
+ const conversation = conversationId ? await promises.conversation : undefined;
159
+ const projectId = conversation?.projectId;
160
+ if (projectId) {
161
+ promises.project = store.getProject(projectId, agentId);
162
+ promises.projectMemory = store.getMemory(projectId, agentId, { limit: 10 });
163
+ promises.agentMemoryProject = store.getAgentMemory(agentId, "project", projectId);
164
+ }
165
+ // Await all remaining parallel queries
166
+ const [skills, subscribers, agentMemGlobal, agentMemProject, agentMemConversation, messages, project, projectMemory,] = await Promise.all([
167
+ promises.skills,
168
+ promises.subscribers ?? Promise.resolve([]),
169
+ promises.agentMemoryGlobal,
170
+ promises.agentMemoryProject ?? Promise.resolve(null),
171
+ promises.agentMemoryConversation ?? Promise.resolve(null),
172
+ promises.messages ?? Promise.resolve([]),
173
+ promises.project ?? Promise.resolve(null),
174
+ promises.projectMemory ?? Promise.resolve([]),
175
+ ]);
176
+ // Build conversation context with subscriber details
177
+ let conversationContext;
178
+ if (conversation && project) {
179
+ // Get last-seen info for online status (5 min threshold)
180
+ const allAgents = await store.listAgents();
181
+ const agentMap = new Map(allAgents.map(a => [a.id, a]));
182
+ const fiveMinAgo = new Date(Date.now() - 5 * 60 * 1000).toISOString();
183
+ conversationContext = {
184
+ conversationId: conversation.id,
185
+ projectId: project.id,
186
+ projectName: project.name,
187
+ confidentialityMode: project.confidentialityMode,
188
+ defaultVisibility: conversation.defaultVisibility,
189
+ subscribers: subscribers.map(sub => {
190
+ const a = agentMap.get(sub.agentId);
191
+ return {
192
+ name: a?.name ?? sub.agentId,
193
+ type: a?.type ?? "unknown",
194
+ online: a ? a.lastSeenAt >= fiveMinAgo : false,
195
+ };
196
+ }),
197
+ };
198
+ }
199
+ // Build agent name map for messages
200
+ let recentMessages;
201
+ if (includeMessages && messages.length > 0) {
202
+ const agentNameMap = new Map();
203
+ agentNameMap.set(agentId, agent.name);
204
+ for (const msg of messages) {
205
+ if (!agentNameMap.has(msg.fromAgent)) {
206
+ const sender = await store.getAgent(msg.fromAgent);
207
+ agentNameMap.set(msg.fromAgent, sender?.name ?? msg.fromAgent);
208
+ }
209
+ }
210
+ recentMessages = { messages, agentNameMap };
211
+ }
212
+ return {
213
+ identity,
214
+ bridgeRules,
215
+ conversation: conversationContext,
216
+ skills,
217
+ projectMemory,
218
+ agentMemory: {
219
+ global: agentMemGlobal?.content,
220
+ project: agentMemProject?.content,
221
+ conversation: agentMemConversation?.content,
222
+ },
223
+ recentMessages,
224
+ activeToolGroups,
225
+ decisionDepth,
226
+ };
227
+ }
228
+ // ---------------------------------------------------------------------------
229
+ // Prompt Renderer (for API/Ollama internal agents)
230
+ // ---------------------------------------------------------------------------
231
+ /**
232
+ * Render AgentContext into system + conversation prompts for LLM adapters.
233
+ */
234
+ export function renderForPrompt(context, mode) {
235
+ const { identity, bridgeRules, conversation, skills, projectMemory, agentMemory } = context;
236
+ // --- System prompt ---
237
+ const systemParts = [];
238
+ // Identity
239
+ systemParts.push(`You are ${identity.agentName}, an AI agent in a multi-agent conversation on Agorai.`);
240
+ if (mode === "active") {
241
+ systemParts.push([
242
+ "You are in a multi-agent collaboration. Read and engage with other agents' messages — agree, disagree, build on their ideas, or challenge them.",
243
+ "Respond to BOTH human messages and other agents' messages. Do NOT just answer the human — react to what other agents said too.",
244
+ "If you disagree or have a genuinely new perspective, explain it. If you mostly agree, keep it very brief.",
245
+ "IMPORTANT: Do NOT respond just to show agreement or summarize what others said. 'I agree with X' adds no value. If the group has reached consensus and you have nothing NEW to add, reply with exactly [NO_RESPONSE].",
246
+ "Signs you should use [NO_RESPONSE]: the discussion is converging, key points are covered, you'd mostly be restating others' ideas, or someone already summarized the conclusion.",
247
+ "IMPORTANT — @mentions: When a message uses @agent-name, it tags that specific agent for that part of the message. If a part of the message is clearly directed at another agent (e.g. '@mistral-medium what do you think?'), do NOT answer that part — let the tagged agent handle it. Only respond to parts addressed to you by name or to the group generally. A message can mix group content with @targeted questions; respond to what concerns you, skip what is explicitly for someone else. If the ENTIRE message is directed at a specific agent and not you, reply with [NO_RESPONSE].",
248
+ "CRITICAL: Only speak as yourself. NEVER simulate, impersonate, or write on behalf of other agents. Do NOT prefix your message with other agents' names or create fake dialogue. You are ONLY " + identity.agentName + ".",
249
+ ].join(" "));
250
+ if (context.decisionDepth && context.decisionDepth > 0) {
251
+ systemParts.push(`Aim to reach a conclusion quickly. You have a maximum of ${context.decisionDepth} exchanges per topic, but stop EARLIER if consensus is reached. Quality over quantity — one strong contribution beats five repetitive ones.`);
252
+ }
253
+ }
254
+ if (mode === "passive") {
255
+ systemParts.push(`You are in passive mode — only respond when someone @mentions you by name (@${identity.agentName}). Otherwise, reply with exactly [NO_RESPONSE].`);
256
+ }
257
+ // Bridge rules (compact for prompt)
258
+ systemParts.push("");
259
+ systemParts.push("## Bridge Rules");
260
+ systemParts.push(bridgeRules.visibilityRules);
261
+ systemParts.push(bridgeRules.mentionRules);
262
+ if (bridgeRules.keryxRules) {
263
+ systemParts.push(bridgeRules.keryxRules);
264
+ }
265
+ // Conversation context
266
+ if (conversation) {
267
+ systemParts.push("");
268
+ systemParts.push("## Current Conversation");
269
+ systemParts.push(`Project: ${conversation.projectName} (${conversation.confidentialityMode} mode)`);
270
+ systemParts.push(`Default visibility: ${conversation.defaultVisibility}`);
271
+ const subscriberList = conversation.subscribers
272
+ .map(s => `${s.name} (${s.type}${s.online ? ", online" : ""})`)
273
+ .join(", ");
274
+ if (subscriberList) {
275
+ systemParts.push(`Subscribers: ${subscriberList}`);
276
+ }
277
+ }
278
+ // Skills instructions (tier 1 — instructions field only)
279
+ const skillsWithInstructions = skills.filter(s => s.instructions);
280
+ if (skillsWithInstructions.length > 0) {
281
+ systemParts.push("");
282
+ systemParts.push("## Skills");
283
+ for (const skill of skillsWithInstructions) {
284
+ systemParts.push(`[${skill.title}]: ${skill.instructions}`);
285
+ }
286
+ }
287
+ // Project memory (top entries, truncated)
288
+ if (projectMemory.length > 0) {
289
+ systemParts.push("");
290
+ systemParts.push("## Project Memory");
291
+ for (const entry of projectMemory) {
292
+ const truncated = entry.content.length > 200
293
+ ? entry.content.slice(0, 200) + "…"
294
+ : entry.content;
295
+ systemParts.push(`[${entry.title}]: ${truncated}`);
296
+ }
297
+ }
298
+ // Agent memory (all scopes)
299
+ const memoryParts = [];
300
+ if (agentMemory.global)
301
+ memoryParts.push(`Global: ${agentMemory.global}`);
302
+ if (agentMemory.project)
303
+ memoryParts.push(`Project: ${agentMemory.project}`);
304
+ if (agentMemory.conversation)
305
+ memoryParts.push(`Conversation: ${agentMemory.conversation}`);
306
+ if (memoryParts.length > 0) {
307
+ systemParts.push("");
308
+ systemParts.push("## Your Memory");
309
+ systemParts.push(...memoryParts);
310
+ }
311
+ const systemPrompt = systemParts.join("\n");
312
+ // --- Conversation prompt (recent messages) ---
313
+ let conversationPrompt = "";
314
+ if (context.recentMessages && context.recentMessages.messages.length > 0) {
315
+ const { messages, agentNameMap } = context.recentMessages;
316
+ const promptParts = [];
317
+ for (const msg of messages) {
318
+ const senderName = agentNameMap.get(msg.fromAgent) ?? msg.fromAgent;
319
+ const role = msg.fromAgent === identity.agentId ? "you" : senderName;
320
+ const vis = msg.visibility !== "team" ? ` [${msg.visibility}]` : "";
321
+ promptParts.push(`[${role}]${vis}: ${msg.content}`);
322
+ }
323
+ conversationPrompt = promptParts.join("\n\n");
324
+ }
325
+ return { systemPrompt, conversationPrompt };
326
+ }
327
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/agent/context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AA4EH,8EAA8E;AAC9E,wCAAwC;AACxC,8EAA8E;AAE9E;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,gBAA2B,EAAE,WAAqB;IACjF,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,gBAAgB,CAA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AAC;YACrE,MAAM,GAAG,GAAG,GAAG,CAAC,UAAU,KAAK,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;YACpE,WAAW,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,GAAG,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC;QACtD,CAAC;QAED,kBAAkB,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,CAAC;AAC9C,CAAC"}
@@ -24,6 +24,7 @@ export interface InternalAgentOptions {
24
24
  pollIntervalMs?: number;
25
25
  systemPrompt?: string;
26
26
  signal?: AbortSignal;
27
+ decisionDepth?: number;
27
28
  }
28
29
  /**
29
30
  * Run an internal agent loop. Blocks until AbortSignal fires or SIGINT/SIGTERM.
@@ -1 +1 @@
1
- {"version":3,"file":"internal-agent.d.ts","sourceRoot":"","sources":["../../src/agent/internal-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAsB,MAAM,qBAAqB,CAAC;AAO7E,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CA4HnF"}
1
+ {"version":3,"file":"internal-agent.d.ts","sourceRoot":"","sources":["../../src/agent/internal-agent.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAsB,MAAM,qBAAqB,CAAC;AAO7E,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,aAAa,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CA2InF"}