1"use strict";(globalThis.webpackChunkopenfga_dev=globalThis.webpackChunkopenfga_dev||[]).push([[687],{81566(e,n,t){t.r(n),t.d(n,{assets:()=>c,contentTitle:()=>l,default:()=>u,frontMatter:()=>r,metadata:()=>s,toc:()=>d});const s=JSON.parse('{"id":"content/modeling/agents/task-based-authorization","title":"Task-Based Authorization","description":"Modeling task-based authorization for agents","source":"@site/docs/content/modeling/agents/task-based-authorization.mdx","sourceDirName":"content/modeling/agents","slug":"/modeling/agents/task-based-authorization","permalink":"/docs/modeling/agents/task-based-authorization","draft":false,"unlisted":false,"editUrl":"https://github.com/openfga/openfga.dev/edit/main/docs/content/modeling/agents/task-based-authorization.mdx","tags":[],"version":"current","lastUpdatedAt":1789987177000,"sidebarPosition":1,"frontMatter":{"title":"Task-Based Authorization","description":"Modeling task-based authorization for agents","sidebar_position":1,"slug":"/modeling/agents/task-based-authorization"},"sidebar":"docs","previous":{"title":"Authorization for MCP Servers","permalink":"/docs/modeling/agents/mcp-authorization"},"next":{"title":"Interacting with the API","permalink":"/docs/interacting"}}');var a=t(74848),o=t(28453),i=t(20822);const r={title:"Task-Based Authorization",description:"Modeling task-based authorization for agents",sidebar_position:1,slug:"/modeling/agents/task-based-authorization"},l="Modeling Task-Based Authorization for Agents",c={},d=[{value:"Tool authorization",id:"tool-authorization",level:2},{value:"Domain-specific models",id:"domain-specific-models",level:2},{value:"Scoping permissions to sessions and agents",id:"scoping-permissions-to-sessions-and-agents",level:2},{value:"Expiration and call count",id:"expiration-and-call-count",level:2},{value:"Binding agents to tasks",id:"binding-agents-to-tasks",level:2},{value:"Delegating task permissions to sub-agents",id:"delegating-task-permissions-to-sub-agents",level:2},{value:"Tuple cleanup",id:"tuple-cleanup",level:2},{value:"Further reading",id:"further-reading",level:2},{value:"Related Sections",id:"related-sections",level:2}];function h(e){const n={a:"a",code:"code",h1:"h1",h2:"h2",header:"header",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,o.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.header,{children:(0,a.jsx)(n.h1,{id:"modeling-task-based-authorization-for-agents",children:"Modeling Task-Based Authorization for Agents"})}),"\n",(0,a.jsx)(i.ZE,{}),"\n",(0,a.jsx)(n.p,{children:"Agents need credentials to interact with APIs. These can be user or service credentials, for internal or third-party systems. In most cases, these credentials grant agents broad access because the underlying authorization systems do not support fine-grained permissions. Consent prompts and service credentials are too coarse for agent use cases."}),"\n",(0,a.jsx)(n.p,{children:'Task-Based Authorization grants agents access to perform specific actions only when necessary, without permanent permissions. Agents start with no permissions and receive only what a given task requires. For example, rather than allowing an agent to create tickets across all projects, you authorize it to "create a ticket in project X" \u2014 scoping permissions to a specific context.'}),"\n",(0,a.jsxs)(n.p,{children:["This guide shows how to model task-based authorization in ",(0,a.jsx)(i.bU,{format:i.Ed.ShortForm}),", progressing from a basic tool-calling model to patterns that support permission hierarchies, session scoping, expiration, and agent binding."]}),"\n",(0,a.jsx)(n.h2,{id:"tool-authorization",children:"Tool authorization"}),"\n",(0,a.jsxs)(n.p,{children:["The simplest model represents tool authorization for a ",(0,a.jsx)(n.a,{href:"https://modelcontextprotocol.io/",children:"Model Context Protocol"})," server. When a task starts, you write tuples granting it permission to call the tools it needs."]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-dsl.openfga",children:"model\n schema 1.1\n\ntype task\n\ntype tool\n relations\n define can_call: [task, task:*]\n\ntype tool_resource\n relations\n define tool: [tool]\n define can_call: [task] or can_call from tool\n"})}),"\n",(0,a.jsxs)(n.p,{children:["A ",(0,a.jsx)(n.code,{children:"tool"})," represents a capability (e.g., ",(0,a.jsx)(n.code,{children:"slack_send_message"}),"), and a ",(0,a.jsx)(n.code,{children:"tool_resource"})," represents a specific target within that tool (e.g., a Slack channel). Granting ",(0,a.jsx)(n.code,{children:"can_call"})," on a ",(0,a.jsx)(n.code,{children:"tool"})," automatically grants access to all of its resources. You can also grant access to individual resources, or use ",(0,a.jsx)(n.code,{children:"task:*"})," to allow any task to call a tool."]}),"\n",(0,a.jsxs)(n.p,{children:["For example, you can grant ",(0,a.jsx)(n.code,{children:"task:1"})," access to send any Slack message, while restricting ",(0,a.jsx)(n.code,{children:"task:2"})," to a specific channel:"]}),"\n",(0,a.jsx)(i.LI,{tuples:[{user:"task:*",relation:"can_call",object:"tool:slack_list_channels"},{user:"task:1",relation:"can_call",object:"tool:slack_send_message"},{user:"task:2",relation:"can_call",object:"tool_resource:slack_send_message/XGA14FG"}]}),"\n",(0,a.jsxs)(n.p,{children:["When checking whether ",(0,a.jsx)(n.code,{children:"task:2"})," can call ",(0,a.jsx)(n.code,{children:"tool_resource:slack_send_message/XGA14FG"}),", send a ",(0,a.jsx)(n.a,{href:"/docs/interacting/contextual-tuples",children:"contextual tuple"})," linking the resource to its tool. This avoids storing a tuple for every channel \u2014 you provide the tool-to-resource relationship at query time."]}),"\n",(0,a.jsx)(i.ou,{user:"task:2",relation:"can_call",object:"tool_resource:slack_send_message/XGA14FG",allowed:!0,skipSetup:!0,contextualTuples:[{_description:"Link the tool_resource to its parent tool",user:"tool:slack_send_message",relation:"tool",object:"tool_resource:slack_send_message/XGA14FG"}]}),"\n",(0,a.jsx)(n.h2,{id:"domain-specific-models",children:"Domain-specific models"}),"\n",(0,a.jsx)(n.p,{children:"The model above is generic. If you are building agents for your own application, your authorization model should reflect your domain. Consider a project management system:"}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-dsl.openfga",children:"model\n schema 1.1\n\ntype user\n\ntype task\n\ntype organization\n relations\n define admin: [user]\n define member: [user]\n\ntype project\n relations\n define organization: [organization]\n\n # relations for users\n define owner: [user]\n define member: [user]\n\n # relations for tasks\n define read: [task]\n define write: [task]\n define delete: [task]\n\n # permissions for users\n define can_delete: delete or owner or admin from organization\n define can_edit: write or owner or admin from organization\n define can_read: read or can_edit or member from organization\n define can_create_ticket: can_edit\n\ntype ticket\n relations\n define project: [project]\n define owner: [user]\n\n # relations for tasks\n define read: [task]\n define write: [task]\n define delete: [task]\n define can_delete: owner or delete or can_delete from project\n define can_edit: owner or write or can_edit from project\n define can_read: read or write or can_read from project\n"})}),"\n",(0,a.jsxs)(n.p,{children:["This enriches an existing user-oriented model by adding ",(0,a.jsx)(n.code,{children:"task"})," as a principal. Granting a ",(0,a.jsx)(n.code,{children:"task"})," the ",(0,a.jsx)(n.code,{children:"write"})," relation on a project gives it permission to read and edit the project and all its tickets. You can also grant permissions at the ticket level for more granular control. This makes your application ready for agent authorization with minimal changes to your existing model."]}),"\n",(0,a.jsxs)(n.p,{children:["If you follow this approach, your application needs to perform both user and task authorization. This means two separate checks: one to verify the user has access to a resource, and another to verify the task has permission to perform the action on behalf of the agent, as described
1in ",(0,a.jsx)(n.a,{href:"#binding-agents-to-tasks",children:"Binding agents to tasks"}),"."]}),"\n",(0,a.jsx)(n.h2,{id:"scoping-permissions-to-sessions-and-agents",children:"Scoping permissions to sessions and agents"}),"\n",(0,a.jsx)(n.p,{children:"In interactive scenarios, users may create multiple sessions. You can scope permissions to a session so that access applies to all tasks within it. You can also scope permissions to an agent so they persist across sessions."}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-dsl.openfga",children:"model\n schema 1.1\n\ntype task\n\ntype agent\n relations\n define task: [task]\n\ntype session\n relations\n define task: [task]\n\ntype tool\n relations\n define can_call: [task, session#task, agent#task]\n"})}),"\n",(0,a.jsxs)(n.p,{children:["The ",(0,a.jsx)(n.code,{children:"can_call"})," relation accepts three types of assignments:"]}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"task"})," \u2014 grant permission to a specific task."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"session#task"}),' \u2014 grant permission to all tasks in a session. When the user says "allow this for this session", write a tuple like ',(0,a.jsx)(n.code,{children:"user: session:1#task, relation: can_call, object: tool:slack_send_message"}),"."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.code,{children:"agent#task"}),' \u2014 grant permission to all tasks for an agent, across sessions. When the user says "always allow this", write a tuple with ',(0,a.jsx)(n.code,{children:"agent:1#task"})," instead."]}),"\n"]}),"\n",(0,a.jsx)(n.p,{children:"Each task is linked to its session and agent when created:"}),"\n",(0,a.jsx)(i.LI,{tuples:[{user:"task:1",relation:"task",object:"agent:1"},{user:"task:1",relation:"task",object:"session:1"},{user:"session:1#task",relation:"can_call",object:"tool:slack_send_message"}]}),"\n",(0,a.jsx)(n.h2,{id:"expiration-and-call-count",children:"Expiration and call count"}),"\n",(0,a.jsxs)(n.p,{children:["You can use ",(0,a.jsx)(i.bU,{format:i.Ed.ShortForm})," ",(0,a.jsx)(n.a,{href:"/docs/configuration-language#conditional-relationships",children:"conditions"})," to make permissions expire after a duration, or limit how many times the tool can be called."]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-dsl.openfga",children:"model\n schema 1.1\n\ntype task\n\ntype tool\n relations\n define can_call: [task, task with expiration, task with max_call_count]\n\ncondition expiration(grant_time: timestamp, grant_duration: duration, current_time: timestamp) {\n current_time < grant_time + grant_duration\n}\n\ncondition max_call_count(max_tool_calls: int, current_tool_count: int) {\n current_tool_count < max_tool_calls\n}\n"})}),"\n",(0,a.jsxs)(n.p,{children:["The ",(0,a.jsx)(n.code,{children:"expiration"})," condition grants access for a fixed duration from the grant time. The ",(0,a.jsx)(n.code,{children:"max_call_count"})," condition limits how many times the tool can be called. When writing the tuple, you provide the condition parameters:"]}),"\n",(0,a.jsx)(i.LI,{tuples:[{user:"task:1",relation:"can_call",object:"tool:slack_send_message",condition:{name:"expiration",context:{grant_time:"2026-03-22T00:00:00Z",grant_duration:"10m"}}}],rightColumnTuples:[{user:"task:2",relation:"can_call",object:"tool:slack_send_message",condition:{name:"max_call_count",context:{max_tool_calls:2}}}]}),"\n",(0,a.jsx)(n.p,{children:"When checking access, pass the current time or current call count in the request context."}),"\n",(0,a.jsx)(n.h2,{id:"binding-agents-to-tasks",children:"Binding agents to tasks"}),"\n",(0,a.jsxs)(n.p,{children:["The examples above do not verify that the agent making the call is actually assigned to the task. You can enforce this using ",(0,a.jsx)(n.a,{href:"/docs/interacting/contextual-tuples",children:"contextual tuples"})," and an intersection (",(0,a.jsx)(n.code,{children:"and"}),") in the model, similar to the ",(0,a.jsx)(n.a,{href:"/docs/modeling/organization-context-authorization",children:"Authorization Through Organization Context"})," pattern."]}),"\n",(0,a.jsx)(n.pre,{children:(0,a.jsx)(n.code,{className:"language-dsl.openfga",children:"model\n schema 1.1\n\ntype task\n\ntype agent\n relations\n define task: [task]\n\ntype tool\n relations\n define calling_agent: [agent]\n define can_call: [task] and task from calling_agent\n"})}),"\n",(0,a.jsxs)(n.p,{children:["The ",(0,a.jsx)(n.code,{children:"can_call"})," relation requires both that the task has been granted access ",(0,a.jsx)(n.strong,{children:"and"})," that the agent making the call is linked to the task. When the task is created, link it to its agent:"]}),"\n",(0,a.jsx)(i.LI,{tuples:[{user:"task:1",relation:"task",object:"agent:1"},{user:"task:1",relation:"can_call",object:"tool:slack_send_message"}]}),"\n",(0,a.jsxs)(n.p,{children:["At check time, send a contextual tuple identifying the calling agent. If the agent is linked to the task, the check returns ",(0,a.jsx)(n.code,{children:"true"}),":"]}),"\n",(0,a.jsx)(i.ou,{user:"task:1",relation:"can_call",object:"tool:slack_send_message",allowed:!0,skipSetup:!0,contextualTuples:[{_description:"The agent making the call",user:"agent:1",relation:"calling_agent",object:"tool:slack_send_message"}]}),"\n",(0,a.jsxs)(n.p,{children:["If a different agent tries to use ",(0,a.jsx)(n.code,{children:"task:1"}),", the check returns ",(0,a.jsx)(n.code,{children:"false"}
1)," because the agent-to-task link does not match:"]}),"\n",(0,a.jsx)(i.ou,{user:"task:1",relation:"can_call",object:"tool:slack_send_message",allowed:!1,skipSetup:!0,contextualTuples:[{_description:"A different agent making the call",user:"agent:2",relation:"calling_agent",object:"tool:slack_send_message"}]}),"\n",(0,a.jsx)(n.h2,{id:"delegating-task-permissions-to-sub-agents",children:"Delegating task permissions to sub-agents"}),"\n",(0,a.jsx)(n.p,{children:"Sub-agents also start with no permissions. When delegating work, you have two options:"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.strong,{children:"Share the task"}),": assign the same task to the sub-agent, giving it all the task's permissions."]}),"\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.strong,{children:"Restrict further"}),": create a new task with a narrower set of permissions for the sub-agent."]}),"\n"]}),"\n",(0,a.jsx)(n.h2,{id:"tuple-cleanup",children:"Tuple cleanup"}),"\n",(0,a.jsx)(n.p,{children:"When a task completes, delete all tuples associated with it to revoke its permissions."}),"\n",(0,a.jsx)(n.h2,{id:"further-reading",children:"Further reading"}),"\n",(0,a.jsx)(n.p,{children:"Mapping user intent to the right set of permissions is an active area of research. These resources explore the topic:"}),"\n",(0,a.jsxs)(n.ul,{children:["\n",(0,a.jsxs)(n.li,{children:[(0,a.jsx)(n.a,{href:"https://mcpdevsummitna26.sched.com/event/2Hbg0/from-scopes-to-intent-reimagining-authorization-for-autonomous-agents-andres-aguiar-abhishek-hingnikar-okta",children:"From Scopes To Intent: Reimagining Authorization for Autonomous Agents"}),", MCP Dev Summit NY 2026 ",(0,a.jsx)(n.a,{href:"https://github.com/aaguiarz/ibac-talk-demo",children:"code repository"})," and ",(0,a.jsx)(n.a,{href:"https://www.youtube.com/watch?v=IVIvtusd7LA",children:"demo"})]}),"\n",(0,a.jsx)(n.li,{children:(0,a.jsx)(n.a,{href:"https://ibac.dev/",children:"Intent-Based Access Control: Securing Agentic AI Through Fine-Grained Authorization"})}),"\n",(0,a.jsx)(n.li,{children:(0,a.jsx)(n.a,{href:"https://arxiv.org/abs/2510.26702",children:"Delegated Authorization for Agents Constrained to Semantic Task-to-Scope Matching"})}),"\n",(0,a.jsx)(n.li,{children:(0,a.jsx)(n.a,{href:"https://notes.karlmcguinness.com/notes/the-mission-shaping-problem/",children:"The Mission Shaping Problem"})}),"\n",(0,a.jsx)(n.li,{children:(0,a.jsx)(n.a,{href:"https://dev.to/siddhantkcode/securing-agentic-ai-authorization-patterns-for-autonomous-systems-3ajo",children:"Securing Agentic AI: authorization patterns for autonomous systems"})}),"\n"]}),"\n",(0,a.jsx)(n.h2,{id:"related-sections",children:"Related Sections"}),"\n",(0,a.jsx)(i.XQ,{description:"Take a look at the following sections for more information.",relatedLinks:[{title:"Conditions",description:"Learn how to model relationships with conditions such as expiration and call count",link:"../../modeling/conditions"},{title:"Contextual Tuples",description:"Learn how to use contextual tuples to send dynamic context at query time",link:"../../interacting/contextual-tuples"}]})]})}function u(e={}){const{wrapper:n}={...(0,o.R)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(h,{...e})}):h(e)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.