Skip to content

feat: scope analytics and config by agentId - #7

Open
ttupper92618 wants to merge 1 commit into
feat/multi-tenant-registryfrom
feat/per-agent-config
Open

feat: scope analytics and config by agentId#7
ttupper92618 wants to merge 1 commit into
feat/multi-tenant-registryfrom
feat/per-agent-config

Conversation

@ttupper92618

Copy link
Copy Markdown
Contributor

Summary

  • Adds agent_id TEXT column to write_events, search_events, graph_events, memory_graph_links (nullable, backward compat via ALTER TABLE ADD COLUMN with try/catch)
  • All analytics recording methods (recordWriteResults, recordSearch, recordGraphWrite, insertGraphLinks) accept optional agentId
  • getStats(days, agentId?) filters all queries by agent_id when provided
  • Write pipeline threads req.agent?.id through to analytics recording
  • Stats/write-events routes filter by agent on agent-scoped requests
  • Config routes (/v2/agents/:agentId/config/*) read/write via registry.getAgentConfig()/setAgentConfig() with fallback to global config; legacy routes unchanged

Depends on #6 (registry + agent routing).

Test plan

  • yarn build passes cleanly
  • Legacy routes still record analytics without agent_id (null)
  • Agent-scoped writes record analytics with correct agent_id
  • GET /v2/agents/:agentId/stats/memories returns only that agent's data
  • Agent-scoped config changes don't affect global config
  • Global config serves as fallback for agents without overrides

🤖 Generated with Claude Code

Adds per-agent isolation to analytics recording and config management:

- analytics/db.ts: adds agent_id column to write_events, search_events,
  graph_events, memory_graph_links (nullable, backward compat); all
  recording methods accept optional agentId; getStats() filters by
  agent_id when provided
- pipeline/write.ts: threads agentId from req.agent through the write
  pipeline to analytics recording
- routes/memories.ts: passes agentId to search and write analytics
- routes/stats.ts: filters stats/write-events by agent_id on
  agent-scoped routes
- routes/config.ts: agent-scoped requests read/write config via
  registry.getAgentConfig()/setAgentConfig() with fallback to global;
  legacy requests unchanged

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9443b54388

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/routes/config.ts
registry.deleteAgentConfig(agentId, "custom_prompt");
}
console.log(`[config] agent ${agentId} custom prompt updated: ${newPrompt ? `${newPrompt.slice(0, 80)}...` : "reset to global"}`);
return v2Ok(res, { prompt: newPrompt, source: newPrompt ? "agent" : "global", persisted: true });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reload agent memory after agent-scoped config writes

This agent-scoped PUT /config/prompt path persists the override and returns immediately, which skips the runtime reload path used by global config updates. In the current code, agent requests execute against req.agentMemory from the pool, and that memory constructor does not consume registry config, so the API reports an agent override as saved while subsequent agent writes continue using prior/global behavior. The same early-return pattern is repeated for other agent-scoped config setters, so per-agent config changes are not actually applied at runtime.

Useful? React with 👍 / 👎.

Comment thread src/pipeline/write.ts
if (ev === "ADD" || ev === "UPDATE") {
const memId = r?.id ?? r?.memory_id;
if (memId) analyticsDb.insertGraphLinks(memId, nodeIds, edgeIds, userId);
if (memId) analyticsDb.insertGraphLinks(memId, nodeIds, edgeIds, userId, agentId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Pass agent ID when capturing graph links

This call now writes agent_id into memory_graph_links, but v2Write still invokes captureGraphLinks with only (result, userId), so agentId is always undefined and new rows get NULL for agent_id. That means the agent-scoping column added in this commit is never populated for graph links, which breaks per-agent attribution/filtering for this dataset.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant