Skip to content

Commit 1a189ba

Browse files
feat: add ai-agents example schema (#47)
* feat: add ai-agents example schema Adds an example showing an AI agent inheriting view access to documents on behalf of a user via an arrow on a `delegates` permission. * fix: correct validation chain for ai-agents example
1 parent 9dfa134 commit 1a189ba

2 files changed

Lines changed: 75 additions & 0 deletions

File tree

schemas/ai-agents/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# AI Agents acting on behalf of a user
2+
3+
An AI agent inherits view access to the documents a user can read or write, but cannot edit them on its own.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
schema: |-
3+
/**
4+
* an entity that can be granted permissions
5+
*/
6+
definition user {
7+
/**
8+
* users can have one or more AI agents that act on their behalf
9+
*/
10+
relation agent: ai_agent
11+
12+
/**
13+
* the set of AI agents that may act on this user's behalf
14+
*/
15+
permission delegates = agent
16+
}
17+
18+
/**
19+
* an AI agent that can act on behalf of a user
20+
*/
21+
definition ai_agent {}
22+
23+
/**
24+
* a resource that we are trying to protect
25+
*/
26+
definition document {
27+
/**
28+
* users can be made writers of specific documents
29+
*/
30+
relation writer: user
31+
32+
/**
33+
* users can be made readers of specific documents
34+
*/
35+
relation reader: user
36+
37+
/**
38+
* if a user has the writer relationship to a specific document, they automatically get permission to edit it
39+
*/
40+
permission edit = writer
41+
42+
/**
43+
* a user can view a document if they are a reader (or can edit it).
44+
* an AI agent can view a document if it acts on behalf of a reader or a writer of that document.
45+
*/
46+
permission view = reader + edit + reader->delegates + writer->delegates
47+
}
48+
49+
relationships: |-
50+
document:firstdoc#writer@user:tom
51+
document:firstdoc#reader@user:fred
52+
user:tom#agent@ai_agent:assistant_tom
53+
user:fred#agent@ai_agent:assistant_fred
54+
55+
assertions:
56+
assertTrue:
57+
- "document:firstdoc#edit@user:tom"
58+
- "document:firstdoc#view@user:tom"
59+
- "document:firstdoc#view@user:fred"
60+
- "document:firstdoc#view@ai_agent:assistant_tom"
61+
- "document:firstdoc#view@ai_agent:assistant_fred"
62+
assertFalse:
63+
- "document:firstdoc#edit@user:fred"
64+
- "document:firstdoc#edit@ai_agent:assistant_tom"
65+
- "document:firstdoc#edit@ai_agent:assistant_fred"
66+
67+
validation:
68+
document:firstdoc#view:
69+
- "[user:tom] is <document:firstdoc#writer>"
70+
- "[user:fred] is <document:firstdoc#reader>"
71+
- "[ai_agent:assistant_tom] is <user:tom#agent>"
72+
- "[ai_agent:assistant_fred] is <user:fred#agent>"

0 commit comments

Comments
 (0)