feat(ai): deliver canonical organization context to chat agents - #768
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ffa3ebf to
0c33ee5
Compare
|
The latest updates on your projects. Learn more about Unkey Deploy
|
The three-case present-context follow-up stayed at 16/18 on the small manual rubric, still missed the targeted emitter attribution, and increased words by 7.3%. Remove the extra rule and its tests rather than retaining prompt growth without a demonstrated benefit. Preserve the original attributed-assertions guidance and reference-budget fallback. The small fixture context again matches the original paired run byte for byte. This reverses the rule from 7aa476d after rebasing onto merged parent #766.
3672994 to
24f8c49
Compare
Greptile SummaryThis PR loads canonical saved organization business profiles into dashboard and shared Slack/MCP agent turns, adds organization-aware tool context, and introduces bounded formatting, timeout handling, tenant-isolation checks, and delivery tests.
Confidence Score: 3/5This PR is not safe to merge until valid domain variants are accepted, zero-website organizations can receive their saved organization profiles, and the explicit-type repository requirement is satisfied. The new domain preflight rejects authorized calls that the existing resolver accepts, while the loader withholds valid canonical profiles solely because an organization has no websites; the test file also violates an explicit repository rule. Files Needing Attention: packages/ai/src/ai/mcp/run-agent.ts, packages/ai/src/lib/organization-business-context.ts, apps/api/src/routes/agent-business-context.test.ts Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Authenticated dashboard, Slack, or MCP turn] --> B[Resolve organization and accessible websites]
B --> C{Requested site or domain authorized?}
C -- No --> D[Reject request or omit business context]
C -- Yes --> E[Read canonical organization profile]
E --> F{Read completes within 1.5 seconds?}
F -- No --> G[Inject explicit unavailable/unknown context]
F -- Yes --> H[Format provenance and assertions]
H --> I{Within 48,000 characters?}
I -- Yes --> J[Inject into model user context]
I -- No --> K[Omit references and retry]
K --> L{Reduced record fits?}
L -- Yes --> J
L -- No --> G
J --> M[Run authorized analytics tools]
|
| (options.websiteDomain && | ||
| !accessibleWebsites.some( | ||
| (site) => | ||
| site.domain === options.websiteDomain && | ||
| (!options.websiteId || site.id === options.websiteId) | ||
| )) |
There was a problem hiding this comment.
The new preflight uses exact, case-sensitive equality for websiteDomain. For example, a caller sending example.com for a stored Example.com site is rejected as inaccessible, even though the existing downstream resolver matches domains case-insensitively. This breaks otherwise authorized shared-agent requests.
| profile: null as OrganizationBusinessProfile | null, | ||
| read: vi.fn(), | ||
| prompts: [] as Parameters<MockLanguageModelV3["doStream"]>[0][], | ||
| contexts: [] as Record<string, unknown>[], |
There was a problem hiding this comment.
This test uses Record<string, unknown> instead of an explicit context type. The same pattern appears on lines 112 and 174, while line 148 also uses an unknown model parameter. This violates the repository directive to avoid any, unknown, and never in favor of explicit types, so the requirement must be satisfied before merging.
Context Used: Basic guidelines for the project so vibe coders do... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Saved organization business context reaches Insights but is absent from ordinary dashboard, Slack and MCP chat. This delivers the canonical saved profile through one bounded loader and formatter in the dashboard route and shared ask/stream/trace preparation. Context carries organization, revision and source provenance; it remains untrusted background and attributed assertions, never instructions or measured evidence.
Depends on #766 (merged). Rebased onto staging 656051c; the final diff contains only the agent-delivery slice. Ready for final review; do not merge automatically.
The extra one-time attribution instruction was tested and removed. The three-case present-context follow-up remained at 16/18 on the small manual rubric, still missed the targeted team-defined emitter attribution, and increased words by 7.3%. Commit 24f8c49 removes that rule and its tests, preserving the original attributed-assertions guidance and reference-budget fallback. The small fixture's formatted context is again byte-for-byte identical to the original paired run (2,824 characters). Existing live artifacts are retained outside git; no further live calls were made.
Validation at 24f8c49: root lint passed; root types 33/33; normal pre-push tests 27/27 tasks (AI 852 passed, 21 skipped); targeted shared-agent tests 50 passed, 1 skipped; API tests 7/7. Native AI SDK provider-mock pairs inspect actual model input for synthetic event meanings, priorities, team-only/mixed context, tenant isolation and no-profile fallbacks. Maximum-length plaintext brief, team fields and all source references are retained; oversized escaped references are explicitly omitted without losing final meanings or exclusions. These deterministic checks establish delivery, not model answer quality.
Scope: packages/ai context loading, agent/tool context, package export and isolated test runner, plus the API agent route and tests. No service, shared schema, Insights or dashboard changes remain in this PR's diff. No new memory source, scraping or unbounded tool loop.